diff options
author | Florin Malita <fmalita@chromium.org> | 2017-04-28 10:57:24 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-28 15:21:22 +0000 |
commit | 713b8ef3748609ee20f6005a66d6aafd02aab4b6 (patch) | |
tree | 14a3483014ae5f1d9b45fa3c86f8b80e2ff60d42 /src/core | |
parent | d596c3f4643b93d2bc753b00ea3d55a34d78d116 (diff) |
Scrub DeviceCM
* remove unused fMatrix, fMatrixStorage
* fPaint -> std::unique_ptr<>
* fDevice -> sk_sp<>
Change-Id: I790b54bfc4d8154216e620a8c1642f3955fe7be0
Reviewed-on: https://skia-review.googlesource.com/14624
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkCanvas.cpp | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 897db3d45d..76b4a522b2 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -247,27 +247,18 @@ void SkCanvas::predrawNotify(const SkRect* rect, const SkPaint* paint, by the device's XY offset and bitmap-bounds. */ struct DeviceCM { - DeviceCM* fNext; - SkBaseDevice* fDevice; - SkRasterClip fClip; - SkPaint* fPaint; // may be null (in the future) - const SkMatrix* fMatrix; - SkMatrix fMatrixStorage; - SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer - - DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, const SkMatrix& stashed) + DeviceCM* fNext; + sk_sp<SkBaseDevice> fDevice; + SkRasterClip fClip; + std::unique_ptr<const SkPaint> fPaint; // may be null (in the future) + SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer + + DeviceCM(sk_sp<SkBaseDevice> device, const SkPaint* paint, const SkMatrix& stashed) : fNext(nullptr) + , fDevice(std::move(device)) + , fPaint(paint ? skstd::make_unique<SkPaint>(*paint) : nullptr) , fStashedMatrix(stashed) - { - SkSafeRef(device); - fDevice = device; - fPaint = paint ? new SkPaint(*paint) : nullptr; - } - - ~DeviceCM() { - SkSafeUnref(fDevice); - delete fPaint; - } + {} void reset(const SkIRect& bounds) { SkASSERT(!fPaint); @@ -348,8 +339,8 @@ public: bool next() { const DeviceCM* rec = fCurrLayer; if (rec && rec->fDevice) { - fDevice = rec->fDevice; - fPaint = rec->fPaint; + fDevice = rec->fDevice.get(); + fPaint = rec->fPaint.get(); fCurrLayer = rec->fNext; // fCurrLayer may be nullptr now return true; @@ -368,16 +359,16 @@ private: const SkPaint* fPaint; // May be null. }; -#define FOR_EACH_TOP_DEVICE( code ) \ - do { \ - DeviceCM* layer = fMCRec->fTopLayer; \ - while (layer) { \ - SkBaseDevice* device = layer->fDevice; \ - if (device) { \ - code; \ - } \ - layer = layer->fNext; \ - } \ +#define FOR_EACH_TOP_DEVICE( code ) \ + do { \ + DeviceCM* layer = fMCRec->fTopLayer; \ + while (layer) { \ + SkBaseDevice* device = layer->fDevice.get(); \ + if (device) { \ + code; \ + } \ + layer = layer->fNext; \ + } \ } while (0) ///////////////////////////////////////////////////////////////////////////// @@ -633,7 +624,7 @@ void SkCanvas::resetForNextPicture(const SkIRect& bounds) { // We're peering through a lot of structs here. Only at this scope do we // know that the device is a SkNoPixelsDevice. - static_cast<SkNoPixelsDevice*>(fMCRec->fLayer->fDevice)->resetForNextPicture(bounds); + static_cast<SkNoPixelsDevice*>(fMCRec->fLayer->fDevice.get())->resetForNextPicture(bounds); fDeviceClipBounds = qr_clip_bounds(bounds); fIsScaleTranslate = true; } @@ -657,7 +648,7 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; - new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fMCRec->fMatrix); + new (fDeviceCMStorage) DeviceCM(sk_ref_sp(device), nullptr, fMCRec->fMatrix); fMCRec->fTopLayer = fMCRec->fLayer; @@ -666,7 +657,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()); - fMCRec->fLayer->fDevice = SkRef(device); fMCRec->fRasterClip.setRect(device->getGlobalBounds()); fDeviceClipBounds = qr_clip_bounds(device->getGlobalBounds()); @@ -824,11 +814,11 @@ SkBaseDevice* SkCanvas::getDevice() const { // return root device MCRec* rec = (MCRec*) fMCStack.front(); SkASSERT(rec && rec->fLayer); - return rec->fLayer->fDevice; + return rec->fLayer->fDevice.get(); } SkBaseDevice* SkCanvas::getTopDevice() const { - return fMCRec->fTopLayer->fDevice; + return fMCRec->fTopLayer->fDevice.get(); } bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowBytes, int x, int y) { @@ -1157,8 +1147,7 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra return; } } - DeviceCM* layer = - new DeviceCM(newDevice.get(), paint, this, stashedMatrix); + DeviceCM* layer = new DeviceCM(newDevice, paint, stashedMatrix); // only have a "next" if this new layer doesn't affect the clip (rare) layer->fNext = BoundsAffectsClip(saveLayerFlags) ? nullptr : fMCRec->fTopLayer; @@ -1218,7 +1207,8 @@ void SkCanvas::internalRestore() { if (layer) { if (fMCRec) { const SkIPoint& origin = layer->fDevice->getOrigin(); - this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), layer->fPaint); + this->internalDrawDevice(layer->fDevice.get(), origin.x(), origin.y(), + layer->fPaint.get()); // restore what we smashed in internalSaveLayer fMCRec->fMatrix = layer->fStashedMatrix; // reset this, since internalDrawDevice will have set it to true @@ -3168,7 +3158,7 @@ static_assert((int)SkRegion::kReplace_Op == (int)kReplace_SkClipOp, " SkRasterHandleAllocator::Handle SkCanvas::accessTopRasterHandle() const { if (fAllocator && fMCRec->fTopLayer->fDevice) { - const SkBaseDevice* dev = fMCRec->fTopLayer->fDevice; + const auto& dev = fMCRec->fTopLayer->fDevice; SkRasterHandleAllocator::Handle handle = dev->getRasterHandle(); SkIPoint origin = dev->getOrigin(); SkMatrix ctm = this->getTotalMatrix(); |