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

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

Issue 1254383006: SkImage_Raster's pixels are always immutable. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 bool isOpaque() const override; 81 bool isOpaque() const override;
82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; 82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
83 83
84 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props, bool lockPix els = false) 84 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props, bool lockPix els = false)
85 : INHERITED(bm.width(), bm.height(), props) 85 : INHERITED(bm.width(), bm.height(), props)
86 , fBitmap(bm) { 86 , fBitmap(bm) {
87 if (lockPixels) { 87 if (lockPixels) {
88 fBitmap.lockPixels(); 88 fBitmap.lockPixels();
89 } 89 }
90 SkASSERT(fBitmap.isImmutable());
90 } 91 }
91 92
92 private: 93 private:
93 SkImage_Raster() : INHERITED(0, 0, NULL) {} 94 SkImage_Raster() : INHERITED(0, 0, NULL) {
95 fBitmap.setImmutable();
96 }
94 97
95 SkBitmap fBitmap; 98 SkBitmap fBitmap;
96 99
97 typedef SkImage_Base INHERITED; 100 typedef SkImage_Base INHERITED;
98 }; 101 };
99 102
100 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
101 104
102 static void release_data(void* addr, void* context) { 105 static void release_data(void* addr, void* context) {
103 SkData* data = static_cast<SkData*>(context); 106 SkData* data = static_cast<SkData*>(context);
(...skipping 12 matching lines...) Expand all
116 fBitmap.lockPixels(); 119 fBitmap.lockPixels();
117 } 120 }
118 121
119 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin, 122 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin,
120 size_t rowBytes, const SkSurfaceProps* props) 123 size_t rowBytes, const SkSurfaceProps* props)
121 : INHERITED(info.width(), info.height(), props) 124 : INHERITED(info.width(), info.height(), props)
122 { 125 {
123 fBitmap.setInfo(info, rowBytes); 126 fBitmap.setInfo(info, rowBytes);
124 fBitmap.setPixelRef(pr, pixelRefOrigin); 127 fBitmap.setPixelRef(pr, pixelRefOrigin);
125 fBitmap.lockPixels(); 128 fBitmap.lockPixels();
129 SkASSERT(fBitmap.isImmutable());
126 } 130 }
127 131
128 SkImage_Raster::~SkImage_Raster() {} 132 SkImage_Raster::~SkImage_Raster() {}
129 133
130 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY, 134 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY,
131 const SkMatrix* localMatrix) const { 135 const SkMatrix* localMatrix) const {
132 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); 136 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix);
133 } 137 }
134 138
135 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const { 139 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 229
226 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 230 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
227 const SkIPoint& pixelRefOrigin, size_t rowBytes, 231 const SkIPoint& pixelRefOrigin, size_t rowBytes,
228 const SkSurfaceProps* props) { 232 const SkSurfaceProps* props) {
229 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) { 233 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) {
230 return NULL; 234 return NULL;
231 } 235 }
232 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props )); 236 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props ));
233 } 237 }
234 238
235 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, bool forceSharePixelRef, 239 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr ops,
236 const SkSurfaceProps* props, SharedPixelRefM ode mode) { 240 SharedPixelRefMode mode, ForceCopyMode force Copy) {
237 SkASSERT(NULL == bm.getTexture()); 241 SkASSERT(NULL == bm.getTexture());
238 242
239 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) { 243 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) {
240 return NULL; 244 return NULL;
241 } 245 }
242 246
243 SkImage* image = NULL; 247 SkImage* image = NULL;
244 if (forceSharePixelRef || bm.isImmutable()) { 248 if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
245 image = SkNEW_ARGS(SkImage_Raster, (bm, props, kLocked_SharedPixelRefMod e == mode));
246 } else {
247 SkBitmap tmp(bm); 249 SkBitmap tmp(bm);
248 tmp.lockPixels(); 250 tmp.lockPixels();
249 if (tmp.getPixels()) { 251 if (tmp.getPixels()) {
250 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(), 252 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(),
251 tmp.getColorTable()); 253 tmp.getColorTable());
252 } 254 }
253 255
254 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here 256 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here
255 if (image && props) { 257 if (image && props) {
256 as_IB(image)->initWithProps(*props); 258 as_IB(image)->initWithProps(*props);
257 } 259 }
260 } else {
261 image = SkNEW_ARGS(SkImage_Raster, (bm, props, kLocked_SharedPixelRefMod e == mode));
258 } 262 }
259 return image; 263 return image;
260 } 264 }
261 265
262 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { 266 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
263 return ((const SkImage_Raster*)image)->getPixelRef(); 267 return ((const SkImage_Raster*)image)->getPixelRef();
264 } 268 }
265 269
266 bool SkImage_Raster::isOpaque() const { 270 bool SkImage_Raster::isOpaque() const {
267 return fBitmap.isOpaque(); 271 return fBitmap.isOpaque();
268 } 272 }
269 273
270 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c onst { 274 bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c onst {
271 if (kRO_LegacyBitmapMode == mode) { 275 if (kRO_LegacyBitmapMode == mode) {
272 // When we're a snapshot from a surface, our bitmap may not be marked im mutable 276 // When we're a snapshot from a surface, our bitmap may not be marked im mutable
273 // even though logically always we are, but in that case we can't physic ally share our 277 // even though logically always we are, but in that case we can't physic ally share our
274 // pixelref since the caller might call setImmutable() themselves 278 // pixelref since the caller might call setImmutable() themselves
275 // (thus changing our state). 279 // (thus changing our state).
276 if (fBitmap.isImmutable()) { 280 if (fBitmap.isImmutable()) {
277 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 281 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
278 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 282 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
279 return true; 283 return true;
280 } 284 }
281 } 285 }
282 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 286 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
283 } 287 }
OLDNEW
« src/core/SkPixelRef.cpp ('K') | « src/image/SkImagePriv.h ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698