diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-12 20:48:18 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-12 20:48:18 +0000 |
commit | 4ed0fb768409bf97b79899c3990d8c15f5e9d784 (patch) | |
tree | 18006613a412171f7b15931e71b2624169396d7a /src/core | |
parent | 1558d68b5c2d0d1734d5fe30ce90cbf0bc68d056 (diff) |
revert 6766, thereby re-landing 6762-6763 now that the bots are ready
git-svn-id: http://skia.googlecode.com/svn/trunk@6770 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkCanvas.cpp | 79 | ||||
-rw-r--r-- | src/core/SkPath.cpp | 17 | ||||
-rw-r--r-- | src/core/SkPictureFlat.h | 3 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 37 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.h | 3 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 53 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 6 | ||||
-rw-r--r-- | src/core/SkRRect.cpp | 24 |
8 files changed, 184 insertions, 38 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 34310c8248..3efdd22c3c 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -17,6 +17,7 @@ #include "SkMetaData.h" #include "SkPicture.h" #include "SkRasterClip.h" +#include "SkRRect.h" #include "SkScalarCompare.h" #include "SkSurface_Base.h" #include "SkTemplates.h" @@ -1125,6 +1126,18 @@ static bool clipPathHelper(const SkCanvas* canvas, SkRasterClip* currClip, } } +bool SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { + if (rrect.isRect()) { + // call the non-virtual version + return this->SkCanvas::clipRect(rrect.getBounds(), op, doAA); + } else { + SkPath path; + path.addRRect(rrect); + // call the non-virtual version + return this->SkCanvas::clipPath(path, op, doAA); + } +} + bool SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { #ifdef SK_ENABLE_CLIP_QUICKREJECT if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) { @@ -1466,6 +1479,40 @@ void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { LOOPER_END } +void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { + if (paint.canComputeFastBounds()) { + SkRect storage; + if (this->quickReject(paint.computeFastBounds(oval, &storage))) { + return; + } + } + + SkPath path; + path.addOval(oval); + // call the non-virtual version + this->SkCanvas::drawPath(path, paint); +} + +void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { + if (paint.canComputeFastBounds()) { + SkRect storage; + if (this->quickReject(paint.computeFastBounds(rrect.getBounds(), &storage))) { + return; + } + } + + if (rrect.isRect()) { + // call the non-virtual version + this->SkCanvas::drawRect(rrect.getBounds(), paint); + } else { + SkPath path; + path.addRRect(rrect); + // call the non-virtual version + this->SkCanvas::drawPath(path, paint); + } +} + + void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { if (!path.isFinite()) { return; @@ -1898,17 +1945,7 @@ void SkCanvas::drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, SkRect r; r.set(cx - radius, cy - radius, cx + radius, cy + radius); - - if (paint.canComputeFastBounds()) { - SkRect storage; - if (this->quickReject(paint.computeFastBounds(r, &storage))) { - return; - } - } - - SkPath path; - path.addOval(r); - this->drawPath(path, paint); + this->drawOval(r, paint); } void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, @@ -1920,28 +1957,14 @@ void SkCanvas::drawRoundRect(const SkRect& r, SkScalar rx, SkScalar ry, return; } } - - SkPath path; - path.addRoundRect(r, rx, ry, SkPath::kCW_Direction); - this->drawPath(path, paint); + SkRRect rrect; + rrect.setRectXY(r, rx, ry); + this->drawRRect(rrect, paint); } else { this->drawRect(r, paint); } } -void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { - if (paint.canComputeFastBounds()) { - SkRect storage; - if (this->quickReject(paint.computeFastBounds(oval, &storage))) { - return; - } - } - - SkPath path; - path.addOval(oval); - this->drawPath(path, paint); -} - void SkCanvas::drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint& paint) { diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index fe9551492d..ae1d187d0d 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -11,9 +11,9 @@ #include "SkBuffer.h" #include "SkMath.h" #include "SkPathRef.h" +#include "SkRRect.h" #include "SkThread.h" - //////////////////////////////////////////////////////////////////////////// #if SK_DEBUG_PATH_REF @@ -1088,6 +1088,21 @@ void SkPath::addRoundRect(const SkRect& rect, const SkScalar rad[], this->close(); } +void SkPath::addRRect(const SkRRect& rrect, Direction dir) { + const SkRect& bounds = rrect.getBounds(); + + if (rrect.isRect()) { + this->addRect(bounds, dir); + } else if (rrect.isOval()) { + this->addOval(bounds, dir); + } else if (rrect.isSimple()) { + const SkVector& rad = rrect.getSimpleRadii(); + this->addRoundRect(bounds, rad.x(), rad.y(), dir); + } else { + this->addRoundRect(bounds, (const SkScalar*)&rrect.fRadii[0], dir); + } +} + bool SkPath::hasOnlyMoveTos() const { int count = fPathRef->countVerbs(); const uint8_t* verbs = const_cast<const SkPathRef*>(fPathRef.get())->verbsMemBegin(); diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 429236150b..9594a594dd 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -29,6 +29,7 @@ enum DrawType { CLIP_PATH, CLIP_REGION, CLIP_RECT, + CLIP_RRECT, CONCAT, DRAW_BITMAP, DRAW_BITMAP_MATRIX, @@ -36,6 +37,7 @@ enum DrawType { DRAW_BITMAP_RECT_TO_RECT, DRAW_CLEAR, DRAW_DATA, + DRAW_OVAL, DRAW_PAINT, DRAW_PATH, DRAW_PICTURE, @@ -45,6 +47,7 @@ enum DrawType { DRAW_POS_TEXT_H, DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H DRAW_RECT, + DRAW_RRECT, DRAW_SPRITE, DRAW_TEXT, DRAW_TEXT_ON_PATH, diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 9a8f133d8a..31ee3ece3a 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -634,7 +634,7 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { #endif #ifdef SPEW_CLIP_SKIPPING - SkipClipRec skipRect, skipRegion, skipPath; + SkipClipRec skipRect, skipRRect, skipRegion, skipPath; #endif #ifdef SK_BUILD_FOR_ANDROID @@ -731,7 +731,7 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { bool doAA = ClipParams_unpackDoAA(packed); size_t offsetToRestore = reader.readInt(); SkASSERT(!offsetToRestore || \ - offsetToRestore >= reader.offset()); + offsetToRestore >= reader.offset()); if (!canvas.clipRect(rect, op, doAA) && offsetToRestore) { #ifdef SPEW_CLIP_SKIPPING skipRect.recordSkip(offsetToRestore - reader.offset()); @@ -739,6 +739,22 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { reader.setOffset(offsetToRestore); } } break; + case CLIP_RRECT: { + SkRRect rrect; + reader.readRRect(&rrect); + uint32_t packed = reader.readInt(); + SkRegion::Op op = ClipParams_unpackRegionOp(packed); + bool doAA = ClipParams_unpackDoAA(packed); + size_t offsetToRestore = reader.readInt(); + SkASSERT(!offsetToRestore || \ + offsetToRestore >= reader.offset()); + if (!canvas.clipRRect(rrect, op, doAA) && offsetToRestore) { +#ifdef SPEW_CLIP_SKIPPING + skipRRect.recordSkip(offsetToRestore - reader.offset()); +#endif + reader.setOffset(offsetToRestore); + } + } break; case CONCAT: canvas.concat(*getMatrix(reader)); break; @@ -776,6 +792,10 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { canvas.drawData(reader.skip(length), length); // skip handles padding the read out to a multiple of 4 } break; + case DRAW_OVAL: { + const SkPaint& paint = *getPaint(reader); + canvas.drawOval(reader.skipT<SkRect>(), paint); + } break; case DRAW_PAINT: canvas.drawPaint(*getPaint(reader)); break; @@ -837,6 +857,11 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { const SkPaint& paint = *getPaint(reader); canvas.drawRect(reader.skipT<SkRect>(), paint); } break; + case DRAW_RRECT: { + const SkPaint& paint = *getPaint(reader); + SkRRect rrect; + canvas.drawRRect(*reader.readRRect(&rrect), paint); + } break; case DRAW_SPRITE: { const SkPaint* paint = getPaint(reader); const SkBitmap& bitmap = getBitmap(reader); @@ -952,10 +977,10 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { #ifdef SPEW_CLIP_SKIPPING { - size_t size = skipRect.fSize + skipPath.fSize + skipRegion.fSize; - SkDebugf("--- Clip skips %d%% rect:%d path:%d rgn:%d\n", - size * 100 / reader.offset(), skipRect.fCount, skipPath.fCount, - skipRegion.fCount); + size_t size = skipRect.fSize + skipRRect.fSize + skipPath.fSize + skipRegion.fSize; + SkDebugf("--- Clip skips %d%% rect:%d rrect:%d path:%d rgn:%d\n", + size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, + skipPath.fCount, skipRegion.fCount); } #endif // this->dumpSize(); diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h index 8f52b19314..13a685fb92 100644 --- a/src/core/SkPicturePlayback.h +++ b/src/core/SkPicturePlayback.h @@ -19,6 +19,7 @@ #include "SkPath.h" #include "SkPathHeap.h" #include "SkRegion.h" +#include "SkRRect.h" #include "SkPictureFlat.h" #include "SkSerializationHelpers.h" @@ -147,7 +148,7 @@ private: int index = reader.readInt(); return (*fRegions)[index - 1]; } - + void getText(SkReader32& reader, TextContainer* text) { size_t length = text->fByteLength = reader.readInt(); text->fText = (const char*)reader.skip(length); diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 3c4df53b1e..82257c8e57 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -8,6 +8,7 @@ #include "SkPictureRecord.h" #include "SkTSearch.h" #include "SkPixelRef.h" +#include "SkRRect.h" #include "SkBBoxHierarchy.h" #include "SkPictureStateTree.h" @@ -111,6 +112,7 @@ static inline uint32_t getSkipableSize(unsigned drawType) { 4, // CLIP_PATH, 4, // CLIP_REGION, 7, // CLIP_RECT, + 15, // CLIP_RRECT, 2, // CONCAT, 0, // DRAW_BITMAP, 0, // DRAW_BITMAP_MATRIX, @@ -118,6 +120,7 @@ static inline uint32_t getSkipableSize(unsigned drawType) { 0, // DRAW_BITMAP_RECT, 0, // DRAW_CLEAR, 0, // DRAW_DATA, + 0, // DRAW_OVAL, 0, // DRAW_PAINT, 0, // DRAW_PATH, 0, // DRAW_PICTURE, @@ -127,6 +130,7 @@ static inline uint32_t getSkipableSize(unsigned drawType) { 0, // DRAW_POS_TEXT_H, 0, // DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H 0, // DRAW_RECT, + 0, // DRAW_RRECT, 0, // DRAW_SPRITE, 0, // DRAW_TEXT, 0, // DRAW_TEXT_ON_PATH, @@ -352,11 +356,30 @@ bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { addRect(rect); addInt(ClipParams_pack(op, doAA)); recordRestoreOffsetPlaceholder(op); - + validate(); return this->INHERITED::clipRect(rect, op, doAA); } +bool SkPictureRecord::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { + if (rrect.isRect()) { + return this->SkPictureRecord::clipRect(rrect.getBounds(), op, doAA); + } + + addDraw(CLIP_RRECT); + addRRect(rrect); + addInt(ClipParams_pack(op, doAA)); + recordRestoreOffsetPlaceholder(op); + + validate(); + + if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { + return this->INHERITED::clipRect(rrect.getBounds(), op, doAA); + } else { + return this->INHERITED::clipRRect(rrect, op, doAA); + } +} + bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { SkRect r; @@ -410,6 +433,13 @@ void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts validate(); } +void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) { + addDraw(DRAW_OVAL); + addPaint(paint); + addRect(oval); + validate(); +} + void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { addDraw(DRAW_RECT); addPaint(paint); @@ -417,6 +447,23 @@ void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) { validate(); } +void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { + if (rrect.isRect()) { + addDraw(DRAW_RECT); + addPaint(paint); + addRect(rrect.getBounds()); + } else if (rrect.isOval()) { + addDraw(DRAW_OVAL); + addPaint(paint); + addRect(rrect.getBounds()); + } else { + addDraw(DRAW_RRECT); + addPaint(paint); + addRRect(rrect); + } + validate(); +} + void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) { addDraw(DRAW_PATH); addPaint(paint); @@ -754,6 +801,10 @@ void SkPictureRecord::addIRectPtr(const SkIRect* rect) { } } +void SkPictureRecord::addRRect(const SkRRect& rrect) { + fWriter.writeRRect(rrect); +} + void SkPictureRecord::addRegion(const SkRegion& region) { addInt(fRegions.find(region)); } diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 77a6b04fc7..abaa22dd9d 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -36,13 +36,16 @@ public: virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE; + virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE; virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE; virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; virtual void clear(SkColor) SK_OVERRIDE; virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) SK_OVERRIDE; - virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; + virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; + virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; + virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE; @@ -129,6 +132,7 @@ private: void addRectPtr(const SkRect* rect); void addIRect(const SkIRect& rect); void addIRectPtr(const SkIRect* rect); + void addRRect(const SkRRect&); void addRegion(const SkRegion& region); void addText(const void* text, size_t byteLength); diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp index 5740a19c82..c409cd6fd7 100644 --- a/src/core/SkRRect.cpp +++ b/src/core/SkRRect.cpp @@ -227,6 +227,30 @@ void SkRRect::computeType() const { fType = kComplex_Type; } +/////////////////////////////////////////////////////////////////////////////// + +uint32_t SkRRect::writeToMemory(void* buffer) const { + SkASSERT(kSizeInMemory == sizeof(SkRect) + sizeof(fRadii)); + + memcpy(buffer, &fRect, sizeof(SkRect)); + memcpy((char*)buffer + sizeof(SkRect), fRadii, sizeof(fRadii)); + return kSizeInMemory; +} + +uint32_t SkRRect::readFromMemory(const void* buffer) { + SkScalar storage[12]; + SkASSERT(sizeof(storage) == kSizeInMemory); + + // we make a local copy, to ensure alignment before we cast + memcpy(storage, buffer, kSizeInMemory); + + this->setRectRadii(*(const SkRect*)&storage[0], + (const SkVector*)&storage[4]); + return kSizeInMemory; +} + +/////////////////////////////////////////////////////////////////////////////// + #ifdef SK_DEBUG void SkRRect::validate() const { bool allRadiiZero = (0 == fRadii[0].fX && 0 == fRadii[0].fY); |