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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkImageGenerator.h" | 11 #include "SkImageGenerator.h" |
12 #include "SkImagePriv.h" | 12 #include "SkImagePriv.h" |
13 #include "SkImage_Base.h" | 13 #include "SkImage_Base.h" |
| 14 #include "SkImage_Gpu.h" |
| 15 #include "SkPixelRef.h" |
14 #include "SkReadPixelsRec.h" | 16 #include "SkReadPixelsRec.h" |
15 #include "SkString.h" | 17 #include "SkString.h" |
16 #include "SkSurface.h" | 18 #include "SkSurface.h" |
17 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
18 #include "GrTexture.h" | 20 #include "GrTexture.h" |
19 #include "GrContext.h" | 21 #include "GrContext.h" |
20 #endif | 22 #endif |
21 | 23 |
22 uint32_t SkImage::NextUniqueID() { | 24 uint32_t SkImage::NextUniqueID() { |
23 static int32_t gUniqueID; | 25 static int32_t gUniqueID; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 222 } |
221 return false; | 223 return false; |
222 } | 224 } |
223 | 225 |
224 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const { | 226 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const { |
225 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY); | 227 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(),
srcX, srcY); |
226 } | 228 } |
227 | 229 |
228 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 230 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
229 | 231 |
| 232 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { |
| 233 SkPixelRef* pr = bm.pixelRef(); |
| 234 if (NULL == pr) { |
| 235 return NULL; |
| 236 } |
| 237 |
| 238 const bool immutable = bm.isImmutable(); |
| 239 const SkImageInfo info = bm.info(); |
| 240 |
| 241 // GPU version? |
| 242 if (GrTexture* tex = pr->getTexture()) { |
| 243 SkAutoTUnref<GrTexture> unrefCopy; |
| 244 if (!immutable) { |
| 245 const bool notBudgeted = false; |
| 246 tex = GrDeepCopyTexture(tex, notBudgeted); |
| 247 if (NULL == tex) { |
| 248 return NULL; |
| 249 } |
| 250 unrefCopy.reset(tex); |
| 251 } |
| 252 return SkNEW_ARGS(SkImage_Gpu, (info.width(), info.height(), info.alphaT
ype(), |
| 253 tex, 0, SkSurface::kNo_Budgeted)); |
| 254 } |
| 255 |
| 256 // Encoded version? |
| 257 if (SkData* encoded = pr->refEncodedData()) { |
| 258 SkAutoTUnref<SkData> data(encoded); |
| 259 return SkImage::NewFromEncoded(encoded); // todo: add origin/subset/et
c? |
| 260 } |
| 261 |
| 262 // This will check for immutable (share or copy) |
| 263 return SkNewImageFromRasterBitmap(bm, false, NULL); |
| 264 } |
| 265 |
| 266 ////////////////////////////////////////////////////////////////////////////////
////// |
| 267 |
230 #if !SK_SUPPORT_GPU | 268 #if !SK_SUPPORT_GPU |
231 | 269 |
232 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph
aType, | 270 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph
aType, |
233 TextureReleaseProc, ReleaseContext) { | 271 TextureReleaseProc, ReleaseContext) { |
234 return NULL; | 272 return NULL; |
235 } | 273 } |
236 | 274 |
237 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { | 275 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) { |
238 return NULL; | 276 return NULL; |
239 } | 277 } |
240 | 278 |
241 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { | 279 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk
AlphaType) { |
242 return NULL; | 280 return NULL; |
243 } | 281 } |
244 | 282 |
245 #endif | 283 #endif |
OLD | NEW |