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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 197 static GrTexture *load_yuv_texture(GrContext* ctx, const GrTextureParams* params , | |
| 198 const SkBitmap& bm, const GrTextureDesc& desc ) { | |
| 199 GrTexture* result = NULL; | |
| 200 | |
| 201 SkPixelRef* pixelRef = bm.pixelRef(); | |
| 202 SkISize yuvSizes[3]; | |
| 203 void* planes[3] = { NULL, NULL, NULL }; | |
| 204 int rowBytes[3] = { 0, 0, 0 }; | |
| 205 if ((NULL == pixelRef) || !pixelRef->getYUV8Planes(yuvSizes, planes, rowByte s)) { | |
| 206 return NULL; | |
| 207 } | |
| 208 | |
| 209 // Allocate the memory for YUV | |
| 210 size_t totalSize = 0; | |
| 211 size_t sizes[3]; | |
| 212 for (int i = 0; i < 3; ++i) { | |
| 213 rowBytes[i] = yuvSizes[i].fWidth; | |
| 214 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; | |
| 215 } | |
| 216 SkAutoMalloc storage(totalSize); | |
| 217 planes[0] = storage.get(); | |
| 218 planes[1] = (uint8_t*)planes[0] + sizes[0]; | |
| 219 planes[2] = (uint8_t*)planes[1] + sizes[1]; | |
| 220 | |
| 221 // Get the YUV planes | |
| 222 if ((NULL == planes[0]) || !pixelRef->getYUV8Planes(yuvSizes, planes, rowByt es)) { | |
|
reed1
2014/07/10 17:15:15
I don't think SkAutoMalloc can ever fail, can it?
sugoi1
2014/07/10 17:54:24
I don't know. What happens if we're out of memory?
| |
| 223 return NULL; | |
| 224 } | |
| 225 | |
| 226 GrTextureDesc yuvDesc; | |
| 227 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | |
| 228 SkAutoTUnref<GrTexture> yuvTextures[3]; | |
| 229 for (int i = 0; i < 3; ++i) { | |
| 230 yuvDesc.fWidth = yuvSizes[i].fWidth; | |
| 231 yuvDesc.fHeight = yuvSizes[i].fHeight; | |
| 232 GrTexture* tex = ctx->createUncachedTexture(yuvDesc, planes[i], rowBytes [i]); | |
|
bsalomon
2014/07/10 18:29:39
We should probably use scratch textures here. We'd
sugoi1
2014/07/10 19:59:06
Done.
| |
| 233 if (NULL == tex) { | |
| 234 return NULL; | |
| 235 } | |
| 236 yuvTextures[i].reset(tex); | |
| 237 } | |
| 238 | |
| 239 GrTextureDesc rtDesc = desc; | |
| 240 rtDesc.fFlags = rtDesc.fFlags | | |
| 241 kRenderTarget_GrTextureFlagBit | | |
| 242 kNoStencil_GrTextureFlagBit; | |
| 243 | |
| 244 // This texture is likely to be used again so leave it in the cache | |
| 245 GrCacheID cacheID; | |
| 246 generate_bitmap_cache_id(bm, &cacheID); | |
| 247 | |
| 248 GrResourceKey key; | |
| 249 result = ctx->createTexture(params, rtDesc, cacheID, NULL, 0, &key); | |
| 250 GrRenderTarget* renderTarget = result ? result->asRenderTarget() : NULL; | |
| 251 if (NULL != renderTarget) { | |
| 252 add_genID_listener(key, bm.pixelRef()); | |
| 253 SkAutoTUnref<GrEffect> yuvToRgbEffect(GrYUVtoRGBEffect::Create( | |
| 254 yuvTextures[0].get(), yuvTextures[1].get(), yuvTextures[2].get())); | |
| 255 GrPaint paint; | |
| 256 paint.addColorEffect(yuvToRgbEffect); | |
| 257 SkRect r = SkRect::MakeWH(yuvSizes[0].fWidth, yuvSizes[0].fHeight); | |
| 258 GrContext::AutoRenderTarget autoRT(ctx, renderTarget); | |
| 259 GrContext::AutoMatrix am; | |
| 260 am.setIdentity(ctx); | |
| 261 GrContext::AutoClip ac(ctx, r); | |
|
bsalomon
2014/07/10 18:29:39
Maybe ac(ctx, GrContext::AutoClip::kWideOpen_Initi
sugoi1
2014/07/10 19:59:06
Will that work if I'm rendering a JPEG while rende
sugoi1
2014/07/11 18:46:15
Done. Seems to work properly in all cases I've tes
| |
| 262 ctx->drawRect(paint, r); | |
| 263 } else { | |
| 264 SkSafeSetNull(result); | |
| 265 } | |
| 266 | |
| 267 return result; | |
| 268 } | |
| 269 | |
| 196 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, | 270 static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx, |
| 197 bool cache, | 271 bool cache, |
| 198 const GrTextureParams* params, | 272 const GrTextureParams* params, |
| 199 const SkBitmap& origBitmap) { | 273 const SkBitmap& origBitmap) { |
| 200 SkBitmap tmpBitmap; | 274 SkBitmap tmpBitmap; |
| 201 | 275 |
| 202 const SkBitmap* bitmap = &origBitmap; | 276 const SkBitmap* bitmap = &origBitmap; |
| 203 | 277 |
| 204 GrTextureDesc desc; | 278 GrTextureDesc desc; |
| 205 generate_bitmap_texture_desc(*bitmap, &desc); | 279 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 | 331 // the bitmap has available pixels, then they might not be what the deco mpressed |
| 258 // data is. | 332 // data is. |
| 259 && !(bitmap->readyToDraw())) { | 333 && !(bitmap->readyToDraw())) { |
| 260 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); | 334 GrTexture *texture = load_etc1_texture(ctx, params, *bitmap, desc); |
| 261 if (NULL != texture) { | 335 if (NULL != texture) { |
| 262 return texture; | 336 return texture; |
| 263 } | 337 } |
| 264 } | 338 } |
| 265 #endif // SK_IGNORE_ETC1_SUPPORT | 339 #endif // SK_IGNORE_ETC1_SUPPORT |
| 266 | 340 |
| 341 else { | |
| 342 GrTexture *texture = load_yuv_texture(ctx, params, *bitmap, desc); | |
| 343 if (NULL != texture) { | |
| 344 return texture; | |
| 345 } | |
| 346 } | |
| 267 SkAutoLockPixels alp(*bitmap); | 347 SkAutoLockPixels alp(*bitmap); |
| 268 if (!bitmap->readyToDraw()) { | 348 if (!bitmap->readyToDraw()) { |
| 269 return NULL; | 349 return NULL; |
| 270 } | 350 } |
| 271 if (cache) { | 351 if (cache) { |
| 272 // This texture is likely to be used again so leave it in the cache | 352 // This texture is likely to be used again so leave it in the cache |
| 273 GrCacheID cacheID; | 353 GrCacheID cacheID; |
| 274 generate_bitmap_cache_id(origBitmap, &cacheID); | 354 generate_bitmap_cache_id(origBitmap, &cacheID); |
| 275 | 355 |
| 276 GrResourceKey key; | 356 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) { | 614 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) && NULL != effect) { |
| 535 grPaint->addColorEffect(effect)->unref(); | 615 grPaint->addColorEffect(effect)->unref(); |
| 536 constantColor = false; | 616 constantColor = false; |
| 537 } | 617 } |
| 538 } | 618 } |
| 539 | 619 |
| 540 // The grcolor is automatically set when calling asneweffect. | 620 // 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. | 621 // 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 ); | 622 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); |
| 543 } | 623 } |
| OLD | NEW |