OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkImageGenerator.h" | |
12 #include "SkMessageBus.h" | 13 #include "SkMessageBus.h" |
13 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
14 #include "GrResourceCache.h" | 15 #include "GrResourceCache.h" |
15 #include "GrGpu.h" | 16 #include "GrGpu.h" |
16 #include "effects/GrDitherEffect.h" | 17 #include "effects/GrDitherEffect.h" |
17 #include "GrDrawTargetCaps.h" | 18 #include "GrDrawTargetCaps.h" |
19 #include "effects/GrYUVtoRGBEffect.h" | |
18 | 20 |
19 #ifndef SK_IGNORE_ETC1_SUPPORT | 21 #ifndef SK_IGNORE_ETC1_SUPPORT |
20 # include "ktx.h" | 22 # include "ktx.h" |
21 # include "etc1.h" | 23 # include "etc1.h" |
22 #endif | 24 #endif |
23 | 25 |
24 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 26 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
25 based bitmap. [palette (colortable) + indices]. | 27 based bitmap. [palette (colortable) + indices]. |
26 | 28 |
27 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 29 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 188 |
187 GrResourceKey key; | 189 GrResourceKey key; |
188 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key ); | 190 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key ); |
189 if (NULL != result) { | 191 if (NULL != result) { |
190 add_genID_listener(key, bm.pixelRef()); | 192 add_genID_listener(key, bm.pixelRef()); |
191 } | 193 } |
192 return result; | 194 return result; |
193 } | 195 } |
194 #endif // SK_IGNORE_ETC1_SUPPORT | 196 #endif // SK_IGNORE_ETC1_SUPPORT |
195 | 197 |
198 static GrTexture *load_yuv_texture(GrContext* ctx, | |
199 const GrTextureParams* params, | |
200 const SkBitmap &bm, GrTextureDesc desc) { | |
201 GrTexture* result = NULL; | |
202 | |
203 SkPixelRef* pixelRef = bm.pixelRef(); | |
204 SkImageGenerator* imageGenerator = pixelRef ? pixelRef->getImageGenerator() : NULL; | |
205 if (imageGenerator) { | |
206 SkISize yuvSizes[3]; | |
207 if (imageGenerator->getYUV8Planes(yuvSizes)) { | |
208 SkImageGenerator::YUV8Planes planes; | |
209 // Set the info based on the Y channel's size | |
210 planes.fInfo = SkImageInfo::MakeN32Premul(yuvSizes[0].fWidth, yuvSiz es[0].fHeight); | |
211 // Allcate the memory for YUV | |
212 size_t ySize = yuvSizes[0].fWidth * yuvSizes[0].fHeight; | |
213 size_t uSize = yuvSizes[1].fWidth * yuvSizes[1].fHeight; | |
214 // size_t vSize = yuvSizes[2].fWidth * yuvSizes[2].fHeight; | |
215 size_t yuvSize = 4 * ySize; // FIXME: ySize + uSize + vSize; | |
sugoi1
2014/07/08 14:42:02
There's still a FIXME here. This allocated memory
| |
216 planes.fPixels = (uint8_t*)sk_malloc_flags(yuvSize, 0); | |
217 // Get the YUV planes | |
218 if ((NULL != planes.fPixels) && | |
219 imageGenerator->getYUV8Planes(yuvSizes, &planes)) { | |
220 // Put the planes into SkBitmap objects | |
221 SkBitmap yBitmap, uBitmap, vBitmap; | |
222 SkImageInfo yInfo = SkImageInfo::MakeA8(yuvSizes[0].fWidth, yuvS izes[0].fHeight); | |
223 SkImageInfo uInfo = SkImageInfo::MakeA8(yuvSizes[1].fWidth, yuvS izes[1].fHeight); | |
224 SkImageInfo vInfo = SkImageInfo::MakeA8(yuvSizes[2].fWidth, yuvS izes[2].fHeight); | |
225 if (yBitmap.installPixels(yInfo, planes.fPixels, yInfo.minRowByt es()) && | |
226 uBitmap.installPixels(uInfo, planes.fPixels + ySize, uInfo.m inRowBytes()) && | |
227 vBitmap.installPixels(vInfo, planes.fPixels + ySize + uSize, vInfo.minRowBytes())) { | |
228 // Upload bitmaps as textures (don't cache these) | |
229 yBitmap.setIsVolatile(true); | |
230 uBitmap.setIsVolatile(true); | |
231 vBitmap.setIsVolatile(true); | |
232 GrTexture* yTexture = GrLockAndRefCachedBitmapTexture(ctx, y Bitmap, params); | |
233 GrTexture* uTexture = GrLockAndRefCachedBitmapTexture(ctx, u Bitmap, params); | |
234 GrTexture* vTexture = GrLockAndRefCachedBitmapTexture(ctx, v Bitmap, params); | |
235 if (yTexture && uTexture && vTexture) { | |
236 GrTextureDesc rtDesc = desc; | |
237 rtDesc.fFlags = rtDesc.fFlags | | |
238 kRenderTarget_GrTextureFlagBit | | |
239 kNoStencil_GrTextureFlagBit; | |
240 | |
241 // This texture is likely to be used again so leave it i n the cache | |
242 GrCacheID cacheID; | |
243 generate_bitmap_cache_id(bm, &cacheID); | |
244 | |
245 GrResourceKey key; | |
246 result = ctx->createTexture(params, rtDesc, cacheID, NUL L, 0, &key); | |
247 GrRenderTarget* renderTarget = result ? result->asRender Target() : NULL; | |
248 if (NULL != renderTarget) { | |
249 add_genID_listener(key, bm.pixelRef()); | |
250 GrEffectRef* yuvToRgbEffect = GrYUVtoRGBEffect::Crea te(yTexture, uTexture, vTexture); | |
251 SkAutoUnref effectRef(yuvToRgbEffect); | |
252 GrPaint paint; | |
253 paint.addColorEffect(yuvToRgbEffect); | |
254 SkRect r = SkRect::MakeWH(yuvSizes[0].fWidth, yuvSiz es[0].fHeight); | |
255 GrContext::AutoRenderTarget autoRT(ctx, renderTarget ); | |
256 GrContext::AutoMatrix am; | |
257 am.setIdentity(ctx); | |
258 GrContext::AutoClip ac(ctx, r); | |
259 ctx->drawRect(paint, r); | |
260 } else { | |
261 SkSafeSetNull(result); | |
262 } | |
263 } | |
264 if (NULL != yTexture) { | |
265 GrUnlockAndUnrefCachedBitmapTexture(yTexture); | |
266 } | |
267 if (NULL != uTexture) { | |
268 GrUnlockAndUnrefCachedBitmapTexture(uTexture); | |
269 } | |
270 if (NULL != vTexture) { | |
271 GrUnlockAndUnrefCachedBitmapTexture(vTexture); | |
272 } | |
273 } | |
274 } | |
275 sk_free(planes.fPixels); | |
276 } | |
277 } | |
278 | |
279 return result; | |
280 } | |
281 | |
196 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 282 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
197 bool cache, | 283 bool cache, |
198 const GrTextureParams* params, | 284 const GrTextureParams* params, |
199 const SkBitmap& origBitmap) { | 285 const SkBitmap& origBitmap) { |
200 SkBitmap tmpBitmap; | 286 SkBitmap tmpBitmap; |
201 | 287 |
202 const SkBitmap* bitmap = &origBitmap; | 288 const SkBitmap* bitmap = &origBitmap; |
203 | 289 |
204 GrTextureDesc desc; | 290 GrTextureDesc desc; |
205 generate_bitmap_texture_desc(*bitmap, &desc); | 291 generate_bitmap_texture_desc(*bitmap, &desc); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // the bitmap has available pixels, then they might not be what the deco mpressed | 343 // the bitmap has available pixels, then they might not be what the deco mpressed |
258 // data is. | 344 // data is. |
259 && !(bitmap->readyToDraw())) { | 345 && !(bitmap->readyToDraw())) { |
260 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); | 346 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); |
261 if (NULL != texture) { | 347 if (NULL != texture) { |
262 return texture; | 348 return texture; |
263 } | 349 } |
264 } | 350 } |
265 #endif // SK_IGNORE_ETC1_SUPPORT | 351 #endif // SK_IGNORE_ETC1_SUPPORT |
266 | 352 |
353 else { | |
354 GrTexture *texture = load_yuv_texture(ctx, params, *bitmap, desc); | |
sugoi1
2014/07/08 14:42:03
The "cache" boolean should probably be used here,
| |
355 if (NULL != texture) { | |
356 return texture; | |
357 } | |
358 } | |
267 SkAutoLockPixels alp(*bitmap); | 359 SkAutoLockPixels alp(*bitmap); |
268 if (!bitmap->readyToDraw()) { | 360 if (!bitmap->readyToDraw()) { |
269 return NULL; | 361 return NULL; |
270 } | 362 } |
271 if (cache) { | 363 if (cache) { |
272 // This texture is likely to be used again so leave it in the cache | 364 // This texture is likely to be used again so leave it in the cache |
273 GrCacheID cacheID; | 365 GrCacheID cacheID; |
274 generate_bitmap_cache_id(origBitmap, &cacheID); | 366 generate_bitmap_cache_id(origBitmap, &cacheID); |
275 | 367 |
276 GrResourceKey key; | 368 GrResourceKey key; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 SkAutoTUnref<GrEffectRef> effect(grEffect); | 627 SkAutoTUnref<GrEffectRef> effect(grEffect); |
536 grPaint->addColorEffect(effect); | 628 grPaint->addColorEffect(effect); |
537 constantColor = false; | 629 constantColor = false; |
538 } | 630 } |
539 } | 631 } |
540 | 632 |
541 // The grcolor is automatically set when calling asneweffect. | 633 // The grcolor is automatically set when calling asneweffect. |
542 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. | 634 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. |
543 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); | 635 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); |
544 } | 636 } |
OLD | NEW |