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

Side by Side Diff: src/image/SkSurface_Raster.cpp

Issue 14263017: Cleanup: Removing unnecessary args/complexity in SkSurface_Base and friends (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/image/SkSurface_Picture.cpp ('k') | tests/SurfaceTest.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 2012 Google Inc. 2 * Copyright 2012 Google Inc.
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 "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkMallocPixelRef.h" 12 #include "SkMallocPixelRef.h"
13 13
14 static const size_t kIgnoreRowBytesValue = (size_t)~0; 14 static const size_t kIgnoreRowBytesValue = (size_t)~0;
15 15
16 class SkSurface_Raster : public SkSurface_Base { 16 class SkSurface_Raster : public SkSurface_Base {
17 public: 17 public:
18 static bool Valid(const SkImage::Info&, size_t rb = kIgnoreRowBytesValue); 18 static bool Valid(const SkImage::Info&, size_t rb = kIgnoreRowBytesValue);
19 19
20 SkSurface_Raster(const SkImage::Info&, void*, size_t rb); 20 SkSurface_Raster(const SkImage::Info&, void*, size_t rb);
21 SkSurface_Raster(const SkImage::Info&, SkPixelRef*, size_t rb); 21 SkSurface_Raster(const SkImage::Info&, SkPixelRef*, size_t rb);
22 22
23 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 23 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
24 virtual SkSurface* onNewSurface(const SkImage::Info&) SK_OVERRIDE; 24 virtual SkSurface* onNewSurface(const SkImage::Info&) SK_OVERRIDE;
25 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 25 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
26 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 26 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
27 const SkPaint*) SK_OVERRIDE; 27 const SkPaint*) SK_OVERRIDE;
28 virtual void onCopyOnWrite(SkImage*, SkCanvas*) SK_OVERRIDE; 28 virtual void onCopyOnWrite() SK_OVERRIDE;
29 29
30 private: 30 private:
31 SkBitmap fBitmap; 31 SkBitmap fBitmap;
32 bool fWeOwnThePixels; 32 bool fWeOwnThePixels;
33 33
34 typedef SkSurface_Base INHERITED; 34 typedef SkSurface_Base INHERITED;
35 }; 35 };
36 36
37 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
38 38
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 118 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
119 const SkPaint* paint) { 119 const SkPaint* paint) {
120 canvas->drawBitmap(fBitmap, x, y, paint); 120 canvas->drawBitmap(fBitmap, x, y, paint);
121 } 121 }
122 122
123 SkImage* SkSurface_Raster::onNewImageSnapshot() { 123 SkImage* SkSurface_Raster::onNewImageSnapshot() {
124 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); 124 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels);
125 } 125 }
126 126
127 void SkSurface_Raster::onCopyOnWrite(SkImage* image, SkCanvas* canvas) { 127 void SkSurface_Raster::onCopyOnWrite() {
128 // are we sharing pixelrefs with the image? 128 // are we sharing pixelrefs with the image?
129 if (SkBitmapImageGetPixelRef(image) == fBitmap.pixelRef()) { 129 SkASSERT(NULL !=this->getCachedImage());
130 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef()) {
130 SkASSERT(fWeOwnThePixels); 131 SkASSERT(fWeOwnThePixels);
131 SkBitmap prev(fBitmap); 132 SkBitmap prev(fBitmap);
132 prev.deepCopyTo(&fBitmap, prev.config()); 133 prev.deepCopyTo(&fBitmap, prev.config());
133 // Now fBitmap is a deep copy of itself (and therefore different from 134 // Now fBitmap is a deep copy of itself (and therefore different from
134 // what is being used by the image. Next we update the canvas to use 135 // what is being used by the image. Next we update the canvas to use
135 // this as its backend, so we can't modify the image's pixels anymore. 136 // this as its backend, so we can't modify the image's pixels anymore.
136 canvas->getDevice()->replaceBitmapBackendForRasterSurface(fBitmap); 137 SkASSERT(NULL != this->getCachedCanvas());
138 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa ce(fBitmap);
137 } 139 }
138 } 140 }
139 141
140 /////////////////////////////////////////////////////////////////////////////// 142 ///////////////////////////////////////////////////////////////////////////////
141 143
142 SkSurface* SkSurface::NewRasterDirect(const SkImage::Info& info, void* pixels, s ize_t rowBytes) { 144 SkSurface* SkSurface::NewRasterDirect(const SkImage::Info& info, void* pixels, s ize_t rowBytes) {
143 if (!SkSurface_Raster::Valid(info, rowBytes)) { 145 if (!SkSurface_Raster::Valid(info, rowBytes)) {
144 return NULL; 146 return NULL;
145 } 147 }
146 if (NULL == pixels) { 148 if (NULL == pixels) {
(...skipping 17 matching lines...) Expand all
164 166
165 size_t size = (size_t)size64; 167 size_t size = (size_t)size64;
166 void* pixels = sk_malloc_throw(size); 168 void* pixels = sk_malloc_throw(size);
167 if (NULL == pixels) { 169 if (NULL == pixels) {
168 return NULL; 170 return NULL;
169 } 171 }
170 172
171 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL , true))); 173 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL , true)));
172 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes)); 174 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes));
173 } 175 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Picture.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698