OLD | NEW |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
76 | 76 |
77 SkShader* onNewShader(SkShader::TileMode, | 77 SkShader* onNewShader(SkShader::TileMode, |
78 SkShader::TileMode, | 78 SkShader::TileMode, |
79 const SkMatrix* localMatrix) const override; | 79 const SkMatrix* localMatrix) const override; |
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) | 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) { |
| 88 fBitmap.lockPixels(); |
| 89 } |
| 90 } |
87 | 91 |
88 private: | 92 private: |
89 SkImage_Raster() : INHERITED(0, 0, NULL) {} | 93 SkImage_Raster() : INHERITED(0, 0, NULL) {} |
90 | 94 |
91 SkBitmap fBitmap; | 95 SkBitmap fBitmap; |
92 | 96 |
93 typedef SkImage_Base INHERITED; | 97 typedef SkImage_Base INHERITED; |
94 }; | 98 }; |
95 | 99 |
96 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, | 226 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, |
223 const SkIPoint& pixelRefOrigin, size_t rowBytes, | 227 const SkIPoint& pixelRefOrigin, size_t rowBytes, |
224 const SkSurfaceProps* props) { | 228 const SkSurfaceProps* props) { |
225 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) { | 229 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) { |
226 return NULL; | 230 return NULL; |
227 } | 231 } |
228 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props
)); | 232 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props
)); |
229 } | 233 } |
230 | 234 |
231 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, bool forceSharePixelRef, | 235 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, bool forceSharePixelRef, |
232 const SkSurfaceProps* props) { | 236 const SkSurfaceProps* props, SharedPixelRefM
ode mode) { |
233 SkASSERT(NULL == bm.getTexture()); | 237 SkASSERT(NULL == bm.getTexture()); |
234 | 238 |
235 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) { | 239 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) { |
236 return NULL; | 240 return NULL; |
237 } | 241 } |
238 | 242 |
239 SkImage* image = NULL; | 243 SkImage* image = NULL; |
240 if (forceSharePixelRef || bm.isImmutable()) { | 244 if (forceSharePixelRef || bm.isImmutable()) { |
241 image = SkNEW_ARGS(SkImage_Raster, (bm, props)); | 245 image = SkNEW_ARGS(SkImage_Raster, (bm, props, kLocked_SharedPixelRefMod
e == mode)); |
242 } else { | 246 } else { |
243 SkBitmap tmp(bm); | 247 SkBitmap tmp(bm); |
244 tmp.lockPixels(); | 248 tmp.lockPixels(); |
245 if (tmp.getPixels()) { | 249 if (tmp.getPixels()) { |
246 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB
ytes(), | 250 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB
ytes(), |
247 tmp.getColorTable()); | 251 tmp.getColorTable()); |
248 } | 252 } |
249 | 253 |
250 // we don't expose props to NewRasterCopy (need a private vers) so post-
init it here | 254 // we don't expose props to NewRasterCopy (need a private vers) so post-
init it here |
251 if (image && props) { | 255 if (image && props) { |
(...skipping 18 matching lines...) Expand all Loading... |
270 // pixelref since the caller might call setImmutable() themselves | 274 // pixelref since the caller might call setImmutable() themselves |
271 // (thus changing our state). | 275 // (thus changing our state). |
272 if (fBitmap.isImmutable()) { | 276 if (fBitmap.isImmutable()) { |
273 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 277 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
274 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 278 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
275 return true; | 279 return true; |
276 } | 280 } |
277 } | 281 } |
278 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 282 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
279 } | 283 } |
OLD | NEW |