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

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

Issue 1341043002: impl preroll for all image backends (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/image/SkImage_Base.h ('k') | no next file » | 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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 *minSize = size; 57 *minSize = size;
58 } 58 }
59 return true; 59 return true;
60 } 60 }
61 61
62 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const SkSurfaceProps*); 62 SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*, const SkSurfaceProps*);
63 virtual ~SkImage_Raster(); 63 virtual ~SkImage_Raster();
64 64
65 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove rride; 65 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const ove rride;
66 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st override; 66 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY) con st override;
67 void onPreroll(GrContext*) const override;
68 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; 67 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
69 SkData* onRefEncoded() const override; 68 SkData* onRefEncoded() const override;
70 bool getROPixels(SkBitmap*) const override; 69 bool getROPixels(SkBitmap*) const override;
71 70
72 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 71 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
73 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes, 72 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes,
74 const SkSurfaceProps*); 73 const SkSurfaceProps*);
75 74
76 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
77 76
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const { 156 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const {
158 const SkImageInfo info = fBitmap.info(); 157 const SkImageInfo info = fBitmap.info();
159 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { 158 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) {
160 return nullptr; 159 return nullptr;
161 } 160 }
162 *infoPtr = info; 161 *infoPtr = info;
163 *rowBytesPtr = fBitmap.rowBytes(); 162 *rowBytesPtr = fBitmap.rowBytes();
164 return fBitmap.getPixels(); 163 return fBitmap.getPixels();
165 } 164 }
166 165
167 void SkImage_Raster::onPreroll(GrContext* ctx) const {
168 // SkImage can be called from lots of threads, but our fBitmap is *not* thre ad-safe,
169 // so we have to perform this lock/unlock in a non-racy way... we make a cop y!
170 SkBitmap localShallowCopy(fBitmap);
171 localShallowCopy.lockPixels();
172 localShallowCopy.unlockPixels();
173 }
174
175 SkData* SkImage_Raster::onRefEncoded() const { 166 SkData* SkImage_Raster::onRefEncoded() const {
176 SkPixelRef* pr = fBitmap.pixelRef(); 167 SkPixelRef* pr = fBitmap.pixelRef();
177 const SkImageInfo prInfo = pr->info(); 168 const SkImageInfo prInfo = pr->info();
178 const SkImageInfo bmInfo = fBitmap.info(); 169 const SkImageInfo bmInfo = fBitmap.info();
179 170
180 // we only try if we (the image) cover the entire area of the pixelRef 171 // we only try if we (the image) cover the entire area of the pixelRef
181 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) { 172 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) {
182 return pr->refEncodedData(); 173 return pr->refEncodedData();
183 } 174 }
184 return nullptr; 175 return nullptr;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 SkBitmap bitmap; 286 SkBitmap bitmap;
296 if (!SkInstallDiscardablePixelRef(generator, subset, &bitmap, nullptr)) { 287 if (!SkInstallDiscardablePixelRef(generator, subset, &bitmap, nullptr)) {
297 return nullptr; 288 return nullptr;
298 } 289 }
299 if (0 == bitmap.width() || 0 == bitmap.height()) { 290 if (0 == bitmap.width() || 0 == bitmap.height()) {
300 return nullptr; 291 return nullptr;
301 } 292 }
302 return new SkImage_Raster(bitmap, nullptr); 293 return new SkImage_Raster(bitmap, nullptr);
303 } 294 }
304 #endif 295 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage_Base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698