Chromium Code Reviews| 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 "SkMessageBus.h" | 12 #include "SkMessageBus.h" |
| 13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
| 14 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
| 15 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 16 #include "effects/GrDitherEffect.h" | 16 #include "effects/GrDitherEffect.h" |
| 17 #include "GrDrawTargetCaps.h" | 17 #include "GrDrawTargetCaps.h" |
| 18 #include "effects/GrYUVtoRGBEffect.h" | |
| 18 | 19 |
| 19 #ifndef SK_IGNORE_ETC1_SUPPORT | 20 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 20 # include "ktx.h" | 21 # include "ktx.h" |
| 21 # include "etc1.h" | 22 # include "etc1.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 25 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
| 25 based bitmap. [palette (colortable) + indices]. | 26 based bitmap. [palette (colortable) + indices]. |
| 26 | 27 |
| 27 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 28 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 generate_bitmap_cache_id(bm, &cacheID); | 186 generate_bitmap_cache_id(bm, &cacheID); |
| 186 | 187 |
| 187 GrResourceKey key; | 188 GrResourceKey key; |
| 188 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key ); | 189 GrTexture* result = ctx->createTexture(params, desc, cacheID, bytes, 0, &key ); |
| 189 if (NULL != result) { | 190 if (NULL != result) { |
| 190 add_genID_listener(key, bm.pixelRef()); | 191 add_genID_listener(key, bm.pixelRef()); |
| 191 } | 192 } |
| 192 return result; | 193 return result; |
| 193 } | 194 } |
| 194 #endif // SK_IGNORE_ETC1_SUPPORT | 195 #endif // SK_IGNORE_ETC1_SUPPORT |
| 195 | 196 |
|
robertphillips
2014/07/10 12:47:20
You could reduce the indent level of this by rever
sugoi1
2014/07/10 16:10:53
Done.
| |
| 197 static GrTexture *load_yuv_texture(GrContext* ctx, | |
| 198 const GrTextureParams* params, | |
|
robertphillips
2014/07/10 12:47:20
const GrTextureDesc& desc ?
sugoi1
2014/07/10 16:10:53
Done.
| |
| 199 const SkBitmap &bm, GrTextureDesc desc) { | |
|
bsalomon
2014/07/09 20:19:18
style nit: Can you move the & to the left of the s
sugoi1
2014/07/10 16:10:53
Done.
| |
| 200 GrTexture* result = NULL; | |
| 201 | |
| 202 SkPixelRef* pixelRef = bm.pixelRef(); | |
| 203 SkISize yuvSizes[3]; | |
|
robertphillips
2014/07/10 12:47:20
NULL != pixelRef ?
sugoi1
2014/07/10 16:10:53
Done.
| |
| 204 if (pixelRef && pixelRef->getYUV8Planes(yuvSizes, NULL)) { | |
|
robertphillips
2014/07/10 12:47:20
Allcate -> Allocate ?
sugoi1
2014/07/10 16:10:53
Done.
| |
| 205 // Allcate the memory for YUV | |
| 206 size_t ySize = yuvSizes[0].fWidth * yuvSizes[0].fHeight; | |
| 207 size_t uSize = yuvSizes[1].fWidth * yuvSizes[1].fHeight; | |
| 208 // size_t vSize = yuvSizes[2].fWidth * yuvSizes[2].fHeight; | |
| 209 size_t yuvSize = 4 * ySize; // FIXME: ySize + uSize + vSize; | |
| 210 SkAutoMalloc storage(yuvSize); | |
| 211 uint8_t* planes = (uint8_t*)storage.get(); | |
| 212 // Get the YUV planes | |
| 213 if ((NULL != planes) && pixelRef->getYUV8Planes(yuvSizes, planes)) { | |
| 214 // Put the planes into SkBitmap objects | |
|
bsalomon
2014/07/09 20:19:18
Do we really need the intermediate step of going i
sugoi1
2014/07/10 16:10:52
Done.
| |
| 215 SkBitmap yBitmap, uBitmap, vBitmap; | |
| 216 SkImageInfo yInfo = SkImageInfo::MakeA8(yuvSizes[0].fWidth, yuvSizes [0].fHeight); | |
| 217 SkImageInfo uInfo = SkImageInfo::MakeA8(yuvSizes[1].fWidth, yuvSizes [1].fHeight); | |
| 218 SkImageInfo vInfo = SkImageInfo::MakeA8(yuvSizes[2].fWidth, yuvSizes [2].fHeight); | |
| 219 if (yBitmap.installPixels(yInfo, planes, yInfo.minRowBytes()) && | |
| 220 uBitmap.installPixels(uInfo, planes + ySize, uInfo.minRowBytes() ) && | |
| 221 vBitmap.installPixels(vInfo, planes + ySize + uSize, vInfo.minRo wBytes())) { | |
| 222 // Upload bitmaps as textures (don't cache these) | |
| 223 yBitmap.setIsVolatile(true); | |
| 224 uBitmap.setIsVolatile(true); | |
| 225 vBitmap.setIsVolatile(true); | |
| 226 GrTexture* yTexture = GrLockAndRefCachedBitmapTexture(ctx, yBitm ap, params); | |
| 227 GrTexture* uTexture = GrLockAndRefCachedBitmapTexture(ctx, uBitm ap, params); | |
| 228 GrTexture* vTexture = GrLockAndRefCachedBitmapTexture(ctx, vBitm ap, params); | |
| 229 if (yTexture && uTexture && vTexture) { | |
| 230 GrTextureDesc rtDesc = desc; | |
| 231 rtDesc.fFlags = rtDesc.fFlags | | |
| 232 kRenderTarget_GrTextureFlagBit | | |
| 233 kNoStencil_GrTextureFlagBit; | |
| 234 | |
| 235 // This texture is likely to be used again so leave it in th e cache | |
| 236 GrCacheID cacheID; | |
| 237 generate_bitmap_cache_id(bm, &cacheID); | |
| 238 | |
| 239 GrResourceKey key; | |
| 240 result = ctx->createTexture(params, rtDesc, cacheID, NULL, 0 , &key); | |
| 241 GrRenderTarget* renderTarget = result ? result->asRenderTarg et() : NULL; | |
| 242 if (NULL != renderTarget) { | |
| 243 add_genID_listener(key, bm.pixelRef()); | |
| 244 SkAutoTUnref<GrEffect> yuvToRgbEffect( | |
| 245 GrYUVtoRGBEffect::Create(yTexture, uTexture, vTextur e)); | |
| 246 GrPaint paint; | |
| 247 paint.addColorEffect(yuvToRgbEffect); | |
| 248 SkRect r = SkRect::MakeWH(yuvSizes[0].fWidth, yuvSizes[0 ].fHeight); | |
| 249 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | |
| 250 GrContext::AutoMatrix am; | |
| 251 am.setIdentity(ctx); | |
| 252 GrContext::AutoClip ac(ctx, r); | |
| 253 ctx->drawRect(paint, r); | |
| 254 } else { | |
| 255 SkSafeSetNull(result); | |
| 256 } | |
| 257 } | |
| 258 if (NULL != yTexture) { | |
| 259 GrUnlockAndUnrefCachedBitmapTexture(yTexture); | |
| 260 } | |
| 261 if (NULL != uTexture) { | |
| 262 GrUnlockAndUnrefCachedBitmapTexture(uTexture); | |
| 263 } | |
| 264 if (NULL != vTexture) { | |
| 265 GrUnlockAndUnrefCachedBitmapTexture(vTexture); | |
| 266 } | |
| 267 } | |
| 268 } | |
| 269 } | |
| 270 | |
| 271 return result; | |
| 272 } | |
| 273 | |
| 196 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 274 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
| 197 bool cache, | 275 bool cache, |
| 198 const GrTextureParams* params, | 276 const GrTextureParams* params, |
| 199 const SkBitmap& origBitmap) { | 277 const SkBitmap& origBitmap) { |
| 200 SkBitmap tmpBitmap; | 278 SkBitmap tmpBitmap; |
| 201 | 279 |
| 202 const SkBitmap* bitmap = &origBitmap; | 280 const SkBitmap* bitmap = &origBitmap; |
| 203 | 281 |
| 204 GrTextureDesc desc; | 282 GrTextureDesc desc; |
| 205 generate_bitmap_texture_desc(*bitmap, &desc); | 283 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 | 335 // the bitmap has available pixels, then they might not be what the deco mpressed |
| 258 // data is. | 336 // data is. |
| 259 && !(bitmap->readyToDraw())) { | 337 && !(bitmap->readyToDraw())) { |
| 260 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); | 338 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); |
| 261 if (NULL != texture) { | 339 if (NULL != texture) { |
| 262 return texture; | 340 return texture; |
| 263 } | 341 } |
| 264 } | 342 } |
| 265 #endif // SK_IGNORE_ETC1_SUPPORT | 343 #endif // SK_IGNORE_ETC1_SUPPORT |
| 266 | 344 |
| 345 else { | |
| 346 GrTexture *texture = load_yuv_texture(ctx, params, *bitmap, desc); | |
| 347 if (NULL != texture) { | |
| 348 return texture; | |
| 349 } | |
| 350 } | |
| 267 SkAutoLockPixels alp(*bitmap); | 351 SkAutoLockPixels alp(*bitmap); |
| 268 if (!bitmap->readyToDraw()) { | 352 if (!bitmap->readyToDraw()) { |
| 269 return NULL; | 353 return NULL; |
| 270 } | 354 } |
| 271 if (cache) { | 355 if (cache) { |
| 272 // This texture is likely to be used again so leave it in the cache | 356 // This texture is likely to be used again so leave it in the cache |
| 273 GrCacheID cacheID; | 357 GrCacheID cacheID; |
| 274 generate_bitmap_cache_id(origBitmap, &cacheID); | 358 generate_bitmap_cache_id(origBitmap, &cacheID); |
| 275 | 359 |
| 276 GrResourceKey key; | 360 GrResourceKey key; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) && NULL != effect) { | 618 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) && NULL != effect) { |
| 535 grPaint->addColorEffect(effect)->unref(); | 619 grPaint->addColorEffect(effect)->unref(); |
| 536 constantColor = false; | 620 constantColor = false; |
| 537 } | 621 } |
| 538 } | 622 } |
| 539 | 623 |
| 540 // The grcolor is automatically set when calling asneweffect. | 624 // The grcolor is automatically set when calling asneweffect. |
| 541 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. | 625 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. |
| 542 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); | 626 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); |
| 543 } | 627 } |
| OLD | NEW |