From 2c9e20055be772feb3f44986c1af0c0a979eff49 Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 25 Jul 2016 08:05:22 -0700 Subject: [PATCH] remove fClipStack and attach/deattach-from-canvas BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2180793002 Review-Url: https://codereview.chromium.org/2180793002 --- include/core/SkBitmapDevice.h | 2 -- include/core/SkDevice.h | 30 ------------------------------ src/core/SkBitmapDevice.cpp | 18 ++++++------------ src/core/SkCanvas.cpp | 11 ++--------- src/core/SkDevice.cpp | 7 +------ src/gpu/SkGpuDevice.cpp | 20 +------------------- src/gpu/SkGpuDevice.h | 4 ---- src/pdf/SkPDFDevice.cpp | 14 -------------- src/pdf/SkPDFDevice.h | 4 ---- 9 files changed, 10 insertions(+), 100 deletions(-) diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index 85beb1619b..bb6d6ec1e8 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -152,8 +152,6 @@ protected: bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) override; bool onPeekPixels(SkPixmap*) override; bool onAccessPixels(SkPixmap*) override; - void onAttachToCanvas(SkCanvas*) override; - void onDetachFromCanvas() override; private: friend class SkCanvas; diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index 4a2d656e97..f3b484e4be 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -112,32 +112,6 @@ public: */ const SkIPoint& getOrigin() const { return fOrigin; } - /** - * onAttachToCanvas is invoked whenever a device is installed in a canvas - * (i.e., setDevice, saveLayer (for the new device created by the save), - * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the - * devices to prepare for drawing (e.g., locking their pixels, etc.) - */ - virtual void onAttachToCanvas(SkCanvas*) { - SkASSERT(!fAttachedToCanvas); -#ifdef SK_DEBUG - fAttachedToCanvas = true; -#endif - }; - - /** - * onDetachFromCanvas notifies a device that it will no longer be drawn to. - * It gives the device a chance to clean up (e.g., unlock its pixels). It - * is invoked from setDevice (for the displaced device), restore and - * possibly from SkCanvas' dtor. - */ - virtual void onDetachFromCanvas() { - SkASSERT(fAttachedToCanvas); -#ifdef SK_DEBUG - fAttachedToCanvas = false; -#endif - }; - protected: enum TileUsage { kPossible_TileUsage, //!< the created device may be drawn tiled @@ -398,10 +372,6 @@ private: SkBitmap fLegacyBitmap; #endif -#ifdef SK_DEBUG - bool fAttachedToCanvas; -#endif - typedef SkRefCnt INHERITED; }; diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index dcdc55bbfb..4b25e21e86 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -70,8 +70,10 @@ static bool valid_for_bitmap_device(const SkImageInfo& info, SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) - , fBitmap(bitmap) { + , fBitmap(bitmap) +{ SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); + fBitmap.lockPixels(); } SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { @@ -80,8 +82,10 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps) : INHERITED(surfaceProps) - , fBitmap(bitmap) { + , fBitmap(bitmap) +{ SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); + fBitmap.lockPixels(); } SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, @@ -183,16 +187,6 @@ bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); } -void SkBitmapDevice::onAttachToCanvas(SkCanvas* canvas) { - INHERITED::onAttachToCanvas(canvas); - fBitmap.lockPixels(); -} - -void SkBitmapDevice::onDetachFromCanvas() { - INHERITED::onDetachFromCanvas(); - fBitmap.unlockPixels(); -} - /////////////////////////////////////////////////////////////////////////////// void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 2cfe8ae2da..ffdcf9d5de 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -207,19 +207,13 @@ struct DeviceCM { , fClip(conservativeRasterClip) , fStashedMatrix(stashed) { - if (nullptr != device) { - device->ref(); - device->onAttachToCanvas(canvas); - } + SkSafeRef(device); fDevice = device; fPaint = paint ? new SkPaint(*paint) : nullptr; } ~DeviceCM() { - if (fDevice) { - fDevice->onDetachFromCanvas(); - fDevice->unref(); - } + SkSafeUnref(fDevice); delete fPaint; } @@ -684,7 +678,6 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { if (device) { // The root device and the canvas should always have the same pixel geometry SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry()); - device->onAttachToCanvas(this); fMCRec->fLayer->fDevice = SkRef(device); fMCRec->fRasterClip.setRect(device->getGlobalBounds()); } diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 75d481e98f..14250ab775 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -23,12 +23,7 @@ #include "SkTextBlobRunIterator.h" #include "SkTextToPathIter.h" -SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) - : fSurfaceProps(surfaceProps) -#ifdef SK_DEBUG - , fAttachedToCanvas(false) -#endif -{ +SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) : fSurfaceProps(surfaceProps) { fOrigin.setZero(); fMetaData = nullptr; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 88f584711c..602396fc21 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -287,30 +287,12 @@ bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { return false; } -void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { - ASSERT_SINGLE_OWNER - INHERITED::onAttachToCanvas(canvas); - - // Canvas promises that this ptr is valid until onDetachFromCanvas is called - fClipStack.reset(SkRef(canvas->getClipStack())); -} - -void SkGpuDevice::onDetachFromCanvas() { - ASSERT_SINGLE_OWNER - INHERITED::onDetachFromCanvas(); - fClip.reset(); - fClipStack.reset(nullptr); -} - // call this every draw call, to ensure that the context reflects our state, // and not the state from some other canvas/device void SkGpuDevice::prepareDraw(const SkDraw& draw) { ASSERT_SINGLE_OWNER - SkASSERT(fClipStack.get()); - - SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack); - fClip.reset(fClipStack, &this->getOrigin()); + fClip.reset(draw.fClipStack, &this->getOrigin()); } GrDrawContext* SkGpuDevice::accessDrawContext() { diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index 7e646a13f1..4cfd02421a 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -146,9 +146,6 @@ public: void flush() override; - void onAttachToCanvas(SkCanvas* canvas) override; - void onDetachFromCanvas() override; - bool onAccessPixels(SkPixmap*) override; // for debugging purposes only @@ -165,7 +162,6 @@ private: sk_sp fRenderTarget; sk_sp fDrawContext; - SkAutoTUnref fClipStack; SkIPoint fClipOrigin; GrClipStackClip fClip; SkISize fSize; diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 8370eabd6a..4181defc5d 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -653,7 +653,6 @@ SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* do , fPageSize(pageSize) , fContentSize(pageSize) , fExistingClipRegion(SkIRect::MakeSize(pageSize)) - , fClipStack(nullptr) , fRasterDpi(rasterDpi) , fDocument(doc) { SkASSERT(pageSize.width() > 0); @@ -1405,19 +1404,6 @@ SkImageInfo SkPDFDevice::imageInfo() const { return info; } -void SkPDFDevice::onAttachToCanvas(SkCanvas* canvas) { - INHERITED::onAttachToCanvas(canvas); - - // Canvas promises that this ptr is valid until onDetachFromCanvas is called - fClipStack = canvas->getClipStack(); -} - -void SkPDFDevice::onDetachFromCanvas() { - INHERITED::onDetachFromCanvas(); - - fClipStack = nullptr; -} - sk_sp SkPDFDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { return SkSurface::MakeRaster(info, &props); } diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index f8497c63ff..6a167d979a 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -119,8 +119,6 @@ public: void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override; - void onAttachToCanvas(SkCanvas* canvas) override; - void onDetachFromCanvas() override; SkImageInfo imageInfo() const override; // PDF specific methods. @@ -256,8 +254,6 @@ private: }; SkSinglyLinkedList fContentEntries; - const SkClipStack* fClipStack; - SkScalar fRasterDpi; SkPDFDocument* fDocument; -- 2.34.1