Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: src/gpu/SkGr.cpp

Issue 890223003: Make npot resizing work properly for bmps that are explicitly texture backed. (Closed) Base URL: https://skia.googlesource.com/skia.git@pub_content_key
Patch Set: fix Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 10 #include "GrDrawTargetCaps.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 485 }
486 } 486 }
487 GrTexture* resized = resize_texture(unstretched, stretch, stretchedKey); 487 GrTexture* resized = resize_texture(unstretched, stretch, stretchedKey);
488 return resized; 488 return resized;
489 } 489 }
490 490
491 return create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey); 491 return create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey);
492 492
493 } 493 }
494 494
495 static GrTexture* get_texture_backing_bmp(const SkBitmap& bitmap, const GrContex t* context,
496 const GrTextureParams* params) {
497 if (GrTexture* texture = bitmap.getTexture()) {
498 // Our texture-resizing-for-tiling used to upscale NPOT textures for til ing only works with
499 // content-key cached resources. Rather than invest in that legacy code path, we'll just
500 // take the horribly slow route of causing a cache miss which will cause the pixels to be
501 // read and reuploaded to a texture with a content key.
502 if (params && !context->getGpu()->caps()->npotTextureTileSupport() &&
503 (params->isTiled() || GrTextureParams::kMipMap_FilterMode == params- >filterMode())) {
504 return NULL;
505 }
506 return texture;
507 }
508 return NULL;
509 }
510
511 bool GrIsBitmapInCache(const GrContext* ctx, 495 bool GrIsBitmapInCache(const GrContext* ctx,
512 const SkBitmap& bitmap, 496 const SkBitmap& bitmap,
513 const GrTextureParams* params) { 497 const GrTextureParams* params) {
514 if (get_texture_backing_bmp(bitmap, ctx, params)) { 498 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
515 return true; 499
500 // Handle the case where the bitmap is explicitly texture backed.
501 GrTexture* texture = bitmap.getTexture();
502 if (texture) {
503 if (kNo_Stretch == stretch) {
504 return true;
505 }
506 // No keys for volatile bitmaps.
507 if (bitmap.isVolatile()) {
508 return false;
509 }
510 const GrContentKey& key = texture->getContentKey();
511 if (!key.isValid()) {
512 return false;
513 }
514 GrContentKey resizedKey;
515 make_resize_key(key, stretch, &resizedKey);
516 return ctx->isResourceInCache(resizedKey);
516 } 517 }
517 518
518 // We don't cache volatile bitmaps 519 // We don't cache volatile bitmaps
519 if (bitmap.isVolatile()) { 520 if (bitmap.isVolatile()) {
520 return false; 521 return false;
521 } 522 }
522 523
523 // If it is inherently texture backed, consider it in the cache
524 if (bitmap.getTexture()) {
525 return true;
526 }
527
528 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
529 GrContentKey key, resizedKey; 524 GrContentKey key, resizedKey;
530 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey); 525 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey);
531
532 GrSurfaceDesc desc;
533 generate_bitmap_texture_desc(bitmap, &desc);
534 return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : resizedKey); 526 return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : resizedKey);
535 } 527 }
536 528
537 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, 529 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
538 const SkBitmap& bitmap, 530 const SkBitmap& bitmap,
539 const GrTextureParams* params) { 531 const GrTextureParams* params) {
540 GrTexture* result = get_texture_backing_bmp(bitmap, ctx, params); 532
533 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
534
535 GrTexture* result = bitmap.getTexture();
541 if (result) { 536 if (result) {
542 return SkRef(result); 537 if (kNo_Stretch == stretch) {
538 return SkRef(result);
539 }
540 GrContentKey resizedKey;
541 // Don't create a key for the resized version if the bmp is volatile.
542 if (!bitmap.isVolatile()) {
543 const GrContentKey& key = result->getContentKey();
544 if (key.isValid()) {
545 make_resize_key(key, stretch, &resizedKey);
546 GrTexture* stretched = ctx->findAndRefCachedTexture(resizedKey);
547 if (stretched) {
548 return stretched;
549 }
550 }
551 }
552 return resize_texture(result, stretch, resizedKey);
543 } 553 }
544 554
545 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
546 GrContentKey key, resizedKey; 555 GrContentKey key, resizedKey;
547 556
548 if (!bitmap.isVolatile()) { 557 if (!bitmap.isVolatile()) {
549 // If the bitmap isn't changing try to find a cached copy first. 558 // If the bitmap isn't changing try to find a cached copy first.
550 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey); 559 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey);
551 560
552 result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey : key); 561 result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey : key);
553 if (result) { 562 if (result) {
554 return result; 563 return result;
555 } 564 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { 726 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) {
718 grPaint->addColorProcessor(fp)->unref(); 727 grPaint->addColorProcessor(fp)->unref();
719 constantColor = false; 728 constantColor = false;
720 } 729 }
721 } 730 }
722 731
723 // The grcolor is automatically set when calling asFragmentProcessor. 732 // The grcolor is automatically set when calling asFragmentProcessor.
724 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 733 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
725 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); 734 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint );
726 } 735 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698