Skip to content

Commit

Permalink
fix d2d compile error and wrong background
Browse files Browse the repository at this point in the history
TODO:
for direct2d, why background is white if return after clear color and
data is null?
  • Loading branch information
wang-bin committed Mar 1, 2013
1 parent 08d0664 commit 080322f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 12 additions & 3 deletions src/Direct2DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 72,7 @@ class Direct2DRendererPrivate : public VideoRendererPrivate
}
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
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 5 additions & 6 deletions src/GDIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(v=vs.85).aspx
Expand All @@ -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!)
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions templates/vo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 080322f

Please sign in to comment.