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

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

Issue 872543002: Take budgeted param when snapping new image. (Closed) Base URL: https://skia.googlesource.com/skia.git@budgeted
Patch Set: Address comment and rebase Created 5 years, 11 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/image/SkSurface_Gpu.cpp ('k') | tests/DeferredCanvasTest.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 SkImageInfo&, size_t rb = kIgnoreRowBytesValue); 18 static bool Valid(const SkImageInfo&, size_t rb = kIgnoreRowBytesValue);
19 19
20 SkSurface_Raster(const SkImageInfo&, void*, size_t rb, 20 SkSurface_Raster(const SkImageInfo&, void*, size_t rb,
21 void (*releaseProc)(void* pixels, void* context), void* con text, 21 void (*releaseProc)(void* pixels, void* context), void* con text,
22 const SkSurfaceProps*); 22 const SkSurfaceProps*);
23 SkSurface_Raster(SkPixelRef*, const SkSurfaceProps*); 23 SkSurface_Raster(SkPixelRef*, const SkSurfaceProps*);
24 24
25 SkCanvas* onNewCanvas() SK_OVERRIDE; 25 SkCanvas* onNewCanvas() SK_OVERRIDE;
26 SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; 26 SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
27 SkImage* onNewImageSnapshot() SK_OVERRIDE; 27 SkImage* onNewImageSnapshot(Budgeted) SK_OVERRIDE;
28 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 28 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
29 const SkPaint*) SK_OVERRIDE; 29 const SkPaint*) SK_OVERRIDE;
30 void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 30 void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
31 31
32 private: 32 private:
33 SkBitmap fBitmap; 33 SkBitmap fBitmap;
34 bool fWeOwnThePixels; 34 bool fWeOwnThePixels;
35 35
36 typedef SkSurface_Base INHERITED; 36 typedef SkSurface_Base INHERITED;
37 }; 37 };
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { 112 SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) {
113 return SkSurface::NewRaster(info); 113 return SkSurface::NewRaster(info);
114 } 114 }
115 115
116 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 116 void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
117 const SkPaint* paint) { 117 const SkPaint* paint) {
118 canvas->drawBitmap(fBitmap, x, y, paint); 118 canvas->drawBitmap(fBitmap, x, y, paint);
119 } 119 }
120 120
121 SkImage* SkSurface_Raster::onNewImageSnapshot() { 121 SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) {
122 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels, &this->props()); 122 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels, &this->props());
123 } 123 }
124 124
125 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { 125 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
126 // are we sharing pixelrefs with the image? 126 // are we sharing pixelrefs with the image?
127 SkASSERT(this->getCachedImage()); 127 SkASSERT(this->getCachedImage(kNo_Budgeted));
128 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef()) { 128 if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap. pixelRef()) {
129 SkASSERT(fWeOwnThePixels); 129 SkASSERT(fWeOwnThePixels);
130 if (kDiscard_ContentChangeMode == mode) { 130 if (kDiscard_ContentChangeMode == mode) {
131 fBitmap.setPixelRef(NULL); 131 fBitmap.setPixelRef(NULL);
132 fBitmap.allocPixels(); 132 fBitmap.allocPixels();
133 } else { 133 } else {
134 SkBitmap prev(fBitmap); 134 SkBitmap prev(fBitmap);
135 prev.deepCopyTo(&fBitmap); 135 prev.deepCopyTo(&fBitmap);
136 } 136 }
137 // Now fBitmap is a deep copy of itself (and therefore different from 137 // Now fBitmap is a deep copy of itself (and therefore different from
138 // what is being used by the image. Next we update the canvas to use 138 // what is being used by the image. Next we update the canvas to use
(...skipping 30 matching lines...) Expand all
169 if (!SkSurface_Raster::Valid(info)) { 169 if (!SkSurface_Raster::Valid(info)) {
170 return NULL; 170 return NULL;
171 } 171 }
172 172
173 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); 173 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL));
174 if (NULL == pr.get()) { 174 if (NULL == pr.get()) {
175 return NULL; 175 return NULL;
176 } 176 }
177 return SkNEW_ARGS(SkSurface_Raster, (pr, props)); 177 return SkNEW_ARGS(SkSurface_Raster, (pr, props));
178 } 178 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698