Skip to content

Commit

Permalink
x11: use old ximage if frame/vo not change
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 29, 2016
1 parent 91a6ae3 commit 24169cb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions widgets/X11Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ class X11RendererPrivate : public VideoRendererPrivate
, ShmCompletionEvent(0)
, ShmCompletionWaitCount(0)
, current_index(0)
, next_index(0)
, gc(NULL)
, pixfmt(VideoFormat::Format_Invalid)
, frame_changed(false)
{
XInitThreads();
memset(ximage_pool, 0, sizeof(ximage_pool));
Expand Down Expand Up @@ -304,7 +306,7 @@ class X11RendererPrivate : public VideoRendererPrivate
ximage_data[index].resize(ximage->bytes_per_line*ximage->height + 32);
return true;
}
bool resizeXImage(int index);
int resizeXImage(int index);

bool use_shm; //TODO: set by user
bool warn_bad_pitch;
Expand All @@ -316,13 +318,15 @@ class X11RendererPrivate : public VideoRendererPrivate
XVisualInfo vinfo;
Display *display;
int current_index;
int next_index;
XImage *ximage_pool[kPoolSize];
GC gc;
XShmSegmentInfo shm_pool[kPoolSize];
VideoFormat::PixelFormat pixfmt;
// if the incoming image pitchs are different from ximage ones, use ximage pitchs and copy data in ximage_data
QByteArray ximage_data[kPoolSize];
VideoFrame frame_orig; // if renderer is resized, scale the original frame
bool frame_changed;
};

X11Renderer::X11Renderer(QWidget *parent, Qt::WindowFlags f):
Expand Down Expand Up @@ -359,6 +363,7 @@ bool X11Renderer::isSupported(VideoFormat::PixelFormat pixfmt) const
bool X11Renderer::receiveFrame(const VideoFrame& frame)
{
DPTR_D(X11Renderer);
d.frame_changed = true;
if (!frame.isValid()) {
d.video_frame = VideoFrame(); // fill background
update();
Expand All @@ -370,14 +375,17 @@ bool X11Renderer::receiveFrame(const VideoFrame& frame)
return true;
}

bool X11RendererPrivate::resizeXImage(int index)
int X11RendererPrivate::resizeXImage(int index)
{
if (!frame_orig.isValid())
return false;
if (!frame_changed)
return -1;
// force align to 8(16?) because xcreateimage will not do alignment
// GAL vmem is 16 aligned
if (!ensureImage(index, FFALIGN(out_rect.width(), 16), FFALIGN(out_rect.height(), 16))) // we can also call it in onResizeRenderer, onSetOutAspectXXX
return false;
frame_changed = false;
XImage* &ximage = ximage_pool[index];
video_frame = frame_orig; // set before map!
VideoFrame interopFrame;
Expand Down Expand Up @@ -444,7 +452,8 @@ void X11Renderer::drawFrame()
{
// TODO: interop
DPTR_D(X11Renderer);
if (!d.resizeXImage(d.current_index))
int ret = d.resizeXImage(d.next_index); // -1: image no change
if (!ret)
return;
if (preferredPixelFormat() != d.pixfmt) {
qDebug() << "x11 preferred pixel format: " << d.pixfmt;
Expand All @@ -471,7 +480,12 @@ void X11Renderer::drawFrame()
}
}
QRect roi = realROI();
XImage* ximage = d.ximage_pool[d.current_index];
int idx = d.current_index; // ret<0, frame/vo no change. if host frame, no filters; >0: filters
if (ret > 0) { // next ximage is ready
idx = d.next_index;
d.next_index = (d.next_index+1)%kPoolSize;
}
XImage* ximage = d.ximage_pool[idx];
if (d.use_shm) {
XShmPutImage(d.display, winId(), d.gc, ximage
, roi.x(), roi.y()//, roi.width(), roi.height()
Expand All @@ -484,7 +498,6 @@ void X11Renderer::drawFrame()
, d.out_rect.x(), d.out_rect.y(), d.out_rect.width(), d.out_rect.height());
XSync(d.display, False); // update immediately
}
d.current_index = (d.current_index+1)%kPoolSize;
}

void X11Renderer::paintEvent(QPaintEvent *)
Expand All @@ -495,6 +508,7 @@ void X11Renderer::paintEvent(QPaintEvent *)
void X11Renderer::resizeEvent(QResizeEvent *e)
{
DPTR_D(X11Renderer);
d.frame_changed = true;
resizeRenderer(e->size());
update(); //update background
}
Expand Down

0 comments on commit 24169cb

Please sign in to comment.