diff --git a/templates/vo.cpp b/templates/vo.cpp index 8bf6563a9..8f74fe3a4 100644 --- a/templates/vo.cpp +++ b/templates/vo.cpp @@ -15,6 +15,7 @@ class %CLASS%Private : public VideoRendererPrivate } ~%CLASS%Private() { } + virtual void setupQuality() {} }; %CLASS%::%CLASS%(QWidget *parent, Qt::WindowFlags f): @@ -49,11 +50,20 @@ void %CLASS%::convertData(const QByteArray &data) Q_UNUSED(locker); } +ool %CLASS%::needUpdateBackground() const +{ + return VideoRenderer::needUpdateBackground(); +} void %CLASS%::drawBackground() { } +bool %CLASS%::needDrawFrame() const +{ + return VideoRenderer::needDrawFrame(); +} + void %CLASS%::drawFrame() { //assume that the image data is already scaled to out_size(NOT renderer size!) @@ -66,26 +76,11 @@ void %CLASS%::drawFrame() void %CLASS%::paintEvent(QPaintEvent *) { - DPTR_D(%CLASS%); - { - //lock is required only when drawing the frame - QMutexLocker locker(&d.img_mutex); - Q_UNUSED(locker); - //begin paint. how about QPainter::beginNativePainting()? - //fill background color when necessary, e.g. renderer is resized, image is null - //we access d.data which will be modified in AVThread, so must be protected - if ((d.update_background && d.out_rect != rect()) || d.data.isEmpty()) { - d.update_background = false; - //fill background color. DO NOT return, you must continue drawing - drawBackground(); - } - //DO NOT return if no data. we should draw other things - //NOTE: if data is not copyed in convertData, you should always call drawFrame() - if (!d.data.isEmpty()) { - drawFrame(); - } - } + //DPTR_D(%CLASS%); + //d.painter->begin(this); //Widget painting can only begin as a result of a paintEvent + handlePaintEvent(); //end paint. how about QPainter::endNativePainting()? + //d.painter->end(); } void %CLASS%::resizeEvent(QResizeEvent *e) diff --git a/templates/vo.h b/templates/vo.h index c82647cfe..4acbcc3e3 100644 --- a/templates/vo.h +++ b/templates/vo.h @@ -29,9 +29,11 @@ class Q_EXPORT %CLASS% : public QWidget, public VideoRenderer */ protected: virtual void convertData(const QByteArray &data); + virtual bool needUpdateBackground() const; //TODO: abstract draw image and font. too many drawXXX() //called in paintEvent before drawFrame() when required virtual void drawBackground(); + virtual bool needDrawFrame() const; //TODO: no virtual func. it's a solution for temporary //draw the current frame using the current paint engine. called by paintEvent() virtual void drawFrame(); /*usually you don't need to reimplement paintEvent, just drawXXX() is ok. unless you want do all