Qt 4.8
Classes | Public Functions | Public Variables | List of all members
QClipData Class Reference

#include <qpaintengine_raster_p.h>

Classes

struct  ClipLine
 

Public Functions

void appendSpan (int x, int length, int y, int coverage)
 
void appendSpans (const QSpan *s, int num)
 
ClipLineclipLines ()
 
void fixup ()
 
void initialize ()
 
 QClipData (int height)
 
void setClipRect (const QRect &rect)
 
void setClipRegion (const QRegion &region)
 
QSpanspans ()
 
 ~QClipData ()
 

Public Variables

int allocated
 
QRect clipRect
 
QRegion clipRegion
 
int clipSpanHeight
 
int count
 
uint enabled: 1
 
uint hasRectClip: 1
 
uint hasRegionClip: 1
 
struct QClipData::ClipLinem_clipLines
 
QSpanm_spans
 
int xmax
 
int xmin
 
int ymax
 
int ymin
 

Detailed Description

Definition at line 386 of file qpaintengine_raster_p.h.

Constructors and Destructors

◆ QClipData()

QClipData::QClipData ( int  height)

Definition at line 4080 of file qpaintengine_raster.cpp.

4081 {
4082  clipSpanHeight = height;
4083  m_clipLines = 0;
4084 
4085  allocated = 0;
4086  m_spans = 0;
4087  xmin = xmax = ymin = ymax = 0;
4088  count = 0;
4089 
4090  enabled = true;
4091  hasRectClip = hasRegionClip = false;
4092 }
struct QClipData::ClipLine * m_clipLines

◆ ~QClipData()

QClipData::~QClipData ( )

Definition at line 4094 of file qpaintengine_raster.cpp.

4095 {
4096  if (m_clipLines)
4097  free(m_clipLines);
4098  if (m_spans)
4099  free(m_spans);
4100 }
struct QClipData::ClipLine * m_clipLines

Functions

◆ appendSpan()

void QClipData::appendSpan ( int  x,
int  length,
int  y,
int  coverage 
)
inline

Definition at line 438 of file qpaintengine_raster_p.h.

Referenced by qt_merge_clip().

439 {
440  Q_ASSERT(m_spans); // initialize() has to be called prior to adding spans..
441 
442  if (count == allocated) {
443  allocated *= 2;
444  m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
445  }
446  m_spans[count].x = x;
447  m_spans[count].len = length;
448  m_spans[count].y = y;
449  m_spans[count].coverage = coverage;
450  ++count;
451 }
unsigned char coverage
unsigned short len
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ appendSpans()

void QClipData::appendSpans ( const QSpan s,
int  num 
)
inline

Definition at line 453 of file qpaintengine_raster_p.h.

Referenced by qt_merge_clip(), and qt_span_clip().

454 {
455  Q_ASSERT(m_spans);
456 
457  if (count + num > allocated) {
458  do {
459  allocated *= 2;
460  } while (count + num > allocated);
461  m_spans = (QSpan *)realloc(m_spans, allocated*sizeof(QSpan));
462  }
463  memcpy(m_spans+count, s, num*sizeof(QSpan));
464  count += num;
465 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ clipLines()

ClipLine* QClipData::clipLines ( )
inline

Definition at line 403 of file qpaintengine_raster_p.h.

403  {
404  if (!m_clipLines)
405  initialize();
406  return m_clipLines;
407  }
struct QClipData::ClipLine * m_clipLines

◆ fixup()

void QClipData::fixup ( )

Definition at line 4216 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip().

4217 {
4218  Q_ASSERT(m_spans);
4219 
4220  if (count == 0) {
4221  ymin = ymax = xmin = xmax = 0;
4222  return;
4223  }
4224 
4225  int y = -1;
4226  ymin = m_spans[0].y;
4227  ymax = m_spans[count-1].y + 1;
4228  xmin = INT_MAX;
4229  xmax = 0;
4230 
4231  const int firstLeft = m_spans[0].x;
4232  const int firstRight = m_spans[0].x + m_spans[0].len;
4233  bool isRect = true;
4234 
4235  for (int i = 0; i < count; ++i) {
4236  QT_FT_Span_& span = m_spans[i];
4237 
4238  if (span.y != y) {
4239  if (span.y != y + 1 && y != -1)
4240  isRect = false;
4241  y = span.y;
4242  m_clipLines[y].spans = &span;
4243  m_clipLines[y].count = 1;
4244  } else
4245  ++m_clipLines[y].count;
4246 
4247  const int spanLeft = span.x;
4248  const int spanRight = spanLeft + span.len;
4249 
4250  if (spanLeft < xmin)
4251  xmin = spanLeft;
4252 
4253  if (spanRight > xmax)
4254  xmax = spanRight;
4255 
4256  if (spanLeft != firstLeft || spanRight != firstRight)
4257  isRect = false;
4258  }
4259 
4260  if (isRect) {
4261  hasRectClip = true;
4263  }
4264 }
unsigned short len
static bool isRect(const T *pts, int elementCount)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
struct QClipData::ClipLine * m_clipLines
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
#define INT_MAX

◆ initialize()

void QClipData::initialize ( )

Definition at line 4102 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip(), qt_merge_clip(), and qt_span_clip().

4103 {
4104  if (m_spans)
4105  return;
4106 
4107  if (!m_clipLines)
4108  m_clipLines = (ClipLine *)calloc(sizeof(ClipLine), clipSpanHeight);
4109 
4111  QT_TRY {
4112  m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan));
4115 
4116  QT_TRY {
4117  if (hasRectClip) {
4118  int y = 0;
4119  while (y < ymin) {
4120  m_clipLines[y].spans = 0;
4121  m_clipLines[y].count = 0;
4122  ++y;
4123  }
4124 
4125  const int len = clipRect.width();
4126  count = 0;
4127  while (y < ymax) {
4128  QSpan *span = m_spans + count;
4129  span->x = xmin;
4130  span->len = len;
4131  span->y = y;
4132  span->coverage = 255;
4133  ++count;
4134 
4135  m_clipLines[y].spans = span;
4136  m_clipLines[y].count = 1;
4137  ++y;
4138  }
4139 
4140  while (y < clipSpanHeight) {
4141  m_clipLines[y].spans = 0;
4142  m_clipLines[y].count = 0;
4143  ++y;
4144  }
4145  } else if (hasRegionClip) {
4146 
4147  const QVector<QRect> rects = clipRegion.rects();
4148  const int numRects = rects.size();
4149 
4150  { // resize
4151  const int maxSpans = (ymax - ymin) * numRects;
4152  if (maxSpans > allocated) {
4153  m_spans = q_check_ptr((QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)));
4154  allocated = maxSpans;
4155  }
4156  }
4157 
4158  int y = 0;
4159  int firstInBand = 0;
4160  count = 0;
4161  while (firstInBand < numRects) {
4162  const int currMinY = rects.at(firstInBand).y();
4163  const int currMaxY = currMinY + rects.at(firstInBand).height();
4164 
4165  while (y < currMinY) {
4166  m_clipLines[y].spans = 0;
4167  m_clipLines[y].count = 0;
4168  ++y;
4169  }
4170 
4171  int lastInBand = firstInBand;
4172  while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y)
4173  ++lastInBand;
4174 
4175  while (y < currMaxY) {
4176 
4177  m_clipLines[y].spans = m_spans + count;
4178  m_clipLines[y].count = lastInBand - firstInBand + 1;
4179 
4180  for (int r = firstInBand; r <= lastInBand; ++r) {
4181  const QRect &currRect = rects.at(r);
4182  QSpan *span = m_spans + count;
4183  span->x = currRect.x();
4184  span->len = currRect.width();
4185  span->y = y;
4186  span->coverage = 255;
4187  ++count;
4188  }
4189  ++y;
4190  }
4191 
4192  firstInBand = lastInBand + 1;
4193  }
4194 
4195  Q_ASSERT(count <= allocated);
4196 
4197  while (y < clipSpanHeight) {
4198  m_clipLines[y].spans = 0;
4199  m_clipLines[y].count = 0;
4200  ++y;
4201  }
4202 
4203  }
4204  } QT_CATCH(...) {
4205  free(m_spans); // have to free m_spans again or someone might think that we were successfully initialized.
4206  m_spans = 0;
4207  QT_RETHROW;
4208  }
4209  } QT_CATCH(...) {
4210  free(m_clipLines); // same for clipLines
4211  m_clipLines = 0;
4212  QT_RETHROW;
4213  }
4214 }
T * q_check_ptr(T *p)
Definition: qglobal.h:1857
unsigned char coverage
unsigned short len
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
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_RETHROW
Definition: qglobal.h:1539
#define calloc(a, b)
struct QClipData::ClipLine * m_clipLines
#define QT_CATCH(A)
Definition: qglobal.h:1537
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
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
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define QT_TRY
Definition: qglobal.h:1536

◆ setClipRect()

void QClipData::setClipRect ( const QRect rect)

Definition at line 4269 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::setClipRectInDeviceCoords().

4270 {
4271  if (hasRectClip && rect == clipRect)
4272  return;
4273 
4274 // qDebug() << "setClipRect" << clipSpanHeight << count << allocated << rect;
4275  hasRectClip = true;
4276  hasRegionClip = false;
4277  clipRect = rect;
4278 
4279  xmin = rect.x();
4280  xmax = rect.x() + rect.width();
4281  ymin = qMin(rect.y(), clipSpanHeight);
4282  ymax = qMin(rect.y() + rect.height(), clipSpanHeight);
4283 
4284  if (m_spans) {
4285  free(m_spans);
4286  m_spans = 0;
4287  }
4288 
4289 // qDebug() << xmin << xmax << ymin << ymax;
4290 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
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
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

◆ setClipRegion()

void QClipData::setClipRegion ( const QRegion region)

Definition at line 4295 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip(), and QRasterPaintEngine::setClipRectInDeviceCoords().

4296 {
4297  if (region.rectCount() == 1) {
4298  setClipRect(region.rects().at(0));
4299  return;
4300  }
4301 
4302  hasRegionClip = true;
4303  hasRectClip = false;
4304  clipRegion = region;
4305 
4306  { // set bounding rect
4307  const QRect rect = region.boundingRect();
4308  xmin = rect.x();
4309  xmax = rect.x() + rect.width();
4310  ymin = rect.y();
4311  ymax = rect.y() + rect.height();
4312  }
4313 
4314  if (m_spans) {
4315  free(m_spans);
4316  m_spans = 0;
4317  }
4318 
4319 }
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
void setClipRect(const QRect &rect)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
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
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ spans()

QSpan* QClipData::spans ( )
inline

Definition at line 409 of file qpaintengine_raster_p.h.

409  {
410  if (!m_spans)
411  initialize();
412  return m_spans;
413  }

Properties

◆ allocated

int QClipData::allocated

Definition at line 415 of file qpaintengine_raster_p.h.

Referenced by qt_span_clip().

◆ clipRect

QRect QClipData::clipRect

◆ clipRegion

QRegion QClipData::clipRegion

◆ clipSpanHeight

int QClipData::clipSpanHeight

Definition at line 395 of file qpaintengine_raster_p.h.

Referenced by qt_merge_clip().

◆ count

int QClipData::count

◆ enabled

uint QClipData::enabled

◆ hasRectClip

uint QClipData::hasRectClip

◆ hasRegionClip

uint QClipData::hasRegionClip

◆ m_clipLines

struct QClipData::ClipLine * QClipData::m_clipLines

◆ m_spans

QSpan* QClipData::m_spans

Definition at line 417 of file qpaintengine_raster_p.h.

Referenced by qt_intersect_spans(), and qt_span_clip().

◆ xmax

int QClipData::xmax

◆ xmin

int QClipData::xmin

◆ ymax

int QClipData::ymax

◆ ymin

int QClipData::ymin

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