Qt 4.8
Classes | Macros | Functions | Variables
qpaintengine_x11.cpp File Reference
#include "qplatformdefs.h"
#include "private/qpixmap_x11_p.h"
#include "qapplication.h"
#include "qdebug.h"
#include "qfont.h"
#include "qwidget.h"
#include "qbitmap.h"
#include "qpixmapcache.h"
#include "qtextcodec.h"
#include "qcoreevent.h"
#include "qiodevice.h"
#include <qmath.h>
#include "qpainter_p.h"
#include <qtextlayout.h>
#include <qvarlengtharray.h>
#include <private/qfont_p.h>
#include <private/qtextengine_p.h>
#include <private/qpaintengine_x11_p.h>
#include <private/qfontengine_x11_p.h>
#include <private/qwidget_p.h>
#include <private/qpainterpath_p.h>
#include "qpen.h"
#include "qcolor.h"
#include "qcolormap.h"
#include <private/qpaintengine_p.h>
#include "qpaintengine_x11_p.h"
#include <private/qt_x11_p.h>
#include <private/qnumeric_p.h>
#include <limits.h>
#include <private/qtessellator_p.h>
#include <private/qstylehelper_p.h>

Go to the source code of this file.

Classes

class  QXRenderTessellator
 

Macros

#define DITHER_SIZE   16
 
#define X11   qt_x11Data
 

Functions

static bool clipLine (QLineF *line, const QRect &rect)
 
static QLine clipStraightLine (const QRect &clip, const QLine &l)
 
static bool complexPictOp (int op)
 
static Picture getPatternFill (int screen, const QBrush &b)
 
static QPainterPath path_for_glyphs (const QVarLengthArray< glyph_t > &glyphs, const QVarLengthArray< QFixedPoint > &positions, const QFontEngineFT *ft)
 
static int qpainterOpToXrender (QPainter::CompositionMode mode)
 
static QPaintEngine::PaintEngineFeatures qt_decide_features ()
 
void qt_draw_tile (QPaintEngine *, qreal, qreal, qreal, qreal, const QPixmap &, qreal, qreal)
 
Q_GUI_EXPORT void * qt_getClipRects (const QRegion &r, int &num)
 
static QPixmap qt_patternForAlpha (uchar alpha, int screen)
 
QPixmap qt_pixmapForBrush (int brushStyle, bool invert)
 
static void qt_render_bitmap (Display *dpy, int scrn, Picture src, Picture dst, int sx, int sy, int x, int y, int sw, int sh, const QPen &pen)
 
QPixmap qt_toX11Pixmap (const QPixmap &pixmap)
 
Q_GUI_EXPORT void qt_x11_drawImage (const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth)
 
Q_GUI_EXPORT GC qt_x11_get_brush_gc (QPainter *p)
 Returns the X11 specific brush GC for the painter p. More...
 
Q_GUI_EXPORT GC qt_x11_get_pen_gc (QPainter *p)
 Returns the X11 specific pen GC for the painter p. More...
 
Drawable qt_x11Handle (const QPaintDevice *pd)
 Returns the X11 Drawable of the paint device. More...
 
const QX11Infoqt_x11Info (const QPaintDevice *pd)
 
static void qt_XRenderCompositeTrapezoids (Display *dpy, int op, Picture src, Picture dst, _Xconst XRenderPictFormat *maskFormat, int xSrc, int ySrc, const XTrapezoid *traps, int size)
 
static void setCapStyle (int cap_style, GC gc)
 
static void x11ClearClipRegion (Display *dpy, GC gc, GC gc2, Picture picture)
 
static void x11SetClipRegion (Display *dpy, GC gc, GC gc2, Picture picture, const QRegion &r)
 

Variables

static const qreal aliasedCoordinateDelta = 0.5 - 0.015625
 
static const uchar base_dither_matrix [DITHER_SIZE][DITHER_SIZE]
 
static const int compositionModeToRenderOp [QPainter::CompositionMode_Xor+1]
 

Macro Definition Documentation

◆ DITHER_SIZE

#define DITHER_SIZE   16

Definition at line 211 of file qpaintengine_x11.cpp.

Referenced by qt_patternForAlpha().

◆ X11

#define X11   qt_x11Data

Definition at line 124 of file qpaintengine_x11.cpp.

Referenced by getPatternFill(), qt_decide_features(), and qt_render_bitmap().

Function Documentation

◆ clipLine()

static bool clipLine ( QLineF line,
const QRect rect 
)
static

Definition at line 604 of file qpaintengine_x11.cpp.

Referenced by QCosmeticStroker::calculateLastPoint(), and QX11PaintEngine::drawLines().

605 {
606  qreal x1 = line->x1();
607  qreal x2 = line->x2();
608  qreal y1 = line->y1();
609  qreal y2 = line->y2();
610 
611  qreal left = rect.x();
612  qreal right = rect.x() + rect.width() - 1;
613  qreal top = rect.y();
614  qreal bottom = rect.y() + rect.height() - 1;
615 
616  enum { Left, Right, Top, Bottom };
617  // clip the lines, after cohen-sutherland, see e.g. http://www.nondot.org/~sabre/graphpro/line6.html
618  int p1 = ((x1 < left) << Left)
619  | ((x1 > right) << Right)
620  | ((y1 < top) << Top)
621  | ((y1 > bottom) << Bottom);
622  int p2 = ((x2 < left) << Left)
623  | ((x2 > right) << Right)
624  | ((y2 < top) << Top)
625  | ((y2 > bottom) << Bottom);
626 
627  if (p1 & p2)
628  // completely outside
629  return false;
630 
631  if (p1 | p2) {
632  qreal dx = x2 - x1;
633  qreal dy = y2 - y1;
634 
635  // clip x coordinates
636  if (x1 < left) {
637  y1 += dy/dx * (left - x1);
638  x1 = left;
639  } else if (x1 > right) {
640  y1 -= dy/dx * (x1 - right);
641  x1 = right;
642  }
643  if (x2 < left) {
644  y2 += dy/dx * (left - x2);
645  x2 = left;
646  } else if (x2 > right) {
647  y2 -= dy/dx * (x2 - right);
648  x2 = right;
649  }
650  p1 = ((y1 < top) << Top)
651  | ((y1 > bottom) << Bottom);
652  p2 = ((y2 < top) << Top)
653  | ((y2 > bottom) << Bottom);
654  if (p1 & p2)
655  return false;
656  // clip y coordinates
657  if (y1 < top) {
658  x1 += dx/dy * (top - y1);
659  y1 = top;
660  } else if (y1 > bottom) {
661  x1 -= dx/dy * (y1 - bottom);
662  y1 = bottom;
663  }
664  if (y2 < top) {
665  x2 += dx/dy * (top - y2);
666  y2 = top;
667  } else if (y2 > bottom) {
668  x2 -= dx/dy * (y2 - bottom);
669  y2 = bottom;
670  }
671  *line = QLineF(QPointF(x1, y1), QPointF(x2, y2));
672  }
673  return true;
674 }
double qreal
Definition: qglobal.h:1193
qreal x2() const
Returns the x-coordinate of the line&#39;s end point.
Definition: qline.h:304
qreal y2() const
Returns the y-coordinate of the line&#39;s end point.
Definition: qline.h:309
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
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
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QTextStream & right(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignRight) on stream and returns stream...
qreal y1() const
Returns the y-coordinate of the line&#39;s start point.
Definition: qline.h:299
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
qreal x1() const
Returns the x-coordinate of the line&#39;s start point.
Definition: qline.h:294
QTextStream & left(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignLeft) on stream and returns stream...

◆ clipStraightLine()

static QLine clipStraightLine ( const QRect clip,
const QLine l 
)
inlinestatic

Definition at line 749 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawRects().

750 {
751  if (l.p1().x() == l.p2().x()) {
752  int x = qBound(clip.left(), l.p1().x(), clip.right());
753  int y1 = qBound(clip.top(), l.p1().y(), clip.bottom());
754  int y2 = qBound(clip.top(), l.p2().y(), clip.bottom());
755 
756  return QLine(x, y1, x, y2);
757  } else {
758  Q_ASSERT(l.p1().y() == l.p2().y());
759 
760  int x1 = qBound(clip.left(), l.p1().x(), clip.right());
761  int x2 = qBound(clip.left(), l.p2().x(), clip.right());
762  int y = qBound(clip.top(), l.p1().y(), clip.bottom());
763 
764  return QLine(x1, y, x2, y);
765  }
766 }
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
QPoint p1() const
Returns the line&#39;s start point.
Definition: qline.h:132
QPoint p2() const
Returns the line&#39;s end point.
Definition: qline.h:137
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
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

◆ complexPictOp()

static bool complexPictOp ( int  op)
inlinestatic

Definition at line 148 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawRects().

149 {
150  return op != PictOpOver && op != PictOpSrc;
151 }

◆ getPatternFill()

static Picture getPatternFill ( int  screen,
const QBrush b 
)
static

Definition at line 303 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEnginePrivate::fillPolygon_dev().

304 {
305  if (!X11->use_xrender)
306  return XNone;
307 
308  XRenderColor color = X11->preMultiply(b.color());
309  XRenderColor bg_color;
310 
311  bg_color = X11->preMultiply(QColor(0, 0, 0, 0));
312 
313  for (int i = 0; i < X11->pattern_fill_count; ++i) {
314  if (X11->pattern_fills[i].screen == screen
315  && X11->pattern_fills[i].opaque == false
316  && X11->pattern_fills[i].style == b.style()
317  && X11->pattern_fills[i].color.alpha == color.alpha
318  && X11->pattern_fills[i].color.red == color.red
319  && X11->pattern_fills[i].color.green == color.green
320  && X11->pattern_fills[i].color.blue == color.blue
321  && X11->pattern_fills[i].bg_color.alpha == bg_color.alpha
322  && X11->pattern_fills[i].bg_color.red == bg_color.red
323  && X11->pattern_fills[i].bg_color.green == bg_color.green
324  && X11->pattern_fills[i].bg_color.blue == bg_color.blue)
325  return X11->pattern_fills[i].picture;
326  }
327  // none found, replace one
328  int i = qrand() % 16;
329 
330  if (X11->pattern_fills[i].screen != screen && X11->pattern_fills[i].picture) {
331  XRenderFreePicture (X11->display, X11->pattern_fills[i].picture);
332  X11->pattern_fills[i].picture = 0;
333  }
334 
335  if (!X11->pattern_fills[i].picture) {
336  Pixmap pixmap = XCreatePixmap (X11->display, RootWindow (X11->display, screen), 8, 8, 32);
337  XRenderPictureAttributes attrs;
338  attrs.repeat = True;
339  X11->pattern_fills[i].picture = XRenderCreatePicture (X11->display, pixmap,
340  XRenderFindStandardFormat(X11->display, PictStandardARGB32),
341  CPRepeat, &attrs);
342  XFreePixmap (X11->display, pixmap);
343  }
344 
345  X11->pattern_fills[i].screen = screen;
346  X11->pattern_fills[i].color = color;
347  X11->pattern_fills[i].bg_color = bg_color;
348  X11->pattern_fills[i].opaque = false;
349  X11->pattern_fills[i].style = b.style();
350 
351  XRenderFillRectangle(X11->display, PictOpSrc, X11->pattern_fills[i].picture, &bg_color, 0, 0, 8, 8);
352 
353  QPixmap pattern(qt_pixmapForBrush(b.style(), true));
354  XRenderPictureAttributes attrs;
355  attrs.repeat = true;
356  XRenderChangePicture(X11->display, pattern.x11PictureHandle(), CPRepeat, &attrs);
357 
358  Picture fill_fg = X11->getSolidFill(screen, b.color());
359  XRenderComposite(X11->display, PictOpOver, fill_fg, pattern.x11PictureHandle(),
360  X11->pattern_fills[i].picture,
361  0, 0, 0, 0, 0, 0, 8, 8);
362 
363  return X11->pattern_fills[i].picture;
364 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
Q_CORE_EXPORT int qrand()
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:99
unsigned long Picture
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define X11

◆ path_for_glyphs()

static QPainterPath path_for_glyphs ( const QVarLengthArray< glyph_t > &  glyphs,
const QVarLengthArray< QFixedPoint > &  positions,
const QFontEngineFT ft 
)
static

Definition at line 2315 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawFreetype().

2318 {
2319  QPainterPath path;
2321  ft->lockFace();
2322  int i = 0;
2323  while (i < glyphs.size()) {
2324  QFontEngineFT::Glyph *glyph = ft->loadGlyph(glyphs[i], 0, QFontEngineFT::Format_Mono);
2325  // #### fix case where we don't get a glyph
2326  if (!glyph)
2327  break;
2328 
2330  int n = 0;
2331  int h = glyph->height;
2332  int xp = qRound(positions[i].x);
2333  int yp = qRound(positions[i].y);
2334 
2335  xp += glyph->x;
2336  yp += -glyph->y + glyph->height;
2337  int pitch = ((glyph->width + 31) & ~31) >> 3;
2338 
2339  uchar *src = glyph->data;
2340  while (h--) {
2341  for (int x = 0; x < glyph->width; ++x) {
2342  bool set = src[x >> 3] & (0x80 >> (x & 7));
2343  if (set) {
2344  QRect r(xp + x, yp - h, 1, 1);
2345  while (x+1 < glyph->width && src[(x+1) >> 3] & (0x80 >> ((x+1) & 7))) {
2346  ++x;
2347  r.setRight(r.right()+1);
2348  }
2349 
2350  path.addRect(r);
2351  ++n;
2352  }
2353  }
2354  src += pitch;
2355  }
2356  ++i;
2357  }
2358  ft->unlockFace();
2359  return path;
2360 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
unsigned char uchar
Definition: qglobal.h:994
void unlockFace() const
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
FT_Face lockFace(Scaling scale=Scaled) const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Glyph * loadGlyph(uint glyph, QFixed subPixelPosition, GlyphFormat format=Format_None, bool fetchMetricsOnly=false) const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
int size() const

◆ qpainterOpToXrender()

static int qpainterOpToXrender ( QPainter::CompositionMode  mode)
inlinestatic

Definition at line 142 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::updateState().

143 {
145  return compositionModeToRenderOp[mode];
146 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const int compositionModeToRenderOp[QPainter::CompositionMode_Xor+1]

◆ qt_decide_features()

static QPaintEngine::PaintEngineFeatures qt_decide_features ( )
static

Definition at line 433 of file qpaintengine_x11.cpp.

434 {
435  QPaintEngine::PaintEngineFeatures features =
441 
442  if (X11->use_xrender) {
443  features |= QPaintEngine::Antialiasing;
444  features |= QPaintEngine::PorterDuff;
445  features |= QPaintEngine::MaskedBrush;
446 #if 0
447  if (X11->xrender_version > 10) {
449  // ###
450  }
451 #endif
452  }
453 
454  return features;
455 }
#define X11

◆ qt_draw_tile()

void qt_draw_tile ( QPaintEngine ,
qreal  ,
qreal  ,
qreal  ,
qreal  ,
const QPixmap ,
qreal  ,
qreal   
)

Definition at line 600 of file qpaintengine.cpp.

Referenced by QX11PaintEngine::drawTiledPixmap(), QPaintEngine::drawTiledPixmap(), and QX11PaintEngine::handle().

602 {
603  qreal yPos, xPos, drawH, drawW, yOff, xOff;
604  yPos = y;
605  yOff = yOffset;
606  while(yPos < y + h) {
607  drawH = pixmap.height() - yOff; // Cropping first row
608  if (yPos + drawH > y + h) // Cropping last row
609  drawH = y + h - yPos;
610  xPos = x;
611  xOff = xOffset;
612  while(xPos < x + w) {
613  drawW = pixmap.width() - xOff; // Cropping first column
614  if (xPos + drawW > x + w) // Cropping last column
615  drawW = x + w - xPos;
616  if (drawW > 0 && drawH > 0)
617  gc->drawPixmap(QRectF(xPos, yPos, drawW, drawH), pixmap, QRectF(xOff, yOff, drawW, drawH));
618  xPos += drawW;
619  xOff = 0;
620  }
621  yPos += drawH;
622  yOff = 0;
623  }
624 }
double qreal
Definition: qglobal.h:1193
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ qt_getClipRects()

Q_GUI_EXPORT void* qt_getClipRects ( const QRegion r,
int &  num 
)

◆ qt_patternForAlpha()

static QPixmap qt_patternForAlpha ( uchar  alpha,
int  screen 
)
static

Definition at line 231 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::updateBrush().

232 {
233  QPixmap pm;
234  QString key = QLatin1Literal("$qt-alpha-brush$")
235  % HexString<uchar>(alpha)
236  % HexString<int>(screen);
237 
238  if (!QPixmapCache::find(key, pm)) {
239  // #### why not use a mono image here????
241  pattern.fill(0xffffffff);
242  for (int y = 0; y < DITHER_SIZE; ++y) {
243  for (int x = 0; x < DITHER_SIZE; ++x) {
244  if (base_dither_matrix[x][y] <= alpha)
245  pattern.setPixel(x, y, 0x00000000);
246  }
247  }
248  pm = QBitmap::fromImage(pattern);
249  pm.x11SetScreen(screen);
250  QPixmapCache::insert(key, pm);
251  }
252  return pm;
253 }
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const uchar base_dither_matrix[DITHER_SIZE][DITHER_SIZE]
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
#define DITHER_SIZE

◆ qt_pixmapForBrush()

QPixmap qt_pixmapForBrush ( int  brushStyle,
bool  invert 
)

Definition at line 99 of file qbrush.cpp.

Referenced by getPatternFill(), and QX11PaintEngine::updateBrush().

100 {
101 
102  QPixmap pm;
103  QString key = QLatin1Literal("$qt-brush$")
104  % HexString<uint>(brushStyle)
105  % QLatin1Char(invert ? '1' : '0');
106  if (!QPixmapCache::find(key, pm)) {
107  pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert),
109  QPixmapCache::insert(key, pm);
110  }
111 
112  return pm;
113 }
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
Definition: qbitmap.cpp:318
const uchar * qt_patternForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:56
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_render_bitmap()

static void qt_render_bitmap ( Display dpy,
int  scrn,
Picture  src,
Picture  dst,
int  sx,
int  sy,
int  x,
int  y,
int  sw,
int  sh,
const QPen pen 
)
static

Definition at line 366 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawPixmap(), and QX11PaintEngine::drawTiledPixmap().

369 {
370  Picture fill_fg = X11->getSolidFill(scrn, pen.color());
371  XRenderComposite(dpy, PictOpOver,
372  fill_fg, src, dst, sx, sy, sx, sy, x, y, sw, sh);
373 }
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
unsigned long Picture
#define X11

◆ qt_toX11Pixmap()

QPixmap qt_toX11Pixmap ( const QPixmap pixmap)

Definition at line 93 of file qpixmap_x11.cpp.

Referenced by QX11PaintEngine::drawPixmap(), and QX11PaintEngine::updateBrush().

94 {
95  if (pixmap.isNull())
96  return QPixmap();
97 
98  if (QPixmap(pixmap).data_ptr()->classId() == QPixmapData::X11Class)
99  return pixmap;
100 
101  return qt_toX11Pixmap(pixmap.toImage());
102 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QPixmap qt_toX11Pixmap(const QImage &image)
Definition: qpixmap_x11.cpp:81
ClassId classId() const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ qt_x11_drawImage()

Q_GUI_EXPORT void qt_x11_drawImage ( const QRect rect,
const QPoint pos,
const QImage image,
Drawable  hd,
GC  gc,
Display dpy,
Visual *  visual,
int  depth 
)

Definition at line 1833 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawImage(), and QRasterWindowSurface::flush().

1835 {
1836  Q_ASSERT(image.format() == QImage::Format_RGB32);
1837  Q_ASSERT(image.depth() == 32);
1838 
1839  XImage *xi;
1840  // Note: this code assumes either RGB or BGR, 8 bpc server layouts
1841  const uint red_mask = (uint) visual->red_mask;
1842  bool bgr_layout = (red_mask == 0xff);
1843 
1844  const int w = rect.width();
1845  const int h = rect.height();
1846 
1847  QImage im;
1848  int image_byte_order = ImageByteOrder(X11->display);
1849  if ((QSysInfo::ByteOrder == QSysInfo::BigEndian && ((image_byte_order == LSBFirst) || bgr_layout))
1850  || (image_byte_order == MSBFirst && QSysInfo::ByteOrder == QSysInfo::LittleEndian)
1851  || (image_byte_order == LSBFirst && bgr_layout))
1852  {
1853  im = image.copy(rect);
1854  const int iw = im.bytesPerLine() / 4;
1855  uint *data = (uint *)im.bits();
1856  for (int i=0; i < h; i++) {
1857  uint *p = data;
1858  uint *end = p + w;
1859  if (bgr_layout && image_byte_order == MSBFirst && QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
1860  while (p < end) {
1861  *p = ((*p << 8) & 0xffffff00) | ((*p >> 24) & 0x000000ff);
1862  p++;
1863  }
1864  } else if ((image_byte_order == LSBFirst && QSysInfo::ByteOrder == QSysInfo::BigEndian)
1865  || (image_byte_order == MSBFirst && QSysInfo::ByteOrder == QSysInfo::LittleEndian)) {
1866  while (p < end) {
1867  *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000)
1868  | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff);
1869  p++;
1870  }
1871  } else if ((image_byte_order == MSBFirst && QSysInfo::ByteOrder == QSysInfo::BigEndian)
1872  || (image_byte_order == LSBFirst && bgr_layout))
1873  {
1874  while (p < end) {
1875  *p = ((*p << 16) & 0x00ff0000) | ((*p >> 16) & 0x000000ff)
1876  | ((*p ) & 0xff00ff00);
1877  p++;
1878  }
1879  }
1880  data += iw;
1881  }
1882  xi = XCreateImage(dpy, visual, depth, ZPixmap,
1883  0, (char *) im.bits(), w, h, 32, im.bytesPerLine());
1884  } else {
1885  xi = XCreateImage(dpy, visual, depth, ZPixmap,
1886  0, (char *) image.scanLine(rect.y())+rect.x()*sizeof(uint), w, h, 32, image.bytesPerLine());
1887  }
1888  XPutImage(dpy, hd, gc, xi, 0, 0, pos.x(), pos.y(), w, h);
1889  xi->data = 0; // QImage owns these bits
1890  XDestroyImage(xi);
1891 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
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 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
static const KeyPair *const end
#define X11
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qt_x11_get_brush_gc()

Q_GUI_EXPORT GC qt_x11_get_brush_gc ( QPainter p)

Returns the X11 specific brush GC for the painter p.

Note that QPainter::begin() must be called before this function returns a valid GC.

Definition at line 115 of file qpaintengine_x11.cpp.

116 {
117  if (p && p->paintEngine()
118  && p->paintEngine()->isActive()
119  && p->paintEngine()->type() == QPaintEngine::X11) {
120  return static_cast<QX11PaintEngine *>(p->paintEngine())->d_func()->gc_brush;
121  }
122  return 0;
123 }
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991

◆ qt_x11_get_pen_gc()

Q_GUI_EXPORT GC qt_x11_get_pen_gc ( QPainter p)

Returns the X11 specific pen GC for the painter p.

Note that QPainter::begin() must be called before this function returns a valid GC.

Definition at line 100 of file qpaintengine_x11.cpp.

101 {
102  if (p && p->paintEngine()
103  && p->paintEngine()->isActive()
104  && p->paintEngine()->type() == QPaintEngine::X11) {
105  return static_cast<QX11PaintEngine *>(p->paintEngine())->d_func()->gc;
106  }
107  return 0;
108 }
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991

◆ qt_x11Handle()

Drawable qt_x11Handle ( const QPaintDevice pd)

Returns the X11 Drawable of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained.

Definition at line 61 of file qpaintdevice_x11.cpp.

Referenced by QX11PaintEngine::begin().

62 {
63  if (!pd) return 0;
64  if (pd->devType() == QInternal::Widget)
65  return static_cast<const QWidget *>(pd)->handle();
66  else if (pd->devType() == QInternal::Pixmap)
67  return static_cast<const QPixmap *>(pd)->handle();
68  return 0;
69 }
virtual int devType() const
Definition: qpaintdevice.h:167

◆ qt_x11Info()

const QX11Info* qt_x11Info ( const QPaintDevice pd)
related

Referenced by QX11PaintEngine::begin().

◆ qt_XRenderCompositeTrapezoids()

static void qt_XRenderCompositeTrapezoids ( Display dpy,
int  op,
Picture  src,
Picture  dst,
_Xconst XRenderPictFormat *  maskFormat,
int  xSrc,
int  ySrc,
const XTrapezoid *  traps,
int  size 
)
static

Definition at line 1538 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEnginePrivate::fillPolygon_dev().

1546 {
1547  const int MAX_TRAPS = 50000;
1548  while (size) {
1549  int to_draw = size;
1550  if (to_draw > MAX_TRAPS)
1551  to_draw = MAX_TRAPS;
1552  XRenderCompositeTrapezoids(dpy, op, src, dst,
1553  maskFormat,
1554  xSrc, ySrc,
1555  traps, to_draw);
1556  size -= to_draw;
1557  traps += to_draw;
1558  }
1559 }

◆ setCapStyle()

static void setCapStyle ( int  cap_style,
GC  gc 
)
inlinestatic

Definition at line 944 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::drawPoints(), and QPen::swap().

945 {
946  ulong mask = GCCapStyle;
947  XGCValues vals;
948  vals.cap_style = cap_style;
949  XChangeGC(X11->display, gc, mask, &vals);
950 }
unsigned long ulong
Definition: qglobal.h:997
#define X11

◆ x11ClearClipRegion()

static void x11ClearClipRegion ( Display dpy,
GC  gc,
GC  gc2,
Picture  picture 
)
inlinestatic

Definition at line 186 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::updateBrush(), QX11PaintEngine::updateClipRegion_dev(), and QX11PaintEngine::updatePen().

193 {
194  if (gc)
195  XSetClipMask(dpy, gc, XNone);
196  if (gc2)
197  XSetClipMask(dpy, gc2, XNone);
198 
199 #ifndef QT_NO_XRENDER
200  if (picture) {
201  XRenderPictureAttributes attrs;
202  attrs.clip_mask = XNone;
203  XRenderChangePicture (dpy, picture, CPClipMask, &attrs);
204  }
205 #else
206  Q_UNUSED(picture);
207 #endif // QT_NO_XRENDER
208 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ x11SetClipRegion()

static void x11SetClipRegion ( Display dpy,
GC  gc,
GC  gc2,
Picture  picture,
const QRegion r 
)
inlinestatic

Definition at line 161 of file qpaintengine_x11.cpp.

Referenced by QX11PaintEngine::updateBrush(), QX11PaintEngine::updateClipRegion_dev(), and QX11PaintEngine::updatePen().

168 {
169  int num;
170  XRectangle *rects = (XRectangle *)qt_getClipRects(r, num);
171 
172  if (gc)
173  XSetClipRectangles( dpy, gc, 0, 0, rects, num, YXBanded );
174  if (gc2)
175  XSetClipRectangles( dpy, gc2, 0, 0, rects, num, YXBanded );
176 
177 #ifndef QT_NO_XRENDER
178  if (picture)
179  XRenderSetPictureClipRectangles(dpy, picture, 0, 0, rects, num);
180 #else
181  Q_UNUSED(picture);
182 #endif // QT_NO_XRENDER
183 }
Q_GUI_EXPORT void * qt_getClipRects(const QRegion &r, int &num)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Variable Documentation

◆ aliasedCoordinateDelta

const qreal aliasedCoordinateDelta = 0.5 - 0.015625
static

◆ base_dither_matrix

const uchar base_dither_matrix[DITHER_SIZE][DITHER_SIZE]
static
Initial value:
= {
{ 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
{ 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
{ 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
{ 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
{ 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
{ 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
{ 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
{ 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
{ 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
{ 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
{ 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
{ 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
{ 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
{ 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
{ 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
{ 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
}

Definition at line 212 of file qpaintengine_x11.cpp.

Referenced by qt_patternForAlpha().

◆ compositionModeToRenderOp

const int compositionModeToRenderOp[QPainter::CompositionMode_Xor+1]
static
Initial value:
= {
PictOpOver,
PictOpOverReverse,
PictOpClear,
PictOpSrc,
PictOpDst,
PictOpIn,
PictOpInReverse,
PictOpOut,
PictOpOutReverse,
PictOpAtop,
PictOpAtopReverse,
PictOpXor
}

Definition at line 127 of file qpaintengine_x11.cpp.

Referenced by qpainterOpToXrender().