diff options
-rw-r--r-- | include/core/SkBBHFactory.h | 8 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 2 | ||||
-rw-r--r-- | include/core/SkDevice.h | 7 | ||||
-rw-r--r-- | include/core/SkPicture.h | 7 | ||||
-rw-r--r-- | include/core/SkPictureRecorder.h | 11 | ||||
-rw-r--r-- | samplecode/SampleArc.cpp | 23 | ||||
-rw-r--r-- | src/core/SkBBHFactory.cpp | 13 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 15 | ||||
-rw-r--r-- | src/core/SkCanvasDrawable.cpp | 22 | ||||
-rw-r--r-- | src/core/SkPicture.cpp | 5 | ||||
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 17 | ||||
-rw-r--r-- | src/core/SkRecorder.cpp | 8 | ||||
-rw-r--r-- | src/core/SkRecorder.h | 3 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 2 |
14 files changed, 40 insertions, 103 deletions
diff --git a/include/core/SkBBHFactory.h b/include/core/SkBBHFactory.h index 2cc37e5491..67c9cd767d 100644 --- a/include/core/SkBBHFactory.h +++ b/include/core/SkBBHFactory.h @@ -9,7 +9,7 @@ #define SkBBHFactory_DEFINED #include "SkSize.h" -#include "SkRect.h" +#include "SkPoint.h" class SkBBoxHierarchy; @@ -18,13 +18,13 @@ public: /** * Allocate a new SkBBoxHierarchy. Return NULL on failure. */ - virtual SkBBoxHierarchy* operator()(const SkRect& bounds) const = 0; + virtual SkBBoxHierarchy* operator()(int width, int height) const = 0; virtual ~SkBBHFactory() {}; }; class SK_API SkRTreeFactory : public SkBBHFactory { public: - virtual SkBBoxHierarchy* operator()(const SkRect& bounds) const SK_OVERRIDE; + virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; private: typedef SkBBHFactory INHERITED; }; @@ -50,7 +50,7 @@ public: SkTileGridFactory(const TileGridInfo& info) : fInfo(info) { } - virtual SkBBoxHierarchy* operator()(const SkRect& bounds) const SK_OVERRIDE; + virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE; private: TileGridInfo fInfo; diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index d172674c41..276b39236f 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -1335,7 +1335,7 @@ private: kDefault_InitFlags = 0, kConservativeRasterClip_InitFlag = 1 << 0, }; - SkCanvas(const SkIRect& bounds, InitFlags); + SkCanvas(int width, int height, InitFlags); SkCanvas(SkBaseDevice*, const SkSurfaceProps*, InitFlags); SkCanvas(const SkBitmap&, const SkSurfaceProps&); diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 3c26baca5b..471a76be8e 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -53,12 +53,6 @@ public: bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height()); } - SkIRect getGlobalBounds() const { - SkIRect bounds; - this->getGlobalBounds(&bounds); - return bounds; - } - int width() const { return this->imageInfo().width(); } @@ -372,7 +366,6 @@ private: friend class SkDeviceFilteredPaint; friend class SkDeviceImageFilterProxy; friend class SkDeferredDevice; // for newSurface - friend class SkNoPixelsBitmapDevice; friend class SkSurface_Raster; diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index c69db37ffa..99bca367d9 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -130,7 +130,7 @@ public: It does not necessarily reflect the bounds of what has been recorded into the picture. @return the cull rect used to create this picture */ - SkRect cullRect() const { return fCullRect; } + const SkRect cullRect() const { return SkRect::MakeWH(fCullWidth, fCullHeight); } /** Return a non-zero, unique value representing the picture. This call is only valid when not recording. Between a beginRecording/endRecording @@ -260,14 +260,15 @@ private: static bool IsValidPictInfo(const SkPictInfo& info); // Takes ownership of the SkRecord, refs the (optional) drawablePicts and BBH. - SkPicture(const SkRect& cullRect, SkRecord*, SkData* drawablePicts, + SkPicture(SkScalar width, SkScalar height, SkRecord*, SkData* drawablePicts, SkBBoxHierarchy*); static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*); static SkPictureData* Backport(const SkRecord&, const SkPictInfo&, SkPicture const* const drawablePics[], int drawableCount); - const SkRect fCullRect; + const SkScalar fCullWidth; + const SkScalar fCullHeight; mutable SkAutoTUnref<const AccelData> fAccelData; mutable SkTDArray<DeletionListener*> fDeletionListeners; // pointers are refed SkAutoTDelete<SkRecord> fRecord; diff --git a/include/core/SkPictureRecorder.h b/include/core/SkPictureRecorder.h index a8ca600b81..de216b4e5b 100644 --- a/include/core/SkPictureRecorder.h +++ b/include/core/SkPictureRecorder.h @@ -50,15 +50,9 @@ public: @param recordFlags optional flags that control recording. @return the canvas. */ - SkCanvas* beginRecording(const SkRect& bounds, - SkBBHFactory* bbhFactory = NULL, - uint32_t recordFlags = 0); - SkCanvas* beginRecording(SkScalar width, SkScalar height, SkBBHFactory* bbhFactory = NULL, - uint32_t recordFlags = 0) { - return this->beginRecording(SkRect::MakeWH(width, height), bbhFactory, recordFlags); - } + uint32_t recordFlags = 0); /** Returns the recording canvas if one is active, or NULL if recording is not active. This does not alter the refcnt on the canvas (if present). @@ -85,7 +79,8 @@ private: void partialReplay(SkCanvas* canvas) const; uint32_t fFlags; - SkRect fCullRect; + SkScalar fCullWidth; + SkScalar fCullHeight; SkAutoTUnref<SkBBoxHierarchy> fBBH; SkAutoTUnref<SkRecorder> fRecorder; SkAutoTDelete<SkRecord> fRecord; diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index ecea90bf3f..a44eeb59ba 100644 --- a/samplecode/SampleArc.cpp +++ b/samplecode/SampleArc.cpp @@ -37,27 +37,6 @@ static void testparse() { SkParsePath::ToSVGString(p2, &str2); } -#include "SkPictureRecorder.h" -static void test_pictbounds(SkCanvas* canvas) { - SkRect r = SkRect::MakeXYWH(100, 50, 100, 100); - SkPictureRecorder recorder; - { - SkCanvas* c = recorder.beginRecording(r, NULL, 0); - c->drawOval(r, SkPaint()); - - SkIRect ir; - c->getClipDeviceBounds(&ir); - SkDebugf("devbounds [%d %d %d %d]\n", ir.left(), ir.top(), ir.right(), ir.bottom()); - - SkASSERT(!c->quickReject(r)); - } - SkPicture* pic = recorder.endRecording(); - - canvas->drawPicture(pic); - SkASSERT(pic->cullRect() == r); - pic->unref(); -} - class ArcsView : public SampleView { class MyDrawable : public SkCanvasDrawable { SkRect fR; @@ -197,8 +176,6 @@ protected: } virtual void onDrawContent(SkCanvas* canvas) { - if (true) { test_pictbounds(canvas); return; } - fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24, SkIntToScalar(360))); diff --git a/src/core/SkBBHFactory.cpp b/src/core/SkBBHFactory.cpp index 4b9ae558e2..22f816c4d9 100644 --- a/src/core/SkBBHFactory.cpp +++ b/src/core/SkBBHFactory.cpp @@ -9,20 +9,15 @@ #include "SkRTree.h" #include "SkTileGrid.h" -SkBBoxHierarchy* SkRTreeFactory::operator()(const SkRect& bounds) const { - SkScalar aspectRatio = bounds.width() / bounds.height(); + +SkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const { + SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width), SkIntToScalar(height)); return SkNEW_ARGS(SkRTree, (aspectRatio)); } -SkBBoxHierarchy* SkTileGridFactory::operator()(const SkRect& bounds) const { +SkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const { SkASSERT(fInfo.fMargin.width() >= 0); SkASSERT(fInfo.fMargin.height() >= 0); - - // We want a conservative answer for the size... - const SkIRect ibounds = bounds.roundOut(); - const int width = ibounds.width(); - const int height = ibounds.height(); - // Note: SkIRects are non-inclusive of the right() column and bottom() row. // For example, an SkIRect at 0,0 with a size of (1,1) will only have // content at pixel (0,0) and will report left=0 and right=1, hence the diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 31a9a7970b..4fda7a37b3 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -431,7 +431,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { } device->onAttachToCanvas(this); fMCRec->fLayer->fDevice = SkRef(device); - fMCRec->fRasterClip.setRect(device->getGlobalBounds()); + fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->height())); } return device; } @@ -453,11 +453,7 @@ static SkBitmap make_nopixels(int width, int height) { class SkNoPixelsBitmapDevice : public SkBitmapDevice { public: - SkNoPixelsBitmapDevice(const SkIRect& bounds) - : INHERITED(make_nopixels(bounds.width(), bounds.height())) - { - this->setOrigin(bounds.x(), bounds.y()); - } + SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(width, height)) {} private: @@ -470,17 +466,16 @@ SkCanvas::SkCanvas(int width, int height) { inc_canvas(); - this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, - (SkIRect::MakeWH(width, height))), kDefault_InitFlags)->unref(); + this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_InitFlags)->unref(); } -SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) +SkCanvas::SkCanvas(int width, int height, InitFlags flags) : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) , fProps(SkSurfaceProps::kLegacyFontHost_InitType) { inc_canvas(); - this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (bounds)), flags)->unref(); + this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unref(); } SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags) diff --git a/src/core/SkCanvasDrawable.cpp b/src/core/SkCanvasDrawable.cpp index e0120f0bb1..0065d430f9 100644 --- a/src/core/SkCanvasDrawable.cpp +++ b/src/core/SkCanvasDrawable.cpp @@ -23,22 +23,9 @@ static int32_t next_generation_id() { SkCanvasDrawable::SkCanvasDrawable() : fGenerationID(0) {} -static void draw_bbox(SkCanvas* canvas, const SkRect& r) { - SkPaint paint; - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(0xFFFF7088); - canvas->drawRect(r, paint); - canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint); - canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint); -} - void SkCanvasDrawable::draw(SkCanvas* canvas) { SkAutoCanvasRestore acr(canvas, true); this->onDraw(canvas); - - if (false) { - draw_bbox(canvas, this->getBounds()); - } } SkPicture* SkCanvasDrawable::newPictureSnapshot(SkBBHFactory* bbhFactory, uint32_t recordFlags) { @@ -65,13 +52,8 @@ void SkCanvasDrawable::notifyDrawingChanged() { #include "SkPictureRecorder.h" SkPicture* SkCanvasDrawable::onNewPictureSnapshot(SkBBHFactory* bbhFactory, uint32_t recordFlags) { - SkPictureRecorder recorder; - const SkRect bounds = this->getBounds(); - SkCanvas* canvas = recorder.beginRecording(bounds, bbhFactory, recordFlags); - this->draw(canvas); - if (false) { - draw_bbox(canvas, bounds); - } + SkPictureRecorder recorder; + this->draw(recorder.beginRecording(bounds.width(), bounds.height(), bbhFactory, recordFlags)); return recorder.endRecording(); } diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 7f4b33afac..4c97cb71b9 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -530,9 +530,10 @@ uint32_t SkPicture::uniqueID() const { return fUniqueID; } -SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawablePicts, +SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkData* drawablePicts, SkBBoxHierarchy* bbh) - : fCullRect(cullRect) + : fCullWidth(width) + , fCullHeight(height) , fRecord(record) , fBBH(SkSafeRef(bbh)) , fDrawablePicts(SkSafeRef(drawablePicts)) diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index aea9e389da..bc8bffb9b3 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -18,19 +18,20 @@ SkPictureRecorder::SkPictureRecorder() {} SkPictureRecorder::~SkPictureRecorder() {} -SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, +SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height, SkBBHFactory* bbhFactory /* = NULL */, uint32_t recordFlags /* = 0 */) { - fCullRect = cullRect; fFlags = recordFlags; + fCullWidth = width; + fCullHeight = height; if (bbhFactory) { - fBBH.reset((*bbhFactory)(cullRect)); + fBBH.reset((*bbhFactory)(width, height)); SkASSERT(fBBH.get()); } fRecord.reset(SkNEW(SkRecord)); - fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); + fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); return this->getRecordingCanvas(); } @@ -51,10 +52,12 @@ SkPicture* SkPictureRecorder::endRecording() { } if (fBBH.get()) { + SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight); + if (saveLayerData) { - SkRecordComputeLayers(fCullRect, *fRecord, fBBH.get(), saveLayerData); + SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData); } else { - SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); + SkRecordFillBounds(cullRect, *fRecord, fBBH.get()); } } @@ -62,7 +65,7 @@ SkPicture* SkPictureRecorder::endRecording() { SkBBHFactory* factory = NULL; uint32_t recordFlags = 0; SkAutoDataUnref drawablePicts(fRecorder->newDrawableSnapshot(factory, recordFlags)); - SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord.detach(), + SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.detach(), drawablePicts, fBBH.get())); if (saveLayerData) { diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 998fb6645b..1af328afd2 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -10,13 +10,9 @@ #include "SkPatchUtils.h" #include "SkPicture.h" +// SkCanvas will fail in mysterious ways if it doesn't know the real width and height. SkRecorder::SkRecorder(SkRecord* record, int width, int height) - : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag) - , fRecord(record) - , fSaveLayerCount(0) {} - -SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) - : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) + : SkCanvas(width, height, SkCanvas::kConservativeRasterClip_InitFlag) , fRecord(record) , fSaveLayerCount(0) {} diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h index 7b2cbfe3a0..563f16d124 100644 --- a/src/core/SkRecorder.h +++ b/src/core/SkRecorder.h @@ -18,8 +18,7 @@ class SkRecorder : public SkCanvas { public: // Does not take ownership of the SkRecord. - SkRecorder(SkRecord*, int width, int height); // legacy version - SkRecorder(SkRecord*, const SkRect& bounds); + SkRecorder(SkRecord*, int width, int height); virtual ~SkRecorder() SK_OVERRIDE; // return a (new or ref'd) data containing the array of pictures that were diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index c9298335f1..5bc60371c9 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -1842,7 +1842,7 @@ struct CountingBBH : public SkBBoxHierarchy { class SpoonFedBBHFactory : public SkBBHFactory { public: explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} - SkBBoxHierarchy* operator()(const SkRect&) const SK_OVERRIDE { + virtual SkBBoxHierarchy* operator()(int width, int height) const { return SkRef(fBBH); } private: |