diff options
Diffstat (limited to 'src/core/SkPictureRecord.cpp')
-rw-r--r-- | src/core/SkPictureRecord.cpp | 100 |
1 files changed, 67 insertions, 33 deletions
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 5810051..fd403cf 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -1,5 +1,11 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ #include "SkPictureRecord.h" -#include "SkShape.h" #include "SkTSearch.h" #define MIN_WRITER_SIZE 16384 @@ -122,45 +128,74 @@ void SkPictureRecord::setMatrix(const SkMatrix& matrix) { this->INHERITED::setMatrix(matrix); } -bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op) { - addDraw(CLIP_RECT); - addRect(rect); - addInt(op); +static bool regionOpExpands(SkRegion::Op op) { + switch (op) { + case SkRegion::kUnion_Op: + case SkRegion::kXOR_Op: + case SkRegion::kReverseDifference_Op: + case SkRegion::kReplace_Op: + return true; + case SkRegion::kIntersect_Op: + case SkRegion::kDifference_Op: + return false; + default: + SkDEBUGFAIL("unknown region op"); + return false; + } +} +void SkPictureRecord::recordOffsetForRestore(SkRegion::Op op) { + if (regionOpExpands(op)) { + // Run back through any previous clip ops, and mark their offset to + // be 0, disabling their ability to trigger a jump-to-restore, otherwise + // they could hide this clips ability to expand the clip (i.e. go from + // empty to non-empty). + uint32_t offset = fRestoreOffsetStack.top(); + while (offset) { + uint32_t* peek = fWriter.peek32(offset); + offset = *peek; + *peek = 0; + } + } + size_t offset = fWriter.size(); addInt(fRestoreOffsetStack.top()); fRestoreOffsetStack.top() = offset; +} + +bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { + addDraw(CLIP_RECT); + addRect(rect); + addInt(ClipParams_pack(op, doAA)); + + this->recordOffsetForRestore(op); validate(); - return this->INHERITED::clipRect(rect, op); + return this->INHERITED::clipRect(rect, op, doAA); } -bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op) { +bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { addDraw(CLIP_PATH); addPath(path); - addInt(op); + addInt(ClipParams_pack(op, doAA)); - size_t offset = fWriter.size(); - addInt(fRestoreOffsetStack.top()); - fRestoreOffsetStack.top() = offset; + this->recordOffsetForRestore(op); validate(); if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { - return this->INHERITED::clipRect(path.getBounds(), op); + return this->INHERITED::clipRect(path.getBounds(), op, doAA); } else { - return this->INHERITED::clipPath(path, op); + return this->INHERITED::clipPath(path, op, doAA); } } bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { addDraw(CLIP_REGION); addRegion(region); - addInt(op); + addInt(ClipParams_pack(op, false)); - size_t offset = fWriter.size(); - addInt(fRestoreOffsetStack.top()); - fRestoreOffsetStack.top() = offset; + this->recordOffsetForRestore(op); validate(); return this->INHERITED::clipRegion(region, op); @@ -223,7 +258,7 @@ void SkPictureRecord::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, } void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, - const SkPaint* paint) { + const SkPaint* paint) { addDraw(DRAW_BITMAP_MATRIX); addPaintPtr(paint); addBitmap(bitmap); @@ -231,6 +266,16 @@ void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m validate(); } +void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, + const SkRect& dst, const SkPaint* paint) { + addDraw(DRAW_BITMAP_NINE); + addPaintPtr(paint); + addBitmap(bitmap); + addIRect(center); + addRect(dst); + validate(); +} + void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint = NULL) { addDraw(DRAW_SPRITE); @@ -382,20 +427,6 @@ void SkPictureRecord::drawPicture(SkPicture& picture) { validate(); } -void SkPictureRecord::drawShape(SkShape* shape) { - addDraw(DRAW_SHAPE); - - int index = fShapes.find(shape); - if (index < 0) { // not found - index = fShapes.count(); - *fShapes.append() = shape; - shape->ref(); - } - // follow the convention of recording a 1-based index - addInt(index + 1); - validate(); -} - void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode*, @@ -447,7 +478,6 @@ void SkPictureRecord::reset() { fPaints.reset(); fPictureRefs.unrefAll(); fRegions.reset(); - fShapes.safeUnrefAll(); fWriter.reset(); fHeap.reset(); @@ -532,6 +562,10 @@ void SkPictureRecord::addRectPtr(const SkRect* rect) { } } +void SkPictureRecord::addIRect(const SkIRect& rect) { + fWriter.write(&rect, sizeof(rect)); +} + void SkPictureRecord::addIRectPtr(const SkIRect* rect) { if (fWriter.writeBool(rect != NULL)) { *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |