diff --git a/src/Direct2DRenderer.cpp b/src/Direct2DRenderer.cpp index a97cb49b..cb5a0f0f 100644 --- a/src/Direct2DRenderer.cpp +++ b/src/Direct2DRenderer.cpp @@ -72,6 +72,7 @@ public: } bool createDeviceResource() { DPTR_P(Direct2DRenderer); + update_background = true; SafeRelease(&render_target); //force create a new one // // This method creates resources which are bound to a particular @@ -191,12 +192,20 @@ void Direct2DRenderer::paintEvent(QPaintEvent *) //http://www.daimakuai.net/?page_id=1574 d.render_target->BeginDraw(); d.render_target->SetTransform(D2D1::Matrix3x2F::Identity()); - if (update_background || !d.bitmap) { + //The first bitmap size is 0x0, we should only draw the background + + if ((d.update_background && d.out_rect != rect())|| d.data.isEmpty()) { d.update_background = false; - //TODO: It seems that the target's background keeps the color even if resize without clear color d.render_target->Clear(D2D1::ColorF(D2D1::ColorF::Black)); - return; +//http://msdn.microsoft.com/en-us/library/windows/desktop/dd535473(v=vs.85).aspx + //ID2D1SolidColorBrush *brush; + //d.render_target->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush); + //d.render_target->FillRectangle(D2D1::RectF(0, 0, width(), height()), brush); } + if (d.data.isEmpty()) { + //return; //why the background is whit if return? the below code draw an empty bitmap? + } + D2D1_RECT_F out_rect = { d.out_rect.left(), d.out_rect.top(), diff --git a/src/GDIRenderer.cpp b/src/GDIRenderer.cpp index d2e2117a..aae1791d 100644 --- a/src/GDIRenderer.cpp +++ b/src/GDIRenderer.cpp @@ -144,12 +144,14 @@ void GDIRenderer::paintEvent(QPaintEvent *) QPainter p(this); hdc = p.paintEngine()->getDC(); } - if (d.update_background || d.data.isEmpty()) { + if ((d.update_background && d.out_rect != rect())|| d.data.isEmpty()) { d.update_background = false; Graphics g(hdc); SolidBrush brush(Color(255, 0, 0, 0)); //argb g.FillRectangle(&brush, 0, 0, width(), height()); //Rectangle(hdc, 0, 0, width(), height()); + } + if (d.data.isEmpty()) { return; } /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms533829%28v=vs.85%29.aspx @@ -164,10 +166,6 @@ void GDIRenderer::paintEvent(QPaintEvent *) return; } - //fill background color only when the displayed frame rect not equas to renderer's - if (d.out_rect != rect()) { - - } HBITMAP hbmp_old = (HBITMAP)SelectObject(d.off_dc, d.off_bitmap); // && image.size() != size() //assume that the image data is already scaled to out_size(NOT renderer size!) @@ -201,7 +199,8 @@ void GDIRenderer::resizeEvent(QResizeEvent *e) void GDIRenderer::showEvent(QShowEvent *) { - DPTR_D(const GDIRenderer); + DPTR_D(GDIRenderer); + d.update_background = true; useQPainter(d.use_qpainter); if (!d.use_qpainter) { d_func().prepare(); diff --git a/templates/vo.cpp b/templates/vo.cpp index 81919fea..94adad90 100644 --- a/templates/vo.cpp +++ b/templates/vo.cpp @@ -71,12 +71,14 @@ void %CLASS%::paintEvent(QPaintEvent *) } //begin paint. how about QPainter::beginNativePainting()? - //fill background color when necessary, e.g. renderer is resized. - if (d.update_background /*&& d.out_rect != rect()*/) { + //fill background color when necessary, e.g. renderer is resized, image is null + if ((d.update_background && d.out_rect != rect()) || d.data.isEmpty()) { d.update_background = false; - //fill background color + //fill background color. DO NOT return, you must continue drawing + } + if (d.data.isEmpty()) { + return; } - //assume that the image data is already scaled to out_size(NOT renderer size!) if (!d.scale_in_renderer || (d.src_width == d.out_rect.width() && d.src_height == d.out_rect.height())) { //you may copy data to video buffer directly