Skip to content

Commit

Permalink
gdi: keep code format the same as template's
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 21, 2013
1 parent 105ba0e commit ffa66c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
34 changes: 20 additions & 14 deletions src/GDIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GDIRendererPrivate : public ImageRendererPrivate
DPTR_DECLARE_PUBLIC(GDIRenderer)

GDIRendererPrivate():
dc_painter(false)
use_qpainter(false)
, support_bitblt(true)
, gdiplus_token(0)
, device_context(0)
Expand All @@ -62,7 +62,7 @@ class GDIRendererPrivate : public ImageRendererPrivate
qDebug("bitblt=%d", ret);
}

bool dc_painter;
bool use_qpainter;
bool support_bitblt;
ULONG_PTR gdiplus_token;
/*
Expand Down Expand Up @@ -96,32 +96,34 @@ bool GDIRenderer::write()

QPaintEngine* GDIRenderer::paintEngine() const
{
if (d_func().dc_painter) {
if (d_func().use_qpainter) {
return QWidget::paintEngine();
} else {
return 0;
}
}

void GDIRenderer::setDCFromPainter(bool dc)
void GDIRenderer::useQPainter(bool qp)
{
DPTR_D(GDIRenderer);
d.dc_painter = dc;
if (dc) {
setAttribute(Qt::WA_PaintOnScreen, false);
} else {
d.use_qpainter = qp;
setAttribute(Qt::WA_PaintOnScreen, !d.use_qpainter);
if (!d.use_qpainter) {
d_func().getDeviceContext();
if (d_func().device_context) {
setAttribute(Qt::WA_PaintOnScreen, true); //use native engine
}
}
}

bool GDIRenderer::useQPainter() const
{
DPTR_D(const GDIRenderer);
return d.use_qpainter;
}

void GDIRenderer::changeEvent(QEvent *event)
{
QWidget::changeEvent(event);
if (event->type() == QEvent::ActivationChange) { //auto called when show
setDCFromPainter(d_func().dc_painter);
useQPainter(d_func().use_qpainter);
event->accept();
}
}
Expand Down Expand Up @@ -149,22 +151,25 @@ void GDIRenderer::paintEvent(QPaintEvent *)
Bitmap bitmap(image.width(), image.height(), image.bytesPerLine()
, PixelFormat32bppRGB, image.bits());
HDC hdc = d.device_context;
if (d.dc_painter) {
if (d.use_qpainter) {
QPainter p(this);
hdc = p.paintEngine()->getDC();
}
//begin paint
// && image.size() != size()
if (d.scale_in_qt) { //TODO:rename scale_on_paint
//qDebug("image size and target size not match. SLOW!!!");
/* http://msdn.microsoft.com/en-us/library/windows/desktop/ms533829%28v=vs.85%29.aspx
* Improving Performance by Avoiding Automatic Scaling
* TODO: How about QPainter?
*/
Graphics g(hdc);
g.SetSmoothingMode(SmoothingModeHighSpeed);
g.DrawImage(&bitmap, 0, 0, d.width, d.height);
} else {
//steps to use BitBlt: http://bbs.csdn.net/topics/60183502
HBITMAP hbmp = 0;// CreateCompatibleBitmap(hdc, d.image.width(), d.image.height());
if (bitmap.GetHBITMAP(Color(), &hbmp) == 0) {
if (SUCCEEDED(bitmap.GetHBITMAP(Color(), &hbmp))) {
//PAINTSTRUCT ps;
//BeginPaint(winId(), &ps); //why it's not necessary?
HDC hdc_mem = CreateCompatibleDC(hdc);
Expand All @@ -175,6 +180,7 @@ void GDIRenderer::paintEvent(QPaintEvent *)
//EndPaint(winId(), &ps);
}
}
//end paint
if (!d.scale_in_qt) {
d.img_mutex.unlock();
}
Expand Down
4 changes: 3 additions & 1 deletion src/QtAV/GDIRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Q_EXPORT GDIRenderer : public QWidget, public ImageRenderer
* true: paintEngine.getDC(), double buffer is enabled by defalut.
* false: GetDC(winId()), no double buffer, should reimplement paintEngine()
*/
void setDCFromPainter(bool dc);
//TODO: move to base class
bool useQPainter() const;
void useQPainter(bool qp);
protected:
virtual void changeEvent(QEvent *event); //stay on top will change parent, we need GetDC() again
virtual void resizeEvent(QResizeEvent *);
Expand Down
1 change: 1 addition & 0 deletions templates/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Q_EXPORT %CLASS% : public QWidget, public ImageRenderer
* return 0 and set this flag
*/
virtual QPaintEngine* paintEngine() const;
//TODO: move to base class
bool useQPainter() const;
void useQPainter(bool qp);
protected:
Expand Down

0 comments on commit ffa66c3

Please sign in to comment.