Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Protected Variables | Properties | Friends | List of all members
QDirectFbBlitter Class Reference

#include <qdirectfbblitter.h>

Inheritance diagram for QDirectFbBlitter:
QBlittable

Public Functions

void alphaFillRect (const QRectF &rect, const QColor &color, QPainter::CompositionMode cmode)
 
IDirectFBSurface * dfbSurface () const
 
virtual void drawPixmap (const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect)
 
void drawPixmapOpacity (const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect, QPainter::CompositionMode cmode, qreal opacity)
 
virtual void fillRect (const QRectF &rect, const QColor &color)
 
 QDirectFbBlitter (const QSize &size, IDirectFBSurface *surface)
 
 QDirectFbBlitter (const QSize &size, bool alpha)
 
virtual ~QDirectFbBlitter ()
 
- Public Functions inherited from QBlittable
Capabilities capabilities () const
 
bool isLocked () const
 
QImagelock ()
 
 Q_DECLARE_FLAGS (Capabilities, Capability)
 
 QBlittable (const QSize &size, Capabilities caps)
 
QSize size () const
 
void unlock ()
 
virtual ~QBlittable ()
 

Static Public Functions

static DFBSurfacePixelFormat alphaPixmapFormat ()
 
static DFBSurfacePixelFormat pixmapFormat ()
 
static DFBSurfacePixelFormat selectPixmapFormat (bool withAlpha)
 

Protected Functions

virtual QImagedoLock ()
 
virtual void doUnlock ()
 

Protected Variables

QImage m_image
 
QDirectFBPointer< IDirectFBSurface > m_surface
 
- Protected Variables inherited from QBlittable
QBlittablePrivated_ptr
 

Properties

bool m_premult
 

Friends

class QDirectFbConvenience
 

Additional Inherited Members

- Public Types inherited from QBlittable
enum  Capability {
  SolidRectCapability = 0x0001, SourcePixmapCapability = 0x0002, SourceOverPixmapCapability = 0x0004, SourceOverScaledPixmapCapability = 0x0008,
  AlphaFillRectCapability = 0x0010, OpacityPixmapCapability = 0x0020, OutlineCapability = 0x0001000
}
 

Detailed Description

Definition at line 53 of file qdirectfbblitter.h.

Constructors and Destructors

◆ QDirectFbBlitter() [1/2]

QDirectFbBlitter::QDirectFbBlitter ( const QSize size,
IDirectFBSurface *  surface 
)

Definition at line 64 of file qdirectfbblitter.cpp.

Referenced by QDirectFbBlitterPlatformPixmap::createBlittable().

66  , m_surface(surface)
67 {
68  m_surface->AddRef(m_surface.data());
69 
70  DFBSurfaceCapabilities surfaceCaps;
71  m_surface->GetCapabilities(m_surface.data(), &surfaceCaps);
72  m_premult = (surfaceCaps & DSCAPS_PREMULTIPLIED);
73 }
T * data() const
Returns the value of the pointer referenced by this object.
QBlittable(const QSize &size, Capabilities caps)
Definition: qblittable.cpp:60
static QBlittable::Capabilities dfb_blitter_capabilities()
QDirectFBPointer< IDirectFBSurface > m_surface

◆ QDirectFbBlitter() [2/2]

QDirectFbBlitter::QDirectFbBlitter ( const QSize size,
bool  alpha 
)

Definition at line 75 of file qdirectfbblitter.cpp.

77 {
78  DFBSurfaceDescription surfaceDesc;
79  memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription));
80  surfaceDesc.width = rect.width();
81  surfaceDesc.height = rect.height();
82 
83  // force alpha format to get AlphaFillRectCapability and ExtendedPixmapCapability support
84  alpha = true;
85 
86  if (alpha) {
87  m_premult = true;
88  surfaceDesc.caps = DSCAPS_PREMULTIPLIED;
89  surfaceDesc.pixelformat = QDirectFbBlitter::alphaPixmapFormat();
90  surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT);
91  } else {
92  surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
93  surfaceDesc.pixelformat = QDirectFbBlitter::pixmapFormat();
94  }
95 
96  IDirectFB *dfb = QDirectFbConvenience::dfbInterface();
97  dfb->CreateSurface(dfb , &surfaceDesc, m_surface.outPtr());
98  m_surface->Clear(m_surface.data(), 0, 0, 0, 0);
99 }
T * data() const
Returns the value of the pointer referenced by this object.
QBlittable(const QSize &size, Capabilities caps)
Definition: qblittable.cpp:60
static QBlittable::Capabilities dfb_blitter_capabilities()
static DFBSurfacePixelFormat pixmapFormat()
static IDirectFB * dfbInterface()
static DFBSurfacePixelFormat alphaPixmapFormat()
QDirectFBPointer< IDirectFBSurface > m_surface

◆ ~QDirectFbBlitter()

QDirectFbBlitter::~QDirectFbBlitter ( )
virtual

Definition at line 101 of file qdirectfbblitter.cpp.

102 {
103  unlock();
104 }
void unlock()
Definition: qblittable.cpp:100

Functions

◆ alphaFillRect()

void QDirectFbBlitter::alphaFillRect ( const QRectF rect,
const QColor color,
QPainter::CompositionMode  cmode 
)
virtual

Reimplemented from QBlittable.

Definition at line 131 of file qdirectfbblitter.cpp.

Referenced by fillRect().

132 {
133  int x, y, w, h;
134  DFBResult result;
135 
136  // check paramters
137  rect.toRect().getRect(&x, &y ,&w, &h);
138  if ((w <= 0) || (h <= 0)) return;
139 
140  if ((cmode == QPainter::CompositionMode_Source) || (color.alpha() == 255)) {
141  // CompositionMode_Source case or CompositionMode_SourceOver with opaque color
142 
143  m_surface->SetDrawingFlags(m_surface.data(),
144  DFBSurfaceDrawingFlags(m_premult ? (DSDRAW_NOFX | DSDRAW_SRC_PREMULTIPLY) : DSDRAW_NOFX));
145  m_surface->SetPorterDuff(m_surface.data(), DSPD_SRC);
146 
147  } else {
148  // CompositionMode_SourceOver case
149 
150  // check if operation is useless
151  if (color.alpha() == 0)
152  return;
153 
154  m_surface->SetDrawingFlags(m_surface.data(),
155  DFBSurfaceDrawingFlags(m_premult ? (DSDRAW_BLEND | DSDRAW_SRC_PREMULTIPLY) : DSDRAW_BLEND));
156  m_surface->SetPorterDuff(m_surface.data(), DSPD_SRC_OVER);
157  }
158 
159  // set color
160  m_surface->SetColor(m_surface.data(), color.red(), color.green(), color.blue(), color.alpha());
161 
162  // perform fill
163  result = m_surface->FillRectangle(m_surface.data(), x, y, w, h);
164  if (result != DFB_OK)
165  DirectFBError("QDirectFBBlitter::alphaFillRect()", result);
166 }
T * data() const
Returns the value of the pointer referenced by this object.
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle&#39;s top-left corner to *x and *y, and its dimensions to *width a...
Definition: qrect.h:392
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
QDirectFBPointer< IDirectFBSurface > m_surface

◆ alphaPixmapFormat()

DFBSurfacePixelFormat QDirectFbBlitter::alphaPixmapFormat ( )
static

Definition at line 106 of file qdirectfbblitter.cpp.

Referenced by QDirectFbBlitter(), and selectPixmapFormat().

107 {
108  return DSPF_ARGB;
109 }

◆ dfbSurface()

IDirectFBSurface * QDirectFbBlitter::dfbSurface ( ) const
inline

Definition at line 108 of file qdirectfbblitter.h.

109 {
110  return m_surface.data();
111 }
T * data() const
Returns the value of the pointer referenced by this object.
QDirectFBPointer< IDirectFBSurface > m_surface

◆ doLock()

QImage * QDirectFbBlitter::doLock ( )
protectedvirtual

Implements QBlittable.

Definition at line 213 of file qdirectfbblitter.cpp.

214 {
216  Q_ASSERT(size().isValid());
217 
218  void *mem;
219  int bpl;
220  const DFBResult result = m_surface->Lock(m_surface.data(), DFBSurfaceLockFlags(DSLF_WRITE|DSLF_READ), static_cast<void**>(&mem), &bpl);
221  if (result == DFB_OK) {
222  DFBSurfacePixelFormat dfbFormat;
223  DFBSurfaceCapabilities dfbCaps;
224  m_surface->GetPixelFormat(m_surface.data(), &dfbFormat);
225  m_surface->GetCapabilities(m_surface.data(), &dfbCaps);
227  int w, h;
228  m_surface->GetSize(m_surface.data(), &w, &h);
229  m_image = QImage(static_cast<uchar *>(mem),w,h,bpl,format);
230  } else {
231  DirectFBError("Failed to lock image", result);
232  }
233 
234  return &m_image;
235 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
T * data() const
Returns the value of the pointer referenced by this object.
static QImage::Format imageFormatFromSurfaceFormat(const DFBSurfacePixelFormat format, const DFBSurfaceCapabilities caps)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Definition: qblittable.cpp:77
QDirectFBPointer< IDirectFBSurface > m_surface

◆ doUnlock()

void QDirectFbBlitter::doUnlock ( )
protectedvirtual

Implements QBlittable.

Definition at line 319 of file qdirectfbblitter.cpp.

320 {
321  m_surface->Unlock(m_surface.data());
322 }
T * data() const
Returns the value of the pointer referenced by this object.
QDirectFBPointer< IDirectFBSurface > m_surface

◆ drawPixmap()

void QDirectFbBlitter::drawPixmap ( const QRectF rect,
const QPixmap pixmap,
const QRectF subrect 
)
virtual

Implements QBlittable.

Definition at line 126 of file qdirectfbblitter.cpp.

127 {
128  drawPixmapOpacity(rect, pixmap, srcRect, QPainter::CompositionMode_SourceOver, 1.0);
129 }
void drawPixmapOpacity(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect, QPainter::CompositionMode cmode, qreal opacity)

◆ drawPixmapOpacity()

void QDirectFbBlitter::drawPixmapOpacity ( const QRectF rect,
const QPixmap pixmap,
const QRectF subrect,
QPainter::CompositionMode  cmode,
qreal  opacity 
)
virtual

Reimplemented from QBlittable.

Definition at line 168 of file qdirectfbblitter.cpp.

Referenced by drawPixmap().

169 {
170  QRect sQRect = subrect.toRect();
171  QRect dQRect = rect.toRect();
172  DFBRectangle sRect = { sQRect.x(), sQRect.y(), sQRect.width(), sQRect.height() };
173  DFBRectangle dRect = { dQRect.x(), dQRect.y(), dQRect.width(), dQRect.height() };
174  DFBResult result;
175 
176  // skip if dst too small
177  if ((dRect.w <= 0) || (dRect.h <= 0)) return;
178 
179  // correct roundings if needed
180  if (sRect.w <= 0) sRect.w = 1;
181  if (sRect.h <= 0) sRect.h = 1;
182 
183  QBlittablePixmapData *blitPm = static_cast<QBlittablePixmapData*>(pixmap.pixmapData());
184  QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blitPm->blittable());
185  dfbBlitter->unlock();
186 
187  IDirectFBSurface *s = dfbBlitter->m_surface.data();
188 
189  DFBSurfaceBlittingFlags blittingFlags = DFBSurfaceBlittingFlags(DSBLIT_BLEND_ALPHACHANNEL);
190  DFBSurfacePorterDuffRule porterDuff = (cmode == QPainter::CompositionMode_SourceOver) ? DSPD_SRC_OVER : DSPD_SRC;
191 
192  if (opacity != 1.0)
193  {
194  blittingFlags = DFBSurfaceBlittingFlags(blittingFlags | DSBLIT_BLEND_COLORALPHA | (m_premult ? DSBLIT_SRC_PREMULTCOLOR : 0));
195  m_surface->SetColor(m_surface.data(), 0xff, 0xff, 0xff, (u8) (opacity * 255.0));
196  }
197 
198  m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(blittingFlags));
199  m_surface->SetPorterDuff(m_surface.data(), porterDuff);
200 
202  m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);
203 
204  if ((sRect.w == dRect.w) && (sRect.h == dRect.h))
205  result = m_surface->Blit(m_surface.data(), s, &sRect, dRect.x, dRect.y);
206  else
207  result = m_surface->StretchBlit(m_surface.data(), s, &sRect, &dRect);
208 
209  if (result != DFB_OK)
210  DirectFBError("QDirectFBBlitter::drawPixmapExtended()", result);
211 }
T * data() const
Returns the value of the pointer referenced by this object.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void unlock()
Definition: qblittable.cpp:100
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QBlittable * blittable() const
QDirectFBPointer< IDirectFBSurface > m_surface
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ fillRect()

void QDirectFbBlitter::fillRect ( const QRectF rect,
const QColor color 
)
virtual

Implements QBlittable.

Definition at line 121 of file qdirectfbblitter.cpp.

122 {
124 }
void alphaFillRect(const QRectF &rect, const QColor &color, QPainter::CompositionMode cmode)

◆ pixmapFormat()

DFBSurfacePixelFormat QDirectFbBlitter::pixmapFormat ( )
static

Definition at line 111 of file qdirectfbblitter.cpp.

Referenced by QDirectFbBlitter(), and selectPixmapFormat().

112 {
113  return DSPF_RGB32;
114 }

◆ selectPixmapFormat()

DFBSurfacePixelFormat QDirectFbBlitter::selectPixmapFormat ( bool  withAlpha)
static

Definition at line 116 of file qdirectfbblitter.cpp.

117 {
118  return withAlpha ? alphaPixmapFormat() : pixmapFormat();
119 }
static DFBSurfacePixelFormat pixmapFormat()
static DFBSurfacePixelFormat alphaPixmapFormat()

Friends and Related Functions

◆ QDirectFbConvenience

friend class QDirectFbConvenience
friend

Definition at line 78 of file qdirectfbblitter.h.

Properties

◆ m_image

QImage QDirectFbBlitter::m_image
protected

Definition at line 76 of file qdirectfbblitter.h.

Referenced by doLock().

◆ m_premult

bool QDirectFbBlitter::m_premult
private

Definition at line 81 of file qdirectfbblitter.h.

Referenced by alphaFillRect(), drawPixmapOpacity(), and QDirectFbBlitter().

◆ m_surface

QDirectFBPointer<IDirectFBSurface> QDirectFbBlitter::m_surface
protected

The documentation for this class was generated from the following files: