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