| 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 "GrXferProcessor.h" | 10 #include "GrXferProcessor.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 } // namespace | 171 } // namespace |
| 172 | 172 |
| 173 | 173 |
| 174 static GrTexture* create_texture_for_bmp(GrContext* ctx, | 174 static GrTexture* create_texture_for_bmp(GrContext* ctx, |
| 175 const GrUniqueKey& optionalKey, | 175 const GrUniqueKey& optionalKey, |
| 176 GrSurfaceDesc desc, | 176 GrSurfaceDesc desc, |
| 177 SkPixelRef* pixelRefForInvalidationNoti
fication, | 177 SkPixelRef* pixelRefForInvalidationNoti
fication, |
| 178 const void* pixels, | 178 const void* pixels, |
| 179 size_t rowBytes) { | 179 size_t rowBytes) { |
| 180 GrTexture* result = ctx->createTexture(desc, true, pixels, rowBytes); | 180 GrTexture* result = ctx->textureProvider()->createTexture(desc, true, pixels
, rowBytes); |
| 181 if (result && optionalKey.isValid()) { | 181 if (result && optionalKey.isValid()) { |
| 182 BitmapInvalidator* listener = SkNEW_ARGS(BitmapInvalidator, (optionalKey
)); | 182 BitmapInvalidator* listener = SkNEW_ARGS(BitmapInvalidator, (optionalKey
)); |
| 183 pixelRefForInvalidationNotification->addGenIDChangeListener(listener); | 183 pixelRefForInvalidationNotification->addGenIDChangeListener(listener); |
| 184 ctx->addResourceToCache(optionalKey, result); | 184 ctx->textureProvider()->assignUniqueKeyToTexture(optionalKey, result); |
| 185 } | 185 } |
| 186 return result; | 186 return result; |
| 187 } | 187 } |
| 188 | 188 |
| 189 // creates a new texture that is the input texture scaled up to the next power o
f two in | 189 // creates a new texture that is the input texture scaled up to the next power o
f two in |
| 190 // width or height. If optionalKey is valid it will be set on the new texture. s
tretch | 190 // width or height. If optionalKey is valid it will be set on the new texture. s
tretch |
| 191 // controls whether the scaling is done using nearest or bilerp filtering. | 191 // controls whether the scaling is done using nearest or bilerp filtering. |
| 192 GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch, | 192 GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch, |
| 193 SkPixelRef* pixelRef, | 193 SkPixelRef* pixelRef, |
| 194 const GrUniqueKey& optionalKey) { | 194 const GrUniqueKey& optionalKey) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 361 |
| 362 GrSurfaceDesc yuvDesc; | 362 GrSurfaceDesc yuvDesc; |
| 363 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 363 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 364 SkAutoTUnref<GrTexture> yuvTextures[3]; | 364 SkAutoTUnref<GrTexture> yuvTextures[3]; |
| 365 for (int i = 0; i < 3; ++i) { | 365 for (int i = 0; i < 3; ++i) { |
| 366 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; | 366 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
| 367 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; | 367 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
| 368 bool needsExactTexture = | 368 bool needsExactTexture = |
| 369 (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || | 369 (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || |
| 370 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); | 370 (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); |
| 371 yuvTextures[i].reset(ctx->refScratchTexture(yuvDesc, | 371 yuvTextures[i].reset(ctx->textureProvider()->refScratchTexture(yuvDesc, |
| 372 needsExactTexture ? GrContext::kExact_ScratchTexMatch : | 372 needsExactTexture ? GrTextureProvider::kExact_ScratchTexMatch : |
| 373 GrContext::kApprox_ScratchTexMatch)); | 373 GrTextureProvider::kApprox_ScratchTexMatch)); |
| 374 if (!yuvTextures[i] || | 374 if (!yuvTextures[i] || |
| 375 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, | 375 !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
| 376 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { | 376 yuvDesc.fConfig, planes[i], yuvInfo.fRo
wBytes[i])) { |
| 377 return NULL; | 377 return NULL; |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 GrSurfaceDesc rtDesc = desc; | 381 GrSurfaceDesc rtDesc = desc; |
| 382 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; | 382 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; |
| 383 | 383 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 464 |
| 465 static GrTexture* create_bitmap_texture(GrContext* ctx, | 465 static GrTexture* create_bitmap_texture(GrContext* ctx, |
| 466 const SkBitmap& bmp, | 466 const SkBitmap& bmp, |
| 467 Stretch stretch, | 467 Stretch stretch, |
| 468 const GrUniqueKey& unstretchedKey, | 468 const GrUniqueKey& unstretchedKey, |
| 469 const GrUniqueKey& stretchedKey) { | 469 const GrUniqueKey& stretchedKey) { |
| 470 if (kNo_Stretch != stretch) { | 470 if (kNo_Stretch != stretch) { |
| 471 SkAutoTUnref<GrTexture> unstretched; | 471 SkAutoTUnref<GrTexture> unstretched; |
| 472 // Check if we have the unstretched version in the cache, if not create
it. | 472 // Check if we have the unstretched version in the cache, if not create
it. |
| 473 if (unstretchedKey.isValid()) { | 473 if (unstretchedKey.isValid()) { |
| 474 unstretched.reset(ctx->findAndRefCachedTexture(unstretchedKey)); | 474 unstretched.reset(ctx->textureProvider()->findAndRefTextureByUniqueK
ey(unstretchedKey)); |
| 475 } | 475 } |
| 476 if (!unstretched) { | 476 if (!unstretched) { |
| 477 unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstre
tchedKey)); | 477 unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstre
tchedKey)); |
| 478 if (!unstretched) { | 478 if (!unstretched) { |
| 479 return NULL; | 479 return NULL; |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 GrTexture* stretched = stretch_texture_to_next_pot(unstretched, stretch,
bmp.pixelRef(), | 482 GrTexture* stretched = stretch_texture_to_next_pot(unstretched, stretch,
bmp.pixelRef(), |
| 483 stretchedKey); | 483 stretchedKey); |
| 484 return stretched; | 484 return stretched; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 502 // No keys for volatile bitmaps. | 502 // No keys for volatile bitmaps. |
| 503 if (bitmap.isVolatile()) { | 503 if (bitmap.isVolatile()) { |
| 504 return false; | 504 return false; |
| 505 } | 505 } |
| 506 const GrUniqueKey& key = texture->getUniqueKey(); | 506 const GrUniqueKey& key = texture->getUniqueKey(); |
| 507 if (!key.isValid()) { | 507 if (!key.isValid()) { |
| 508 return false; | 508 return false; |
| 509 } | 509 } |
| 510 GrUniqueKey stretchedKey; | 510 GrUniqueKey stretchedKey; |
| 511 make_stretched_key(key, stretch, &stretchedKey); | 511 make_stretched_key(key, stretch, &stretchedKey); |
| 512 return ctx->isResourceInCache(stretchedKey); | 512 return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey); |
| 513 } | 513 } |
| 514 | 514 |
| 515 // We don't cache volatile bitmaps | 515 // We don't cache volatile bitmaps |
| 516 if (bitmap.isVolatile()) { | 516 if (bitmap.isVolatile()) { |
| 517 return false; | 517 return false; |
| 518 } | 518 } |
| 519 | 519 |
| 520 GrUniqueKey key, stretchedKey; | 520 GrUniqueKey key, stretchedKey; |
| 521 make_bitmap_keys(bitmap, stretch, &key, &stretchedKey); | 521 make_bitmap_keys(bitmap, stretch, &key, &stretchedKey); |
| 522 return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : stretchedKey)
; | 522 return ctx->textureProvider()->existsTextureWithUniqueKey( |
| 523 (kNo_Stretch == stretch) ? key : stretchedKey); |
| 523 } | 524 } |
| 524 | 525 |
| 525 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, | 526 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 526 const SkBitmap& bitmap, | 527 const SkBitmap& bitmap, |
| 527 const GrTextureParams* params) { | 528 const GrTextureParams* params) { |
| 528 | 529 |
| 529 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par
ams); | 530 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par
ams); |
| 530 | 531 |
| 531 GrTexture* result = bitmap.getTexture(); | 532 GrTexture* result = bitmap.getTexture(); |
| 532 if (result) { | 533 if (result) { |
| 533 if (kNo_Stretch == stretch) { | 534 if (kNo_Stretch == stretch) { |
| 534 return SkRef(result); | 535 return SkRef(result); |
| 535 } | 536 } |
| 536 GrUniqueKey stretchedKey; | 537 GrUniqueKey stretchedKey; |
| 537 // Don't create a key for the resized version if the bmp is volatile. | 538 // Don't create a key for the resized version if the bmp is volatile. |
| 538 if (!bitmap.isVolatile()) { | 539 if (!bitmap.isVolatile()) { |
| 539 const GrUniqueKey& key = result->getUniqueKey(); | 540 const GrUniqueKey& key = result->getUniqueKey(); |
| 540 if (key.isValid()) { | 541 if (key.isValid()) { |
| 541 make_stretched_key(key, stretch, &stretchedKey); | 542 make_stretched_key(key, stretch, &stretchedKey); |
| 542 GrTexture* stretched = ctx->findAndRefCachedTexture(stretchedKey
); | 543 GrTexture* stretched = |
| 544 ctx->textureProvider()->findAndRefTextureByUniqueKey(stretch
edKey); |
| 543 if (stretched) { | 545 if (stretched) { |
| 544 return stretched; | 546 return stretched; |
| 545 } | 547 } |
| 546 } | 548 } |
| 547 } | 549 } |
| 548 return stretch_texture_to_next_pot(result, stretch, bitmap.pixelRef(), s
tretchedKey); | 550 return stretch_texture_to_next_pot(result, stretch, bitmap.pixelRef(), s
tretchedKey); |
| 549 } | 551 } |
| 550 | 552 |
| 551 GrUniqueKey key, resizedKey; | 553 GrUniqueKey key, resizedKey; |
| 552 | 554 |
| 553 if (!bitmap.isVolatile()) { | 555 if (!bitmap.isVolatile()) { |
| 554 // If the bitmap isn't changing try to find a cached copy first. | 556 // If the bitmap isn't changing try to find a cached copy first. |
| 555 make_bitmap_keys(bitmap, stretch, &key, &resizedKey); | 557 make_bitmap_keys(bitmap, stretch, &key, &resizedKey); |
| 556 | 558 |
| 557 result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey
: key); | 559 result = ctx->textureProvider()->findAndRefTextureByUniqueKey( |
| 560 resizedKey.isValid() ? resizedKey : key); |
| 558 if (result) { | 561 if (result) { |
| 559 return result; | 562 return result; |
| 560 } | 563 } |
| 561 } | 564 } |
| 562 | 565 |
| 563 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); | 566 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); |
| 564 if (result) { | 567 if (result) { |
| 565 return result; | 568 return result; |
| 566 } | 569 } |
| 567 | 570 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 if (fp) { | 730 if (fp) { |
| 728 grPaint->addColorProcessor(fp)->unref(); | 731 grPaint->addColorProcessor(fp)->unref(); |
| 729 constantColor = false; | 732 constantColor = false; |
| 730 } | 733 } |
| 731 } | 734 } |
| 732 | 735 |
| 733 // The grcolor is automatically set when calling asFragmentProcessor. | 736 // The grcolor is automatically set when calling asFragmentProcessor. |
| 734 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 737 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 735 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); | 738 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); |
| 736 } | 739 } |
| OLD | NEW |