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 | 9 |
| 10 #include "GrDrawTargetCaps.h" | |
| 11 #include "GrGpu.h" | |
| 12 #include "GrGpuResourceCacheAccess.h" | |
| 13 #include "GrXferProcessor.h" | 10 #include "GrXferProcessor.h" |
| 14 #include "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
| 15 #include "SkConfig8888.h" | 12 #include "SkConfig8888.h" |
| 16 #include "SkData.h" | 13 #include "SkData.h" |
| 17 #include "SkMessageBus.h" | 14 #include "SkMessageBus.h" |
| 18 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
| 19 #include "SkResourceCache.h" | 16 #include "SkResourceCache.h" |
| 20 #include "SkTextureCompressor.h" | 17 #include "SkTextureCompressor.h" |
| 21 #include "SkYUVPlanesCache.h" | 18 #include "SkYUVPlanesCache.h" |
| 22 #include "effects/GrDitherEffect.h" | 19 #include "effects/GrDitherEffect.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 | 86 |
| 90 enum Stretch { | 87 enum Stretch { |
| 91 kNo_Stretch, | 88 kNo_Stretch, |
| 92 kBilerp_Stretch, | 89 kBilerp_Stretch, |
| 93 kNearest_Stretch | 90 kNearest_Stretch |
| 94 }; | 91 }; |
| 95 | 92 |
| 96 static Stretch get_stretch_type(const GrContext* ctx, int width, int height, | 93 static Stretch get_stretch_type(const GrContext* ctx, int width, int height, |
| 97 const GrTextureParams* params) { | 94 const GrTextureParams* params) { |
| 98 if (params && params->isTiled()) { | 95 if (params && params->isTiled()) { |
| 99 const GrDrawTargetCaps* caps = ctx->getGpu()->caps(); | 96 if (!ctx->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(hei ght))) { |
| 100 if (!caps->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(he ight))) { | |
| 101 switch(params->filterMode()) { | 97 switch(params->filterMode()) { |
| 102 case GrTextureParams::kNone_FilterMode: | 98 case GrTextureParams::kNone_FilterMode: |
| 103 return kNearest_Stretch; | 99 return kNearest_Stretch; |
| 104 case GrTextureParams::kBilerp_FilterMode: | 100 case GrTextureParams::kBilerp_FilterMode: |
| 105 case GrTextureParams::kMipMap_FilterMode: | 101 case GrTextureParams::kMipMap_FilterMode: |
| 106 return kBilerp_Stretch; | 102 return kBilerp_Stretch; |
| 107 } | 103 } |
| 108 } | 104 } |
| 109 } | 105 } |
| 110 return kNo_Stretch; | 106 return kNo_Stretch; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { | 209 if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { |
| 214 rtDesc.fConfig = kSkia8888_GrPixelConfig; | 210 rtDesc.fConfig = kSkia8888_GrPixelConfig; |
| 215 } else { | 211 } else { |
| 216 return NULL; | 212 return NULL; |
| 217 } | 213 } |
| 218 } else { | 214 } else { |
| 219 return NULL; | 215 return NULL; |
| 220 } | 216 } |
| 221 } | 217 } |
| 222 | 218 |
| 223 GrTexture* resized = context->getGpu()->createTexture(rtDesc, true, NULL, 0) ; | 219 GrTexture* resized = context->createTexture(rtDesc); |
| 224 | 220 |
| 225 if (!resized) { | 221 if (!resized) { |
| 226 return NULL; | 222 return NULL; |
| 227 } | 223 } |
| 228 GrPaint paint; | 224 GrPaint paint; |
| 229 | 225 |
| 230 // If filtering is not desired then we want to ensure all texels in the resa mpled image are | 226 // If filtering is not desired then we want to ensure all texels in the resa mpled image are |
| 231 // copies of texels from the original. | 227 // copies of texels from the original. |
| 232 GrTextureParams params(SkShader::kClamp_TileMode, | 228 GrTextureParams params(SkShader::kClamp_TileMode, |
| 233 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode : | 229 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode : |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 247 | 243 |
| 248 return resized; | 244 return resized; |
| 249 } | 245 } |
| 250 | 246 |
| 251 static GrTexture* sk_gr_allocate_texture(GrContext* ctx, | 247 static GrTexture* sk_gr_allocate_texture(GrContext* ctx, |
| 252 const GrContentKey& optionalKey, | 248 const GrContentKey& optionalKey, |
| 253 GrSurfaceDesc desc, | 249 GrSurfaceDesc desc, |
| 254 const void* pixels, | 250 const void* pixels, |
| 255 size_t rowBytes) { | 251 size_t rowBytes) { |
| 256 GrTexture* result; | 252 GrTexture* result; |
| 257 if (optionalKey.isValid()) { | 253 // Compressed textures cannot be scratch. |
| 254 if (optionalKey.isValid() || GrPixelConfigIsCompressed(desc.fConfig)) { | |
| 258 result = ctx->createTexture(desc, pixels, rowBytes); | 255 result = ctx->createTexture(desc, pixels, rowBytes); |
| 259 if (result) { | 256 if (result) { |
| 260 SkASSERT(ctx->addResourceToCache(optionalKey, result)); | 257 SkASSERT(ctx->addResourceToCache(optionalKey, result)); |
| 261 } | 258 } |
| 262 | 259 |
| 263 } else { | 260 } else { |
| 264 result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch) ; | 261 result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch) ; |
| 265 if (pixels && result) { | 262 if (pixels && result) { |
| 266 result->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, p ixels, rowBytes); | 263 result->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, p ixels, rowBytes); |
| 267 } | 264 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 const SkBitmap& origBitmap, | 410 const SkBitmap& origBitmap, |
| 414 const GrContentKey& optional Key) { | 411 const GrContentKey& optional Key) { |
| 415 SkBitmap tmpBitmap; | 412 SkBitmap tmpBitmap; |
| 416 | 413 |
| 417 const SkBitmap* bitmap = &origBitmap; | 414 const SkBitmap* bitmap = &origBitmap; |
| 418 | 415 |
| 419 GrSurfaceDesc desc; | 416 GrSurfaceDesc desc; |
| 420 generate_bitmap_texture_desc(*bitmap, &desc); | 417 generate_bitmap_texture_desc(*bitmap, &desc); |
| 421 | 418 |
| 422 if (kIndex_8_SkColorType == bitmap->colorType()) { | 419 if (kIndex_8_SkColorType == bitmap->colorType()) { |
| 423 if (ctx->supportsIndex8PixelConfig()) { | 420 if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
| 424 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , | 421 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , |
| 425 bitmap->width(), bitma p->height()); | 422 bitmap->width(), bitma p->height()); |
| 426 SkAutoMalloc storage(imageSize); | 423 SkAutoMalloc storage(imageSize); |
| 427 build_index8_data(storage.get(), origBitmap); | 424 build_index8_data(storage.get(), origBitmap); |
| 428 | 425 |
| 429 // our compressed data will be trimmed, so pass width() for its | 426 // our compressed data will be trimmed, so pass width() for its |
| 430 // "rowBytes", since they are the same now. | 427 // "rowBytes", since they are the same now. |
| 431 return sk_gr_allocate_texture(ctx, optionalKey, desc, storage.get(), bitmap->width()); | 428 return sk_gr_allocate_texture(ctx, optionalKey, desc, storage.get(), bitmap->width()); |
| 432 } else { | 429 } else { |
| 433 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 430 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
| 434 // now bitmap points to our temp, which has been promoted to 32bits | 431 // now bitmap points to our temp, which has been promoted to 32bits |
| 435 bitmap = &tmpBitmap; | 432 bitmap = &tmpBitmap; |
| 436 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 433 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
| 437 } | 434 } |
| 438 } | 435 } |
| 439 | 436 |
| 440 // Is this an ETC1 encoded texture? | 437 // Is this an ETC1 encoded texture? |
| 441 #ifndef SK_IGNORE_ETC1_SUPPORT | 438 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 442 else if ( | 439 // Make sure that the underlying device supports ETC1 textures before we go ahead |
| 443 // We do not support scratch ETC1 textures, hence they should all be at least | 440 // and check the data. |
| 444 // trying to go to the cache. | 441 else if (ctx->isConfigTexturable(kETC1_GrPixelConfig) |
| 445 optionalKey.isValid() | 442 // If the bitmap had compressed data and was then uncompressed, it'l l still return |
| 446 // Make sure that the underlying device supports ETC1 textures before we go ahead | 443 // compressed data on 'refEncodedData' and upload it. Probably not g ood, since if |
| 447 // and check the data. | 444 // the bitmap has available pixels, then they might not be what the decompressed |
| 448 && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelConfig) | 445 // data is. |
| 449 // If the bitmap had compressed data and was then uncompressed, it'll st ill return | 446 && !(bitmap->readyToDraw())) { |
| 450 // compressed data on 'refEncodedData' and upload it. Probably not good, since if | |
| 451 // the bitmap has available pixels, then they might not be what the deco mpressed | |
| 452 // data is. | |
| 453 && !(bitmap->readyToDraw())) { | |
| 454 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); | 447 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); |
| 455 if (texture) { | 448 if (texture) { |
| 456 return texture; | 449 return texture; |
| 457 } | 450 } |
| 458 } | 451 } |
| 459 #endif // SK_IGNORE_ETC1_SUPPORT | 452 #endif // SK_IGNORE_ETC1_SUPPORT |
| 460 | 453 |
| 461 else { | 454 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); |
|
bsalomon
2015/02/01 03:37:50
This else meant that when etc1 was compiled in and
| |
| 462 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); | 455 if (texture) { |
| 463 if (texture) { | 456 return texture; |
| 464 return texture; | |
| 465 } | |
| 466 } | 457 } |
| 458 | |
| 467 SkAutoLockPixels alp(*bitmap); | 459 SkAutoLockPixels alp(*bitmap); |
| 468 if (!bitmap->readyToDraw()) { | 460 if (!bitmap->readyToDraw()) { |
| 469 return NULL; | 461 return NULL; |
| 470 } | 462 } |
| 471 | 463 |
| 472 return sk_gr_allocate_texture(ctx, optionalKey, desc, bitmap->getPixels(), b itmap->rowBytes()); | 464 return sk_gr_allocate_texture(ctx, optionalKey, desc, bitmap->getPixels(), b itmap->rowBytes()); |
| 473 } | 465 } |
| 474 | 466 |
| 475 static GrTexture* create_bitmap_texture(GrContext* ctx, | 467 static GrTexture* create_bitmap_texture(GrContext* ctx, |
| 476 const SkBitmap& bmp, | 468 const SkBitmap& bmp, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 497 | 489 |
| 498 } | 490 } |
| 499 | 491 |
| 500 static GrTexture* get_texture_backing_bmp(const SkBitmap& bitmap, const GrContex t* context, | 492 static GrTexture* get_texture_backing_bmp(const SkBitmap& bitmap, const GrContex t* context, |
| 501 const GrTextureParams* params) { | 493 const GrTextureParams* params) { |
| 502 if (GrTexture* texture = bitmap.getTexture()) { | 494 if (GrTexture* texture = bitmap.getTexture()) { |
| 503 // Our texture-resizing-for-tiling used to upscale NPOT textures for til ing only works with | 495 // Our texture-resizing-for-tiling used to upscale NPOT textures for til ing only works with |
| 504 // content-key cached resources. Rather than invest in that legacy code path, we'll just | 496 // content-key cached resources. Rather than invest in that legacy code path, we'll just |
| 505 // take the horribly slow route of causing a cache miss which will cause the pixels to be | 497 // take the horribly slow route of causing a cache miss which will cause the pixels to be |
| 506 // read and reuploaded to a texture with a content key. | 498 // read and reuploaded to a texture with a content key. |
| 507 if (params && !context->getGpu()->caps()->npotTextureTileSupport() && | 499 if (params && !context->npotTextureTileSupport() && |
| 508 (params->isTiled() || GrTextureParams::kMipMap_FilterMode == params- >filterMode())) { | 500 (params->isTiled() || GrTextureParams::kMipMap_FilterMode == params- >filterMode())) { |
| 509 return NULL; | 501 return NULL; |
| 510 } | 502 } |
| 511 return texture; | 503 return texture; |
| 512 } | 504 } |
| 513 return NULL; | 505 return NULL; |
| 514 } | 506 } |
| 515 | 507 |
| 516 bool GrIsBitmapInCache(const GrContext* ctx, | 508 bool GrIsBitmapInCache(const GrContext* ctx, |
| 517 const SkBitmap& bitmap, | 509 const SkBitmap& bitmap, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { | 714 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { |
| 723 grPaint->addColorProcessor(fp)->unref(); | 715 grPaint->addColorProcessor(fp)->unref(); |
| 724 constantColor = false; | 716 constantColor = false; |
| 725 } | 717 } |
| 726 } | 718 } |
| 727 | 719 |
| 728 // The grcolor is automatically set when calling asFragmentProcessor. | 720 // The grcolor is automatically set when calling asFragmentProcessor. |
| 729 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. | 721 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. |
| 730 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); | 722 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); |
| 731 } | 723 } |
| OLD | NEW |