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

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

Issue 1217053003: add SkImage::NewFromBitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 221 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
222 const SkIPoint& pixelRefOrigin, size_t rowBytes, 222 const SkIPoint& pixelRefOrigin, size_t rowBytes,
223 const SkSurfaceProps* props) { 223 const SkSurfaceProps* props) {
224 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) { 224 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) {
225 return NULL; 225 return NULL;
226 } 226 }
227 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props )); 227 return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props ));
228 } 228 }
229 229
230 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef, 230 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, bool forceSharePixelRef,
231 const SkSurfaceProps* props) { 231 const SkSurfaceProps* props) {
232 SkASSERT(NULL == bm.getTexture());
233
232 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) { 234 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) {
233 return NULL; 235 return NULL;
234 } 236 }
235 237
236 SkImage* image = NULL; 238 SkImage* image = NULL;
237 if (canSharePixelRef || bm.isImmutable()) { 239 if (forceSharePixelRef || bm.isImmutable()) {
238 image = SkNEW_ARGS(SkImage_Raster, (bm, props)); 240 image = SkNEW_ARGS(SkImage_Raster, (bm, props));
239 } else { 241 } else {
240 bm.lockPixels(); 242 SkBitmap tmp(bm);
241 if (bm.getPixels()) { 243 tmp.lockPixels();
242 image = SkImage::NewRasterCopy(bm.info(), bm.getPixels(), bm.rowByte s()); 244 if (tmp.getPixels()) {
245 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(),
246 tmp.getColorTable());
243 } 247 }
244 bm.unlockPixels();
245 248
246 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here 249 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here
247 if (image && props) { 250 if (image && props) {
248 as_IB(image)->initWithProps(*props); 251 as_IB(image)->initWithProps(*props);
249 } 252 }
250 } 253 }
251 return image; 254 return image;
252 } 255 }
253 256
254 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) { 257 const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
255 return ((const SkImage_Raster*)image)->getPixelRef(); 258 return ((const SkImage_Raster*)image)->getPixelRef();
256 } 259 }
257 260
258 bool SkImage_Raster::isOpaque() const { 261 bool SkImage_Raster::isOpaque() const {
259 return fBitmap.isOpaque(); 262 return fBitmap.isOpaque();
260 } 263 }
261 264
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698