Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: src/core/SkCanvas.cpp

Issue 1763143002: WIP RasterCanvasLayerAllocator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test and some further work Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
11 #include "SkClipStack.h" 11 #include "SkClipStack.h"
12 #include "SkColorFilter.h" 12 #include "SkColorFilter.h"
13 #include "SkDraw.h" 13 #include "SkDraw.h"
14 #include "SkDrawable.h" 14 #include "SkDrawable.h"
15 #include "SkDrawFilter.h" 15 #include "SkDrawFilter.h"
16 #include "SkDrawLooper.h" 16 #include "SkDrawLooper.h"
17 #include "SkErrorInternals.h" 17 #include "SkErrorInternals.h"
18 #include "SkImage.h" 18 #include "SkImage.h"
19 #include "SkImage_Base.h" 19 #include "SkImage_Base.h"
20 #include "SkImageFilter.h" 20 #include "SkImageFilter.h"
21 #include "SkImageFilterCache.h" 21 #include "SkImageFilterCache.h"
22 #include "SkMatrixUtils.h" 22 #include "SkMatrixUtils.h"
23 #include "SkMetaData.h" 23 #include "SkMetaData.h"
24 #include "SkNinePatchIter.h" 24 #include "SkNinePatchIter.h"
25 #include "SkPaintPriv.h" 25 #include "SkPaintPriv.h"
26 #include "SkPatchUtils.h" 26 #include "SkPatchUtils.h"
27 #include "SkPicture.h" 27 #include "SkPicture.h"
28 #include "SkRasterCanvasLayerAllocator.h"
28 #include "SkRasterClip.h" 29 #include "SkRasterClip.h"
29 #include "SkReadPixelsRec.h" 30 #include "SkReadPixelsRec.h"
30 #include "SkRRect.h" 31 #include "SkRRect.h"
31 #include "SkSmallAllocator.h" 32 #include "SkSmallAllocator.h"
32 #include "SkSpecialImage.h" 33 #include "SkSpecialImage.h"
33 #include "SkSurface_Base.h" 34 #include "SkSurface_Base.h"
34 #include "SkTextBlob.h" 35 #include "SkTextBlob.h"
35 #include "SkTextFormatParams.h" 36 #include "SkTextFormatParams.h"
36 #include "SkTLazy.h" 37 #include "SkTLazy.h"
37 #include "SkTraceEvent.h" 38 #include "SkTraceEvent.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 these are used (assuming we're not on a layer) we rebuild these cache 190 these are used (assuming we're not on a layer) we rebuild these cache
190 values: they reflect the top of the save stack, but translated and clipped 191 values: they reflect the top of the save stack, but translated and clipped
191 by the device's XY offset and bitmap-bounds. 192 by the device's XY offset and bitmap-bounds.
192 */ 193 */
193 struct DeviceCM { 194 struct DeviceCM {
194 DeviceCM* fNext; 195 DeviceCM* fNext;
195 SkBaseDevice* fDevice; 196 SkBaseDevice* fDevice;
196 SkRasterClip fClip; 197 SkRasterClip fClip;
197 SkPaint* fPaint; // may be null (in the future) 198 SkPaint* fPaint; // may be null (in the future)
198 const SkMatrix* fMatrix; 199 const SkMatrix* fMatrix;
200 SkRasterCanvasLayerAllocator* fAllocator;
201 void* fNativeContext;
199 SkMatrix fMatrixStorage; 202 SkMatrix fMatrixStorage;
200 SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer 203 SkMatrix fStashedMatrix; // original CTM; used by imagefilter in saveLayer
201 const bool fDeviceIsBitmapDevice; 204 const bool fDeviceIsBitmapDevice;
202 205
203 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, 206 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
204 bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMat rix& stashed) 207 bool conservativeRasterClip, bool deviceIsBitmapDevice, const SkMat rix& stashed)
205 : fNext(nullptr) 208 : fNext(nullptr)
206 , fClip(conservativeRasterClip) 209 , fClip(conservativeRasterClip)
210 , fAllocator(nullptr)
211 , fNativeContext(nullptr)
207 , fStashedMatrix(stashed) 212 , fStashedMatrix(stashed)
208 , fDeviceIsBitmapDevice(deviceIsBitmapDevice) 213 , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
209 { 214 {
210 if (nullptr != device) { 215 if (nullptr != device) {
211 device->ref(); 216 device->ref();
212 device->onAttachToCanvas(canvas); 217 device->onAttachToCanvas(canvas);
213 } 218 }
214 fDevice = device; 219 fDevice = device;
215 fPaint = paint ? new SkPaint(*paint) : nullptr; 220 fPaint = paint ? new SkPaint(*paint) : nullptr;
216 } 221 }
217 222
218 ~DeviceCM() { 223 ~DeviceCM() {
219 if (fDevice) { 224 if (fDevice) {
225 if (fAllocator) {
226 fAllocator->free(fDevice->accessBitmap(false).getPixels(),
227 fNativeContext);
228 }
220 fDevice->onDetachFromCanvas(); 229 fDevice->onDetachFromCanvas();
221 fDevice->unref(); 230 fDevice->unref();
222 } 231 }
223 delete fPaint; 232 delete fPaint;
224 } 233 }
225 234
226 void reset(const SkIRect& bounds) { 235 void reset(const SkIRect& bounds) {
227 SkASSERT(!fPaint); 236 SkASSERT(!fPaint);
228 SkASSERT(!fNext); 237 SkASSERT(!fNext);
229 SkASSERT(fDevice); 238 SkASSERT(fDevice);
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 fCachedLocalClipBounds.setEmpty(); 645 fCachedLocalClipBounds.setEmpty();
637 fCachedLocalClipBoundsDirty = true; 646 fCachedLocalClipBoundsDirty = true;
638 fClipStack->reset(); 647 fClipStack->reset();
639 fMCRec->reset(bounds); 648 fMCRec->reset(bounds);
640 649
641 // We're peering through a lot of structs here. Only at this scope do we 650 // We're peering through a lot of structs here. Only at this scope do we
642 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce). 651 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce).
643 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e()); 652 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e());
644 } 653 }
645 654
646 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 655 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags,
656 sk_sp<SkRasterCanvasLayerAllocator> allocator) {
647 if (device && device->forceConservativeRasterClip()) { 657 if (device && device->forceConservativeRasterClip()) {
648 flags = InitFlags(flags | kConservativeRasterClip_InitFlag); 658 flags = InitFlags(flags | kConservativeRasterClip_InitFlag);
649 } 659 }
650 // Since init() is only called once by our constructors, it is safe to perfo rm this 660 // Since init() is only called once by our constructors, it is safe to perfo rm this
651 // const-cast. 661 // const-cast.
652 *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativ eRasterClip_InitFlag); 662 *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativ eRasterClip_InitFlag);
653 663
654 fCachedLocalClipBounds.setEmpty(); 664 fCachedLocalClipBounds.setEmpty();
655 fCachedLocalClipBoundsDirty = true; 665 fCachedLocalClipBoundsDirty = true;
656 fAllowSoftClip = true; 666 fAllowSoftClip = true;
657 fAllowSimplifyClip = false; 667 fAllowSimplifyClip = false;
658 fDeviceCMDirty = true; 668 fDeviceCMDirty = true;
659 fSaveCount = 1; 669 fSaveCount = 1;
660 fMetaData = nullptr; 670 fMetaData = nullptr;
661 671
662 fClipStack.reset(new SkClipStack); 672 fClipStack.reset(new SkClipStack);
663 673
664 fMCRec = (MCRec*)fMCStack.push_back(); 674 fMCRec = (MCRec*)fMCStack.push_back();
665 new (fMCRec) MCRec(fConservativeRasterClip); 675 new (fMCRec) MCRec(fConservativeRasterClip);
666 676
667 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 677 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
668 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 678 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
669 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, false, 679 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, false,
670 fMCRec->fMatrix); 680 fMCRec->fMatrix);
671 681
672 fMCRec->fTopLayer = fMCRec->fLayer; 682 fMCRec->fTopLayer = fMCRec->fLayer;
673 683
674 fSurfaceBase = nullptr; 684 fSurfaceBase = nullptr;
685 fAllocator = allocator;
686 fMCRec->fLayer->fAllocator = allocator.get();
675 687
676 if (device) { 688 if (device) {
677 // The root device and the canvas should always have the same pixel geom etry 689 // The root device and the canvas should always have the same pixel geom etry
678 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( )); 690 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( ));
679 device->onAttachToCanvas(this); 691 device->onAttachToCanvas(this);
680 fMCRec->fLayer->fDevice = SkRef(device); 692 fMCRec->fLayer->fDevice = SkRef(device);
681 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); 693 fMCRec->fRasterClip.setRect(device->getGlobalBounds());
682 } 694 }
683 return device; 695 return device;
684 } 696 }
685 697
686 SkCanvas::SkCanvas() 698 SkCanvas::SkCanvas()
687 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 699 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
688 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 700 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
689 , fConservativeRasterClip(false) 701 , fConservativeRasterClip(false)
690 { 702 {
691 inc_canvas(); 703 inc_canvas();
692 704
693 this->init(nullptr, kDefault_InitFlags); 705 this->init(nullptr, kDefault_InitFlags, nullptr);
694 } 706 }
695 707
696 static SkBitmap make_nopixels(int width, int height) { 708 static SkBitmap make_nopixels(int width, int height) {
697 SkBitmap bitmap; 709 SkBitmap bitmap;
698 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); 710 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height));
699 return bitmap; 711 return bitmap;
700 } 712 }
701 713
702 class SkNoPixelsBitmapDevice : public SkBitmapDevice { 714 class SkNoPixelsBitmapDevice : public SkBitmapDevice {
703 public: 715 public:
704 SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceP rops) 716 SkNoPixelsBitmapDevice(const SkIRect& bounds, const SkSurfaceProps& surfaceP rops)
705 : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps ) 717 : INHERITED(make_nopixels(bounds.width(), bounds.height()), surfaceProps )
706 { 718 {
707 this->setOrigin(bounds.x(), bounds.y()); 719 this->setOrigin(bounds.x(), bounds.y());
708 } 720 }
709 721
710 private: 722 private:
711 723
712 typedef SkBitmapDevice INHERITED; 724 typedef SkBitmapDevice INHERITED;
713 }; 725 };
714 726
715 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) 727 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props)
716 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 728 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
717 , fProps(SkSurfacePropsCopyOrDefault(props)) 729 , fProps(SkSurfacePropsCopyOrDefault(props))
718 , fConservativeRasterClip(false) 730 , fConservativeRasterClip(false)
719 { 731 {
720 inc_canvas(); 732 inc_canvas();
721 733
722 this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps ), 734 this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps ),
723 kDefault_InitFlags)->unref(); 735 kDefault_InitFlags, nullptr)->unref();
724 } 736 }
725 737
726 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) 738 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags)
727 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 739 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
728 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 740 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
729 , fConservativeRasterClip(false) 741 , fConservativeRasterClip(false)
730 { 742 {
731 inc_canvas(); 743 inc_canvas();
732 744
733 this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags)->unref(); 745 this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags,
746 nullptr)->unref();
734 } 747 }
735 748
736 SkCanvas::SkCanvas(SkBaseDevice* device) 749 SkCanvas::SkCanvas(SkBaseDevice* device)
737 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 750 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
738 , fProps(device->surfaceProps()) 751 , fProps(device->surfaceProps())
739 , fConservativeRasterClip(false) 752 , fConservativeRasterClip(false)
740 { 753 {
741 inc_canvas(); 754 inc_canvas();
742 755
743 this->init(device, kDefault_InitFlags); 756 this->init(device, kDefault_InitFlags, nullptr);
744 } 757 }
745 758
746 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) 759 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags)
747 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 760 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
748 , fProps(device->surfaceProps()) 761 , fProps(device->surfaceProps())
749 , fConservativeRasterClip(false) 762 , fConservativeRasterClip(false)
750 { 763 {
751 inc_canvas(); 764 inc_canvas();
752 765
753 this->init(device, flags); 766 this->init(device, flags, nullptr);
754 } 767 }
755 768
756 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) 769 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
757 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 770 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
758 , fProps(props) 771 , fProps(props)
759 , fConservativeRasterClip(false) 772 , fConservativeRasterClip(false)
760 { 773 {
761 inc_canvas(); 774 inc_canvas();
762 775
763 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); 776 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
764 this->init(device, kDefault_InitFlags); 777 this->init(device, kDefault_InitFlags, nullptr);
765 } 778 }
766 779
767 SkCanvas::SkCanvas(const SkBitmap& bitmap) 780 SkCanvas::SkCanvas(const SkBitmap& bitmap)
768 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 781 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
769 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 782 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
770 , fConservativeRasterClip(false) 783 , fConservativeRasterClip(false)
771 { 784 {
772 inc_canvas(); 785 inc_canvas();
773 786
774 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps)); 787 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
775 this->init(device, kDefault_InitFlags); 788 this->init(device, kDefault_InitFlags, nullptr);
789 }
790
791 SkCanvas::SkCanvas(const SkBitmap& bitmap,
792 sk_sp<SkRasterCanvasLayerAllocator> allocator)
793 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
794 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
795 , fConservativeRasterClip(false)
796 {
797 inc_canvas();
798
799 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
800 this->init(device, kDefault_InitFlags, allocator);
801 // TODO(tomhudson): this is circuitous, wasteful, and ugly to boot
802 this->fMCRec->fLayer->fNativeContext =
803 allocator->getNativeContext(this->accessTopLayerPixels(nullptr, nullptr) );
776 } 804 }
777 805
778 SkCanvas::~SkCanvas() { 806 SkCanvas::~SkCanvas() {
779 // free up the contents of our deque 807 // free up the contents of our deque
780 this->restoreToCount(1); // restore everything but the last 808 this->restoreToCount(1); // restore everything but the last
781 809
782 this->internalRestore(); // restore the last, since we're going away 810 this->internalRestore(); // restore the last, since we're going away
783 811
784 delete fMetaData; 812 delete fMetaData;
785 813
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 SkImageInfo info = make_layer_info(device->imageInfo(), ir.width(), ir.heigh t(), isOpaque, 1296 SkImageInfo info = make_layer_info(device->imageInfo(), ir.width(), ir.heigh t(), isOpaque,
1269 paint); 1297 paint);
1270 1298
1271 bool forceSpriteOnRestore = false; 1299 bool forceSpriteOnRestore = false;
1272 { 1300 {
1273 const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() || 1301 const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() ||
1274 (saveLayerFlags & kPreserveLCDText_SaveLaye rFlag); 1302 (saveLayerFlags & kPreserveLCDText_SaveLaye rFlag);
1275 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; 1303 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
1276 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo, 1304 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo,
1277 pres erveLCDText, false); 1305 pres erveLCDText, false);
1278 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); 1306 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint, fAlloca tor.get());
1279 if (nullptr == newDev) { 1307 if (nullptr == newDev) {
1280 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint) 1308 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint)
1281 const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelG eometry); 1309 const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelG eometry);
1282 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); 1310 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps);
1283 if (nullptr == newDev) { 1311 if (nullptr == newDev) {
1284 SkErrorInternals::SetError(kInternalError_SkError, 1312 SkErrorInternals::SetError(kInternalError_SkError,
1285 "Unable to create device for layer.") ; 1313 "Unable to create device for layer.") ;
1286 return; 1314 return;
1287 } 1315 }
1288 forceSpriteOnRestore = true; 1316 forceSpriteOnRestore = true;
1289 } 1317 }
1290 device = newDev; 1318 device = newDev;
1291 } 1319 }
1292 device->setOrigin(ir.fLeft, ir.fTop); 1320 device->setOrigin(ir.fLeft, ir.fTop);
1293 1321
1294 if (rec.fBackdrop) { 1322 if (rec.fBackdrop) {
1295 draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, devic e, fMCRec->fMatrix); 1323 draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, devic e, fMCRec->fMatrix);
1296 } 1324 }
1297 1325
1298 DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip, 1326 DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip,
1299 forceSpriteOnRestore, stashedMatrix); 1327 forceSpriteOnRestore, stashedMatrix);
1300 device->unref(); 1328 device->unref();
1301 1329
1302 layer->fNext = fMCRec->fTopLayer; 1330 layer->fNext = fMCRec->fTopLayer;
1331 layer->fAllocator = fAllocator.get();
1332 layer->fNativeContext = fAllocator
1333 ? fAllocator->getNativeContext(device->accessBitmap(false).getPixels())
1334 : nullptr;
1303 fMCRec->fLayer = layer; 1335 fMCRec->fLayer = layer;
1304 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1336 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1305 } 1337 }
1306 1338
1307 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1339 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
1308 if (0xFF == alpha) { 1340 if (0xFF == alpha) {
1309 return this->saveLayer(bounds, nullptr); 1341 return this->saveLayer(bounds, nullptr);
1310 } else { 1342 } else {
1311 SkPaint tmpPaint; 1343 SkPaint tmpPaint;
1312 tmpPaint.setAlpha(alpha); 1344 tmpPaint.setAlpha(alpha);
1313 return this->saveLayer(bounds, &tmpPaint); 1345 return this->saveLayer(bounds, &tmpPaint);
1314 } 1346 }
1315 } 1347 }
1316 1348
1317 void SkCanvas::internalRestore() { 1349 void SkCanvas::internalRestore() {
1318 SkASSERT(fMCStack.count() != 0); 1350 SkASSERT(fMCStack.count() != 0);
1319 1351
1320 fDeviceCMDirty = true; 1352 fDeviceCMDirty = true;
1321 fCachedLocalClipBoundsDirty = true; 1353 fCachedLocalClipBoundsDirty = true;
1322 1354
1323 fClipStack->restore(); 1355 fClipStack->restore();
1324 1356
1325 // reserve our layer (if any) 1357 // reserve our layer (if any)
1326 DeviceCM* layer = fMCRec->fLayer; // may be null 1358 DeviceCM* layer = fMCRec->fLayer; // may be null
1359
1327 // now detach it from fMCRec so we can pop(). Gets freed after its drawn 1360 // now detach it from fMCRec so we can pop(). Gets freed after its drawn
1328 fMCRec->fLayer = nullptr; 1361 fMCRec->fLayer = nullptr;
1329 1362
1330 // now do the normal restore() 1363 // now do the normal restore()
1331 fMCRec->~MCRec(); // balanced in save() 1364 fMCRec->~MCRec(); // balanced in save()
1332 fMCStack.pop_back(); 1365 fMCStack.pop_back();
1333 fMCRec = (MCRec*)fMCStack.back(); 1366 fMCRec = (MCRec*)fMCStack.back();
1334 1367
1335 /* Time to draw the layer's offscreen. We can't call the public drawSprite, 1368 /* Time to draw the layer's offscreen. We can't call the public drawSprite,
1336 since if we're being recorded, we don't want to record this (the 1369 since if we're being recorded, we don't want to record this (the
1337 recorder will have already recorded the restore). 1370 recorder will have already recorded the restore).
1338 */ 1371 */
1339 if (layer) { 1372 if (layer) {
1373 SkASSERT(layer->fAllocator == fAllocator.get());
1340 if (layer->fNext) { 1374 if (layer->fNext) {
1341 const SkIPoint& origin = layer->fDevice->getOrigin(); 1375 const SkIPoint& origin = layer->fDevice->getOrigin();
1342 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), 1376 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
1343 layer->fPaint, layer->fDeviceIsBitmapDevice ); 1377 layer->fPaint, layer->fDeviceIsBitmapDevice );
1344 // restore what we smashed in internalSaveLayer 1378 // restore what we smashed in internalSaveLayer
1345 fMCRec->fMatrix = layer->fStashedMatrix; 1379 fMCRec->fMatrix = layer->fStashedMatrix;
1346 // reset this, since internalDrawDevice will have set it to true 1380 // reset this, since internalDrawDevice will have set it to true
1347 fDeviceCMDirty = true; 1381 fDeviceCMDirty = true;
1348 delete layer; 1382 delete layer;
1349 } else { 1383 } else {
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 1794
1761 void SkCanvas::replayClips(ClipVisitor* visitor) const { 1795 void SkCanvas::replayClips(ClipVisitor* visitor) const {
1762 SkClipStack::B2TIter iter(*fClipStack); 1796 SkClipStack::B2TIter iter(*fClipStack);
1763 const SkClipStack::Element* element; 1797 const SkClipStack::Element* element;
1764 1798
1765 while ((element = iter.next()) != nullptr) { 1799 while ((element = iter.next()) != nullptr) {
1766 element->replay(visitor); 1800 element->replay(visitor);
1767 } 1801 }
1768 } 1802 }
1769 1803
1804 void* SkCanvas::getTopLayerNative() const {
1805 return fMCRec->fLayer->fNativeContext;
1806 }
1807
1808
1770 /////////////////////////////////////////////////////////////////////////////// 1809 ///////////////////////////////////////////////////////////////////////////////
1771 1810
1772 bool SkCanvas::isClipEmpty() const { 1811 bool SkCanvas::isClipEmpty() const {
1773 return fMCRec->fRasterClip.isEmpty(); 1812 return fMCRec->fRasterClip.isEmpty();
1774 } 1813 }
1775 1814
1776 bool SkCanvas::isClipRect() const { 1815 bool SkCanvas::isClipRect() const {
1777 return fMCRec->fRasterClip.isRect(); 1816 return fMCRec->fRasterClip.isRect();
1778 } 1817 }
1779 1818
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 3113
3075 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3114 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3076 fCanvas->restoreToCount(fSaveCount); 3115 fCanvas->restoreToCount(fSaveCount);
3077 } 3116 }
3078 3117
3079 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API 3118 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
3080 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 3119 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
3081 return this->makeSurface(info, props).release(); 3120 return this->makeSurface(info, props).release();
3082 } 3121 }
3083 #endif 3122 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698