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

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

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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
« no previous file with comments | « src/core/SkCachedData.cpp ('k') | src/core/SkClipStack.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 bool conservativeRasterClip, bool deviceIsBitmapDevice) 196 bool conservativeRasterClip, bool deviceIsBitmapDevice)
197 : fNext(NULL) 197 : fNext(NULL)
198 , fClip(conservativeRasterClip) 198 , fClip(conservativeRasterClip)
199 , fDeviceIsBitmapDevice(deviceIsBitmapDevice) 199 , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
200 { 200 {
201 if (NULL != device) { 201 if (NULL != device) {
202 device->ref(); 202 device->ref();
203 device->onAttachToCanvas(canvas); 203 device->onAttachToCanvas(canvas);
204 } 204 }
205 fDevice = device; 205 fDevice = device;
206 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; 206 fPaint = paint ? new SkPaint(*paint) : NULL;
207 } 207 }
208 208
209 ~DeviceCM() { 209 ~DeviceCM() {
210 if (fDevice) { 210 if (fDevice) {
211 fDevice->onDetachFromCanvas(); 211 fDevice->onDetachFromCanvas();
212 fDevice->unref(); 212 fDevice->unref();
213 } 213 }
214 SkDELETE(fPaint); 214 delete fPaint;
215 } 215 }
216 216
217 void reset(const SkIRect& bounds) { 217 void reset(const SkIRect& bounds) {
218 SkASSERT(!fPaint); 218 SkASSERT(!fPaint);
219 SkASSERT(!fNext); 219 SkASSERT(!fNext);
220 SkASSERT(fDevice); 220 SkASSERT(fDevice);
221 fClip.setRect(bounds); 221 fClip.setRect(bounds);
222 } 222 }
223 223
224 void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip, 224 void updateMC(const SkMatrix& totalMatrix, const SkRasterClip& totalClip,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 fFilter = SkSafeRef(prev.fFilter); 297 fFilter = SkSafeRef(prev.fFilter);
298 fLayer = NULL; 298 fLayer = NULL;
299 fTopLayer = prev.fTopLayer; 299 fTopLayer = prev.fTopLayer;
300 fDeferredSaveCount = 0; 300 fDeferredSaveCount = 0;
301 301
302 // don't bother initializing fNext 302 // don't bother initializing fNext
303 inc_rec(); 303 inc_rec();
304 } 304 }
305 ~MCRec() { 305 ~MCRec() {
306 SkSafeUnref(fFilter); 306 SkSafeUnref(fFilter);
307 SkDELETE(fLayer); 307 delete fLayer;
308 dec_rec(); 308 dec_rec();
309 } 309 }
310 310
311 void reset(const SkIRect& bounds) { 311 void reset(const SkIRect& bounds) {
312 SkASSERT(fLayer); 312 SkASSERT(fLayer);
313 SkASSERT(fDeferredSaveCount == 0); 313 SkASSERT(fDeferredSaveCount == 0);
314 314
315 fMatrix.reset(); 315 fMatrix.reset();
316 fRasterClip.setRect(bounds); 316 fRasterClip.setRect(bounds);
317 fLayer->reset(bounds); 317 fLayer->reset(bounds);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 597 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
598 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; 598 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ;
599 fCachedLocalClipBounds.setEmpty(); 599 fCachedLocalClipBounds.setEmpty();
600 fCachedLocalClipBoundsDirty = true; 600 fCachedLocalClipBoundsDirty = true;
601 fAllowSoftClip = true; 601 fAllowSoftClip = true;
602 fAllowSimplifyClip = false; 602 fAllowSimplifyClip = false;
603 fDeviceCMDirty = true; 603 fDeviceCMDirty = true;
604 fSaveCount = 1; 604 fSaveCount = 1;
605 fMetaData = NULL; 605 fMetaData = NULL;
606 606
607 fClipStack.reset(SkNEW(SkClipStack)); 607 fClipStack.reset(new SkClipStack);
608 608
609 fMCRec = (MCRec*)fMCStack.push_back(); 609 fMCRec = (MCRec*)fMCStack.push_back();
610 new (fMCRec) MCRec(fConservativeRasterClip); 610 new (fMCRec) MCRec(fConservativeRasterClip);
611 611
612 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 612 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
613 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 613 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
614 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse); 614 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse);
615 615
616 fMCRec->fTopLayer = fMCRec->fLayer; 616 fMCRec->fTopLayer = fMCRec->fLayer;
617 617
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 657
658 typedef SkBitmapDevice INHERITED; 658 typedef SkBitmapDevice INHERITED;
659 }; 659 };
660 660
661 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) 661 SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props)
662 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 662 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
663 , fProps(SkSurfacePropsCopyOrDefault(props)) 663 , fProps(SkSurfacePropsCopyOrDefault(props))
664 { 664 {
665 inc_canvas(); 665 inc_canvas();
666 666
667 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, 667 this->init(new SkNoPixelsBitmapDevice(SkIRect::MakeWH(width, height), fProps ),
668 (SkIRect::MakeWH(width, height), fProps)), kDefault_In itFlags)->unref(); 668 kDefault_InitFlags)->unref();
669 } 669 }
670 670
671 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) 671 SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags)
672 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 672 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
673 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 673 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
674 { 674 {
675 inc_canvas(); 675 inc_canvas();
676 676
677 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (bounds, fProps)), flags)->unr ef(); 677 this->init(new SkNoPixelsBitmapDevice(bounds, fProps), flags)->unref();
678 } 678 }
679 679
680 SkCanvas::SkCanvas(SkBaseDevice* device) 680 SkCanvas::SkCanvas(SkBaseDevice* device)
681 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 681 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
682 , fProps(device->surfaceProps()) 682 , fProps(device->surfaceProps())
683 { 683 {
684 inc_canvas(); 684 inc_canvas();
685 685
686 this->init(device, kDefault_InitFlags); 686 this->init(device, kDefault_InitFlags);
687 } 687 }
688 688
689 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) 689 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags)
690 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 690 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
691 , fProps(device->surfaceProps()) 691 , fProps(device->surfaceProps())
692 { 692 {
693 inc_canvas(); 693 inc_canvas();
694 694
695 this->init(device, flags); 695 this->init(device, flags);
696 } 696 }
697 697
698 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) 698 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
699 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 699 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
700 , fProps(props) 700 , fProps(props)
701 { 701 {
702 inc_canvas(); 702 inc_canvas();
703 703
704 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap, fProps ))); 704 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
705 this->init(device, kDefault_InitFlags); 705 this->init(device, kDefault_InitFlags);
706 } 706 }
707 707
708 SkCanvas::SkCanvas(const SkBitmap& bitmap) 708 SkCanvas::SkCanvas(const SkBitmap& bitmap)
709 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 709 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
710 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 710 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
711 { 711 {
712 inc_canvas(); 712 inc_canvas();
713 713
714 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap, fProps ))); 714 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(bitmap, fProps));
715 this->init(device, kDefault_InitFlags); 715 this->init(device, kDefault_InitFlags);
716 } 716 }
717 717
718 SkCanvas::~SkCanvas() { 718 SkCanvas::~SkCanvas() {
719 // free up the contents of our deque 719 // free up the contents of our deque
720 this->restoreToCount(1); // restore everything but the last 720 this->restoreToCount(1); // restore everything but the last
721 721
722 this->internalRestore(); // restore the last, since we're going away 722 this->internalRestore(); // restore the last, since we're going away
723 723
724 SkDELETE(fMetaData); 724 delete fMetaData;
725 725
726 dec_canvas(); 726 dec_canvas();
727 } 727 }
728 728
729 SkDrawFilter* SkCanvas::getDrawFilter() const { 729 SkDrawFilter* SkCanvas::getDrawFilter() const {
730 return fMCRec->fFilter; 730 return fMCRec->fFilter;
731 } 731 }
732 732
733 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { 733 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) {
734 this->checkForDeferredSave(); 734 this->checkForDeferredSave();
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 SkErrorInternals::SetError(kInternalError_SkError, 1128 SkErrorInternals::SetError(kInternalError_SkError,
1129 "Unable to create device for layer.") ; 1129 "Unable to create device for layer.") ;
1130 return; 1130 return;
1131 } 1131 }
1132 forceSpriteOnRestore = true; 1132 forceSpriteOnRestore = true;
1133 } 1133 }
1134 device = newDev; 1134 device = newDev;
1135 } 1135 }
1136 1136
1137 device->setOrigin(ir.fLeft, ir.fTop); 1137 device->setOrigin(ir.fLeft, ir.fTop);
1138 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip, 1138 DeviceCM* layer =
1139 forceSpriteOnRestore)); 1139 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore);
1140 device->unref(); 1140 device->unref();
1141 1141
1142 layer->fNext = fMCRec->fTopLayer; 1142 layer->fNext = fMCRec->fTopLayer;
1143 fMCRec->fLayer = layer; 1143 fMCRec->fLayer = layer;
1144 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1144 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1145 } 1145 }
1146 1146
1147 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1147 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
1148 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); 1148 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag);
1149 } 1149 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 since if we're being recorded, we don't want to record this (the 1181 since if we're being recorded, we don't want to record this (the
1182 recorder will have already recorded the restore). 1182 recorder will have already recorded the restore).
1183 */ 1183 */
1184 if (layer) { 1184 if (layer) {
1185 if (layer->fNext) { 1185 if (layer->fNext) {
1186 const SkIPoint& origin = layer->fDevice->getOrigin(); 1186 const SkIPoint& origin = layer->fDevice->getOrigin();
1187 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), 1187 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
1188 layer->fPaint, layer->fDeviceIsBitmapDevice ); 1188 layer->fPaint, layer->fDeviceIsBitmapDevice );
1189 // reset this, since internalDrawDevice will have set it to true 1189 // reset this, since internalDrawDevice will have set it to true
1190 fDeviceCMDirty = true; 1190 fDeviceCMDirty = true;
1191 SkDELETE(layer); 1191 delete layer;
1192 } else { 1192 } else {
1193 // we're at the root 1193 // we're at the root
1194 SkASSERT(layer == (void*)fDeviceCMStorage); 1194 SkASSERT(layer == (void*)fDeviceCMStorage);
1195 layer->~DeviceCM(); 1195 layer->~DeviceCM();
1196 } 1196 }
1197 } 1197 }
1198 } 1198 }
1199 1199
1200 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 1200 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
1201 if (NULL == props) { 1201 if (NULL == props) {
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2869 2869
2870 SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_ t rowBytes) { 2870 SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_ t rowBytes) {
2871 if (!supported_for_raster_canvas(info)) { 2871 if (!supported_for_raster_canvas(info)) {
2872 return NULL; 2872 return NULL;
2873 } 2873 }
2874 2874
2875 SkBitmap bitmap; 2875 SkBitmap bitmap;
2876 if (!bitmap.installPixels(info, pixels, rowBytes)) { 2876 if (!bitmap.installPixels(info, pixels, rowBytes)) {
2877 return NULL; 2877 return NULL;
2878 } 2878 }
2879 return SkNEW_ARGS(SkCanvas, (bitmap)); 2879 return new SkCanvas(bitmap);
2880 } 2880 }
2881 2881
2882 /////////////////////////////////////////////////////////////////////////////// 2882 ///////////////////////////////////////////////////////////////////////////////
2883 2883
2884 SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatri x* matrix, 2884 SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatri x* matrix,
2885 const SkPaint* paint, const SkR ect& bounds) 2885 const SkPaint* paint, const SkR ect& bounds)
2886 : fCanvas(canvas) 2886 : fCanvas(canvas)
2887 , fSaveCount(canvas->getSaveCount()) 2887 , fSaveCount(canvas->getSaveCount())
2888 { 2888 {
2889 if (paint) { 2889 if (paint) {
2890 SkRect newBounds = bounds; 2890 SkRect newBounds = bounds;
2891 if (matrix) { 2891 if (matrix) {
2892 matrix->mapRect(&newBounds); 2892 matrix->mapRect(&newBounds);
2893 } 2893 }
2894 canvas->saveLayer(&newBounds, paint); 2894 canvas->saveLayer(&newBounds, paint);
2895 } else if (matrix) { 2895 } else if (matrix) {
2896 canvas->save(); 2896 canvas->save();
2897 } 2897 }
2898 2898
2899 if (matrix) { 2899 if (matrix) {
2900 canvas->concat(*matrix); 2900 canvas->concat(*matrix);
2901 } 2901 }
2902 } 2902 }
2903 2903
2904 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2904 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2905 fCanvas->restoreToCount(fSaveCount); 2905 fCanvas->restoreToCount(fSaveCount);
2906 } 2906 }
OLDNEW
« no previous file with comments | « src/core/SkCachedData.cpp ('k') | src/core/SkClipStack.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698