Qt 4.8
Public Functions | Properties | List of all members
QVGCompositionHelper Class Reference

#include <qvgcompositionhelper_p.h>

Public Functions

void blitWindow (VGImage image, const QSize &imageSize, const QRect &rect, const QPoint &topLeft, int opacity)
 
void clearScissor ()
 
void drawCursorPixmap (const QPixmap &pixmap, const QPoint &offset)
 
void endCompositing ()
 
void fillBackground (const QRegion &region, const QBrush &brush)
 
 QVGCompositionHelper ()
 
void setScissor (const QRegion &region)
 
void startCompositing (const QSize &screenSize)
 
virtual ~QVGCompositionHelper ()
 

Properties

QVGPaintEnginePrivated
 
QSize screenSize
 

Detailed Description

Definition at line 65 of file qvgcompositionhelper_p.h.

Constructors and Destructors

◆ QVGCompositionHelper()

QVGCompositionHelper::QVGCompositionHelper ( )

Definition at line 3990 of file qpaintengine_vg.cpp.

3991 {
3993 }
QVGPaintEnginePrivate * vgPrivate()
Q_OPENVG_EXPORT QVGPaintEngine * qt_vg_create_paint_engine(void)
QVGPaintEnginePrivate * d

◆ ~QVGCompositionHelper()

QVGCompositionHelper::~QVGCompositionHelper ( )
virtual

Definition at line 3995 of file qpaintengine_vg.cpp.

3996 {
3997 }

Functions

◆ blitWindow()

void QVGCompositionHelper::blitWindow ( VGImage  image,
const QSize imageSize,
const QRect rect,
const QPoint topLeft,
int  opacity 
)

Definition at line 4012 of file qpaintengine_vg.cpp.

Referenced by endCompositing().

4014 {
4015  if (image == VG_INVALID_HANDLE)
4016  return;
4017 
4018  // Determine which sub rectangle of the window to draw.
4019  QRect sr = rect.translated(-topLeft);
4020 
4021  if (opacity >= 255) {
4022  // Fully opaque: use vgSetPixels() to directly copy the sub-region.
4023  int y = screenSize.height() - (rect.bottom() + 1);
4024  vgSetPixels(rect.x(), y, image, sr.x(),
4025  imageSize.height() - (sr.y() + sr.height()),
4026  sr.width(), sr.height());
4027  } else {
4028  // Extract the child image that we want to draw.
4029  VGImage child;
4030  if (sr.topLeft().isNull() && sr.size() == imageSize)
4031  child = image;
4032  else {
4033  child = vgChildImage
4034  (image, sr.x(), imageSize.height() - (sr.y() + sr.height()),
4035  sr.width(), sr.height());
4036  }
4037 
4038  // Set the image transform.
4039  QTransform transform;
4040  int y = screenSize.height() - (rect.bottom() + 1);
4041  transform.translate(rect.x() - 0.5f, y - 0.5f);
4042  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
4043 
4044  // Enable opacity for image drawing if necessary.
4045  if (opacity != d->paintOpacity) {
4046  VGfloat values[4];
4047  values[0] = 1.0f;
4048  values[1] = 1.0f;
4049  values[2] = 1.0f;
4050  values[3] = ((VGfloat)opacity) / 255.0f;
4051  vgSetParameterfv(d->opacityPaint, VG_PAINT_COLOR, 4, values);
4052  d->paintOpacity = values[3];
4053  }
4054  if (d->fillPaint != d->opacityPaint) {
4055  vgSetPaint(d->opacityPaint, VG_FILL_PATH);
4056  d->fillPaint = d->opacityPaint;
4057  }
4058  d->setImageMode(VG_DRAW_IMAGE_MULTIPLY);
4059 
4060  // Draw the child image.
4061  vgDrawImage(child);
4062 
4063  // Destroy the child image.
4064  if(child != image)
4065  vgDestroyImage(child);
4066  }
4067 }
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
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
void setTransform(VGMatrixMode mode, const QTransform &transform)
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
bool isNull() const
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
Definition: qpoint.h:125
void setImageMode(VGImageMode mode)
quint16 values[128]
QVGPaintEnginePrivate * d
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ clearScissor()

void QVGCompositionHelper::clearScissor ( )

Definition at line 4228 of file qpaintengine_vg.cpp.

4229 {
4230  if (d->scissorActive || d->scissorDirty) {
4231  vgSeti(VG_SCISSORING, VG_FALSE);
4232  d->scissorActive = false;
4233  d->scissorDirty = false;
4234  }
4235 }
QVGPaintEnginePrivate * d

◆ drawCursorPixmap()

void QVGCompositionHelper::drawCursorPixmap ( const QPixmap pixmap,
const QPoint offset 
)

Definition at line 4161 of file qpaintengine_vg.cpp.

Referenced by fillBackground().

4162 {
4163  VGImage vgImage = VG_INVALID_HANDLE;
4164 
4165  // Fetch the VGImage from the pixmap if possible.
4166  QPixmapData *pd = pixmap.pixmapData();
4167  if (!pd)
4168  return; // null QPixmap
4169  if (pd->classId() == QPixmapData::OpenVGClass) {
4170  QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd);
4171  if (vgpd->isValid())
4172  vgImage = vgpd->toVGImage();
4173  }
4174 
4175  // Set the image transformation and modes.
4176  VGfloat devh = screenSize.height();
4177  QTransform transform(1.0f, 0.0f, 0.0f,
4178  0.0f, -1.0f, 0.0f,
4179  0.0f, devh, 1.0f);
4180  transform.translate(offset.x(), offset.y());
4181  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
4182  d->setImageMode(VG_DRAW_IMAGE_NORMAL);
4183 
4184  // Draw the VGImage.
4185  if (vgImage != VG_INVALID_HANDLE) {
4186  vgDrawImage(vgImage);
4187  } else {
4188  QImage img = pixmap.toImage().convertToFormat
4190 
4191  vgImage = vgCreateImage
4192  (VG_sARGB_8888_PRE, img.width(), img.height(),
4193  VG_IMAGE_QUALITY_FASTER);
4194  if (vgImage == VG_INVALID_HANDLE)
4195  return;
4196  vgImageSubData
4197  (vgImage, img.constBits() + img.bytesPerLine() * (img.height() - 1),
4198  -(img.bytesPerLine()), VG_sARGB_8888_PRE, 0, 0,
4199  img.width(), img.height());
4200 
4201  vgDrawImage(vgImage);
4202  vgDestroyImage(vgImage);
4203  }
4204 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
void setTransform(VGMatrixMode mode, const QTransform &transform)
virtual VGImage toVGImage()
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void setImageMode(VGImageMode mode)
ClassId classId() const
const uchar * constBits() const
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1985
QVGPaintEnginePrivate * d
bool isValid() const
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height.
Definition: qsize.h:129
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPixmapData * pixmapData() const
Definition: qpixmap.cpp:2277

◆ endCompositing()

void QVGCompositionHelper::endCompositing ( )

Definition at line 4006 of file qpaintengine_vg.cpp.

4007 {
4008  clearScissor();
4009 }

◆ fillBackground()

void QVGCompositionHelper::fillBackground ( const QRegion region,
const QBrush brush 
)

Definition at line 4107 of file qpaintengine_vg.cpp.

Referenced by fillBackgroundRect().

4108 {
4109  if (brush.style() == Qt::SolidPattern) {
4110  // Use vgClear() to quickly fill the background.
4111  QColor color = brush.color();
4112  if (d->clearColor != color || d->clearOpacity != 1.0f) {
4113  VGfloat values[4];
4114  values[0] = color.redF();
4115  values[1] = color.greenF();
4116  values[2] = color.blueF();
4117  values[3] = color.alphaF();
4118  vgSetfv(VG_CLEAR_COLOR, 4, values);
4119  d->clearColor = color;
4120  d->clearOpacity = 1.0f;
4121  }
4122  if (region.rectCount() == 1) {
4123  QRect r = region.boundingRect();
4124  vgClear(r.x(), screenSize.height() - r.y() - r.height(),
4125  r.width(), r.height());
4126  } else {
4127  const QVector<QRect> rects = region.rects();
4128  for (int i = 0; i < rects.size(); ++i) {
4129  QRect r = rects.at(i);
4130  vgClear(r.x(), screenSize.height() - r.y() - r.height(),
4131  r.width(), r.height());
4132  }
4133  }
4134 
4135  } else {
4136  // Set the path transform to the default viewport transformation.
4137  VGfloat devh = screenSize.height();
4138  QTransform viewport(1.0f, 0.0f, 0.0f,
4139  0.0f, -1.0f, 0.0f,
4140  0.0f, devh, 1.0f);
4141  d->setTransform(VG_MATRIX_PATH_USER_TO_SURFACE, viewport);
4142 
4143  // Set the brush to use to fill the background.
4144  d->ensureBrush(brush);
4145  d->setFillRule(VG_EVEN_ODD);
4146 
4147  if (region.rectCount() == 1) {
4148  fillBackgroundRect(region.boundingRect(), d);
4149  } else {
4150  const QVector<QRect> rects = region.rects();
4151  for (int i = 0; i < rects.size(); ++i)
4152  fillBackgroundRect(rects.at(i), d);
4153  }
4154 
4155  // We will need to reset the path transform during the next paint.
4156  d->pathTransformSet = false;
4157  }
4158 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setTransform(VGMatrixMode mode, const QTransform &transform)
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
quint16 values[128]
void ensureBrush(const QBrush &brush)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVGPaintEnginePrivate * d
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
qreal redF() const
Returns the red color component of this color.
Definition: qcolor.cpp:1213
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int height() const
Returns the height.
Definition: qsize.h:129
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void fillBackgroundRect(const QRect &rect, QVGPaintEnginePrivate *d)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void setFillRule(VGint mode)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ setScissor()

void QVGCompositionHelper::setScissor ( const QRegion region)

Definition at line 4206 of file qpaintengine_vg.cpp.

4207 {
4208  QVector<QRect> rects = region.rects();
4209  int count = rects.count();
4210  if (count > d->maxScissorRects)
4211  count = d->maxScissorRects;
4212  QVarLengthArray<VGint> params(count * 4);
4213  int height = screenSize.height();
4214  for (int i = 0; i < count; ++i) {
4215  params[i * 4 + 0] = rects[i].x();
4216  params[i * 4 + 1] = height - rects[i].y() - rects[i].height();
4217  params[i * 4 + 2] = rects[i].width();
4218  params[i * 4 + 3] = rects[i].height();
4219  }
4220 
4221  vgSetiv(VG_SCISSOR_RECTS, count * 4, params.data());
4222  vgSeti(VG_SCISSORING, VG_TRUE);
4223  d->scissorDirty = false;
4224  d->scissorActive = true;
4225  d->scissorRegion = region;
4226 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVGPaintEnginePrivate * d
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
int height() const
Returns the height.
Definition: qsize.h:129

◆ startCompositing()

void QVGCompositionHelper::startCompositing ( const QSize screenSize)

Definition at line 3999 of file qpaintengine_vg.cpp.

4000 {
4001  this->screenSize = screenSize;
4002  clearScissor();
4003  d->setBlendMode(VG_BLEND_SRC_OVER);
4004 }
void setBlendMode(VGBlendMode mode)
QVGPaintEnginePrivate * d

Properties

◆ d

QVGPaintEnginePrivate* QVGCompositionHelper::d
private

Definition at line 82 of file qvgcompositionhelper_p.h.

◆ screenSize

QSize QVGCompositionHelper::screenSize
private

Definition at line 83 of file qvgcompositionhelper_p.h.


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