| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); | 173 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key))); |
| 178 } | 174 } |
| 179 #endif | 175 #endif |
| 180 | 176 |
| 181 static GrTexture* create_texture_for_bmp(GrContext* ctx, | 177 static GrTexture* create_texture_for_bmp(GrContext* ctx, |
| 182 const GrContentKey& optionalKey, | 178 const GrContentKey& optionalKey, |
| 183 GrSurfaceDesc desc, | 179 GrSurfaceDesc desc, |
| 184 const void* pixels, | 180 const void* pixels, |
| 185 size_t rowBytes) { | 181 size_t rowBytes) { |
| 186 GrTexture* result; | 182 GrTexture* result; |
| 187 if (optionalKey.isValid()) { | 183 if (optionalKey.isValid() || GrPixelConfigIsCompressed(desc.fConfig)) { |
| 188 result = ctx->createTexture(desc, pixels, rowBytes); | 184 result = ctx->createTexture(desc, pixels, rowBytes); |
| 189 if (result) { | 185 if (result) { |
| 190 SkAssertResult(ctx->addResourceToCache(optionalKey, result)); | 186 SkAssertResult(ctx->addResourceToCache(optionalKey, result)); |
| 191 } | 187 } |
| 192 } else { | 188 } else { |
| 193 result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch)
; | 189 result = ctx->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch)
; |
| 194 if (pixels && result) { | 190 if (pixels && result) { |
| 195 result->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, p
ixels, rowBytes); | 191 result->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, p
ixels, rowBytes); |
| 196 } | 192 } |
| 197 } | 193 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const SkBitmap& origBitmap, | 404 const SkBitmap& origBitmap, |
| 409 const GrContentKey& optional
Key) { | 405 const GrContentKey& optional
Key) { |
| 410 SkBitmap tmpBitmap; | 406 SkBitmap tmpBitmap; |
| 411 | 407 |
| 412 const SkBitmap* bitmap = &origBitmap; | 408 const SkBitmap* bitmap = &origBitmap; |
| 413 | 409 |
| 414 GrSurfaceDesc desc; | 410 GrSurfaceDesc desc; |
| 415 generate_bitmap_texture_desc(*bitmap, &desc); | 411 generate_bitmap_texture_desc(*bitmap, &desc); |
| 416 | 412 |
| 417 if (kIndex_8_SkColorType == bitmap->colorType()) { | 413 if (kIndex_8_SkColorType == bitmap->colorType()) { |
| 418 if (ctx->supportsIndex8PixelConfig()) { | 414 if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
| 419 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, | 415 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, |
| 420 bitmap->width(), bitma
p->height()); | 416 bitmap->width(), bitma
p->height()); |
| 421 SkAutoMalloc storage(imageSize); | 417 SkAutoMalloc storage(imageSize); |
| 422 build_index8_data(storage.get(), origBitmap); | 418 build_index8_data(storage.get(), origBitmap); |
| 423 | 419 |
| 424 // our compressed data will be trimmed, so pass width() for its | 420 // our compressed data will be trimmed, so pass width() for its |
| 425 // "rowBytes", since they are the same now. | 421 // "rowBytes", since they are the same now. |
| 426 return create_texture_for_bmp(ctx, optionalKey, desc, storage.get(),
bitmap->width()); | 422 return create_texture_for_bmp(ctx, optionalKey, desc, storage.get(),
bitmap->width()); |
| 427 } else { | 423 } else { |
| 428 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); | 424 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); |
| 429 // now bitmap points to our temp, which has been promoted to 32bits | 425 // now bitmap points to our temp, which has been promoted to 32bits |
| 430 bitmap = &tmpBitmap; | 426 bitmap = &tmpBitmap; |
| 431 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 427 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); |
| 432 } | 428 } |
| 433 } | 429 } |
| 434 | 430 |
| 435 // Is this an ETC1 encoded texture? | 431 // Is this an ETC1 encoded texture? |
| 436 #ifndef SK_IGNORE_ETC1_SUPPORT | 432 #ifndef SK_IGNORE_ETC1_SUPPORT |
| 437 else if ( | 433 // Make sure that the underlying device supports ETC1 textures before we go
ahead |
| 438 // We do not support scratch ETC1 textures, hence they should all be at
least | 434 // and check the data. |
| 439 // trying to go to the cache. | 435 else if (ctx->isConfigTexturable(kETC1_GrPixelConfig) |
| 440 optionalKey.isValid() | 436 // If the bitmap had compressed data and was then uncompressed, it'l
l still return |
| 441 // Make sure that the underlying device supports ETC1 textures before we
go ahead | 437 // compressed data on 'refEncodedData' and upload it. Probably not g
ood, since if |
| 442 // and check the data. | 438 // the bitmap has available pixels, then they might not be what the
decompressed |
| 443 && ctx->getGpu()->caps()->isConfigTexturable(kETC1_GrPixelConfig) | 439 // data is. |
| 444 // If the bitmap had compressed data and was then uncompressed, it'll st
ill return | 440 && !(bitmap->readyToDraw())) { |
| 445 // compressed data on 'refEncodedData' and upload it. Probably not good,
since if | |
| 446 // the bitmap has available pixels, then they might not be what the deco
mpressed | |
| 447 // data is. | |
| 448 && !(bitmap->readyToDraw())) { | |
| 449 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); | 441 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); |
| 450 if (texture) { | 442 if (texture) { |
| 451 return texture; | 443 return texture; |
| 452 } | 444 } |
| 453 } | 445 } |
| 454 #endif // SK_IGNORE_ETC1_SUPPORT | 446 #endif // SK_IGNORE_ETC1_SUPPORT |
| 455 | 447 |
| 456 else { | 448 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); |
| 457 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); | 449 if (texture) { |
| 458 if (texture) { | 450 return texture; |
| 459 return texture; | |
| 460 } | |
| 461 } | 451 } |
| 452 |
| 462 SkAutoLockPixels alp(*bitmap); | 453 SkAutoLockPixels alp(*bitmap); |
| 463 if (!bitmap->readyToDraw()) { | 454 if (!bitmap->readyToDraw()) { |
| 464 return NULL; | 455 return NULL; |
| 465 } | 456 } |
| 466 | 457 |
| 467 return create_texture_for_bmp(ctx, optionalKey, desc, bitmap->getPixels(), b
itmap->rowBytes()); | 458 return create_texture_for_bmp(ctx, optionalKey, desc, bitmap->getPixels(), b
itmap->rowBytes()); |
| 468 } | 459 } |
| 469 | 460 |
| 470 static GrTexture* create_bitmap_texture(GrContext* ctx, | 461 static GrTexture* create_bitmap_texture(GrContext* ctx, |
| 471 const SkBitmap& bmp, | 462 const SkBitmap& bmp, |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { | 717 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { |
| 727 grPaint->addColorProcessor(fp)->unref(); | 718 grPaint->addColorProcessor(fp)->unref(); |
| 728 constantColor = false; | 719 constantColor = false; |
| 729 } | 720 } |
| 730 } | 721 } |
| 731 | 722 |
| 732 // The grcolor is automatically set when calling asFragmentProcessor. | 723 // The grcolor is automatically set when calling asFragmentProcessor. |
| 733 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 724 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 734 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 725 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 735 } | 726 } |
| OLD | NEW |