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

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

Issue 1728093005: Move Budgeted enum out of SkSurface, use in GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add aliases for Chrome Created 4 years, 10 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') | src/utils/SkImageGeneratorUtils.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() override; 25 SkCanvas* onNewCanvas() override;
26 SkSurface* onNewSurface(const SkImageInfo&) override; 26 SkSurface* onNewSurface(const SkImageInfo&) override;
27 SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) override; 27 SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) override;
28 void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override; 28 void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override;
29 void onCopyOnWrite(ContentChangeMode) override; 29 void onCopyOnWrite(ContentChangeMode) override;
30 void onRestoreBackingMutability() override; 30 void onRestoreBackingMutability() override;
31 31
32 private: 32 private:
33 SkBitmap fBitmap; 33 SkBitmap fBitmap;
34 size_t fRowBytes; 34 size_t fRowBytes;
35 bool fWeOwnThePixels; 35 bool fWeOwnThePixels;
36 36
37 typedef SkSurface_Base INHERITED; 37 typedef SkSurface_Base INHERITED;
(...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, &this->props()); 113 return SkSurface::NewRaster(info, &this->props());
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(Budgeted, ForceCopyMode forceCopyM ode) { 121 SkImage* SkSurface_Raster::onNewImageSnapshot(SkBudgeted, ForceCopyMode forceCop yMode) {
122 if (fWeOwnThePixels) { 122 if (fWeOwnThePixels) {
123 // SkImage_raster requires these pixels are immutable for its full lifet ime. 123 // SkImage_raster requires these pixels are immutable for its full lifet ime.
124 // We'll undo this via onRestoreBackingMutability() if we can avoid the COW. 124 // We'll undo this via onRestoreBackingMutability() if we can avoid the COW.
125 if (SkPixelRef* pr = fBitmap.pixelRef()) { 125 if (SkPixelRef* pr = fBitmap.pixelRef()) {
126 pr->setTemporarilyImmutable(); 126 pr->setTemporarilyImmutable();
127 } 127 }
128 } else { 128 } else {
129 forceCopyMode = kYes_ForceCopyMode; 129 forceCopyMode = kYes_ForceCopyMode;
130 } 130 }
131 131
132 // Our pixels are in memory, so read access on the snapshot SkImage could be cheap. 132 // Our pixels are in memory, so read access on the snapshot SkImage could be cheap.
133 // Lock the shared pixel ref to ensure peekPixels() is usable. 133 // Lock the shared pixel ref to ensure peekPixels() is usable.
134 return SkNewImageFromRasterBitmap(fBitmap, forceCopyMode); 134 return SkNewImageFromRasterBitmap(fBitmap, forceCopyMode);
135 } 135 }
136 136
137 void SkSurface_Raster::onRestoreBackingMutability() { 137 void SkSurface_Raster::onRestoreBackingMutability() {
138 SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there. 138 SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there.
139 if (SkPixelRef* pr = fBitmap.pixelRef()) { 139 if (SkPixelRef* pr = fBitmap.pixelRef()) {
140 pr->restoreMutability(); 140 pr->restoreMutability();
141 } 141 }
142 } 142 }
143 143
144 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { 144 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
145 // are we sharing pixelrefs with the image? 145 // are we sharing pixelrefs with the image?
146 SkAutoTUnref<SkImage> cached(this->refCachedImage(kNo_Budgeted, kNo_ForceUni que)); 146 SkAutoTUnref<SkImage> cached(this->refCachedImage(SkBudgeted::kNo, kNo_Force Unique));
147 SkASSERT(cached); 147 SkASSERT(cached);
148 if (SkBitmapImageGetPixelRef(cached) == fBitmap.pixelRef()) { 148 if (SkBitmapImageGetPixelRef(cached) == fBitmap.pixelRef()) {
149 SkASSERT(fWeOwnThePixels); 149 SkASSERT(fWeOwnThePixels);
150 if (kDiscard_ContentChangeMode == mode) { 150 if (kDiscard_ContentChangeMode == mode) {
151 fBitmap.allocPixels(); 151 fBitmap.allocPixels();
152 } else { 152 } else {
153 SkBitmap prev(fBitmap); 153 SkBitmap prev(fBitmap);
154 fBitmap.allocPixels(); 154 fBitmap.allocPixels();
155 prev.lockPixels(); 155 prev.lockPixels();
156 SkASSERT(prev.info() == fBitmap.info()); 156 SkASSERT(prev.info() == fBitmap.info());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 if (rowBytes) { 203 if (rowBytes) {
204 SkASSERT(pr->rowBytes() == rowBytes); 204 SkASSERT(pr->rowBytes() == rowBytes);
205 } 205 }
206 return new SkSurface_Raster(pr, props); 206 return new SkSurface_Raster(pr, props);
207 } 207 }
208 208
209 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p rops) { 209 SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* p rops) {
210 return NewRaster(info, 0, props); 210 return NewRaster(info, 0, props);
211 } 211 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | src/utils/SkImageGeneratorUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698