aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkBitmapDevice.cpp')
-rw-r--r--src/core/SkBitmapDevice.cpp84
1 files changed, 59 insertions, 25 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 45ec2b70ae..5742e1d0a3 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -71,11 +71,10 @@ static bool valid_for_bitmap_device(const SkImageInfo& info,
SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap)
: INHERITED(bitmap.info(), SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))
, fBitmap(bitmap)
+ , fRCStack(bitmap.width(), bitmap.height())
{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
fBitmap.lockPixels();
-
- fRCStack.push_back().setRect(SkIRect::MakeWH(bitmap.width(), bitmap.height()));
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) {
@@ -87,11 +86,10 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
: INHERITED(bitmap.info(), surfaceProps)
, fBitmap(bitmap)
, fRasterHandle(hndl)
+ , fRCStack(bitmap.width(), bitmap.height())
{
SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
fBitmap.lockPixels();
-
- fRCStack.push_back().setRect(SkIRect::MakeWH(bitmap.width(), bitmap.height()));
}
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
@@ -137,6 +135,8 @@ void SkBitmapDevice::setNewSize(const SkISize& size) {
SkASSERT(!fBitmap.pixelRef());
fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight));
this->privateResize(fBitmap.info().width(), fBitmap.info().height());
+
+ fRCStack.setNewSize(size.fWidth, size.fHeight);
}
void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
@@ -191,17 +191,35 @@ bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_USE_DEVICE_CLIPPING
+class ModifiedDraw : public SkDraw {
+public:
+ ModifiedDraw(const SkMatrix& devCTM, const SkRasterClip& rc, SkISize rcs,
+ const SkDraw& draw) : SkDraw(draw) {
+#ifdef SK_DEBUG
+ SkISize dvs = { draw.fDevice->width(), draw.fDevice->height() };
+ SkASSERT(dvs == rcs);
+ SkASSERT(devCTM == *draw.fMatrix);
+#endif
+ fRC = &rc;
+ }
+};
+#define PREPARE_DRAW(draw) ModifiedDraw(this->ctm(), fRCStack.rc(), fRCStack.getRootSize(), draw)
+#else
+#define PREPARE_DRAW(draw) draw
+#endif
+
void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
- draw.drawPaint(paint);
+ PREPARE_DRAW(draw).drawPaint(paint);
}
void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint) {
- draw.drawPoints(mode, count, pts, paint);
+ PREPARE_DRAW(draw).drawPoints(mode, count, pts, paint);
}
void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) {
- draw.drawRect(r, paint);
+ PREPARE_DRAW(draw).drawRect(r, paint);
}
void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
@@ -221,20 +239,20 @@ void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
// required to override drawRRect.
this->drawPath(draw, path, paint, nullptr, true);
#else
- draw.drawRRect(rrect, paint);
+ PREPARE_DRAW(draw).drawRRect(rrect, paint);
#endif
}
void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path,
const SkPaint& paint, const SkMatrix* prePathMatrix,
bool pathIsMutable) {
- draw.drawPath(path, paint, prePathMatrix, pathIsMutable);
+ PREPARE_DRAW(draw).drawPath(path, paint, prePathMatrix, pathIsMutable);
}
void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
const SkMatrix& matrix, const SkPaint& paint) {
LogDrawScaleFactor(SkMatrix::Concat(*draw.fMatrix, matrix), paint.getFilterQuality());
- draw.drawBitmap(bitmap, matrix, nullptr, paint);
+ PREPARE_DRAW(draw).drawBitmap(bitmap, matrix, nullptr, paint);
}
static inline bool CanApplyDstMatrixAsCTM(const SkMatrix& m, const SkPaint& paint) {
@@ -323,7 +341,7 @@ void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
// matrix with the CTM, and try to call drawSprite if it can. If not,
// it will make a shader and call drawRect, as we do below.
if (CanApplyDstMatrixAsCTM(matrix, paint)) {
- draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint);
+ PREPARE_DRAW(draw).drawBitmap(*bitmapPtr, matrix, dstPtr, paint);
return;
}
}
@@ -353,18 +371,18 @@ void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
int x, int y, const SkPaint& paint) {
- draw.drawSprite(bitmap, x, y, paint);
+ PREPARE_DRAW(draw).drawSprite(bitmap, x, y, paint);
}
void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint) {
- draw.drawText((const char*)text, len, x, y, paint);
+ PREPARE_DRAW(draw).drawText((const char*)text, len, x, y, paint);
}
void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
const SkScalar xpos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& paint) {
- draw.drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint);
+ PREPARE_DRAW(draw).drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint);
}
void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
@@ -373,14 +391,14 @@ void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode
const SkColor colors[], SkBlendMode bmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
- draw.drawVertices(vmode, vertexCount, verts, textures, colors, bmode,
+ PREPARE_DRAW(draw).drawVertices(vmode, vertexCount, verts, textures, colors, bmode,
indices, indexCount, paint);
}
void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
int x, int y, const SkPaint& paint) {
SkASSERT(!paint.getImageFilter());
- draw.drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint);
+ PREPARE_DRAW(draw).drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint);
}
///////////////////////////////////////////////////////////////////////////////
@@ -459,28 +477,44 @@ bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
void SkBitmapDevice::onSave() {
- fRCStack.push_back(fRCStack.back());
+ fRCStack.save();
}
void SkBitmapDevice::onRestore() {
- fRCStack.pop_back();
+ fRCStack.restore();
}
void SkBitmapDevice::onClipRect(const SkRect& rect, SkClipOp op, bool aa) {
- fRCStack.back().op(rect, this->ctm(), SkIRect::MakeWH(this->width(), this->height()),
- (SkRegion::Op)op, aa);
+ fRCStack.clipRect(this->ctm(), rect, op, aa);
}
void SkBitmapDevice::onClipRRect(const SkRRect& rrect, SkClipOp op, bool aa) {
- fRCStack.back().op(rrect, this->ctm(), SkIRect::MakeWH(this->width(), this->height()),
- (SkRegion::Op)op, aa);
+ fRCStack.clipRRect(this->ctm(), rrect, op, aa);
}
void SkBitmapDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) {
- fRCStack.back().op(path, this->ctm(), SkIRect::MakeWH(this->width(), this->height()),
- (SkRegion::Op)op, aa);
+ fRCStack.clipPath(this->ctm(), path, op, aa);
}
void SkBitmapDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) {
- fRCStack.back().op(rgn, (SkRegion::Op)op);
+ SkIPoint origin = this->getOrigin();
+ SkRegion tmp;
+ const SkRegion* ptr = &rgn;
+ if (origin.fX | origin.fY) {
+ // translate from "global/canvas" coordinates to relative to this device
+ rgn.translate(-origin.fX, -origin.fY, &tmp);
+ ptr = &tmp;
+ }
+ fRCStack.clipRegion(*ptr, op);
+}
+
+void SkBitmapDevice::onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) {
+ fRCStack.setDeviceClipRestriction(mutableClipRestriction);
+}
+
+void SkBitmapDevice::validateDevBounds(const SkIRect& drawClipBounds) {
+#ifdef SK_DEBUG
+ const SkIRect& stackBounds = fRCStack.rc().getBounds();
+ SkASSERT(drawClipBounds == stackBounds);
+#endif
}