| 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" | 10 #include "GrDrawTargetCaps.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 353 } |
| 354 SkAutoLockPixels alp(*bitmap); | 354 SkAutoLockPixels alp(*bitmap); |
| 355 if (!bitmap->readyToDraw()) { | 355 if (!bitmap->readyToDraw()) { |
| 356 return NULL; | 356 return NULL; |
| 357 } | 357 } |
| 358 | 358 |
| 359 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc, | 359 return sk_gr_allocate_texture(ctx, cache, params, origBitmap, desc, |
| 360 bitmap->getPixels(), bitmap->rowBytes()); | 360 bitmap->getPixels(), bitmap->rowBytes()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 static GrTexture* get_texture_backing_bmp(const SkBitmap& bitmap, const GrContex
t* context, |
| 364 const GrTextureParams* params) { |
| 365 if (GrTexture* texture = bitmap.getTexture()) { |
| 366 // Our texture-resizing-for-tiling used to upscale NPOT textures for til
ing only works with |
| 367 // content-key cached resources. Rather than invest in that legacy code
path, we'll just |
| 368 // take the horribly slow route of causing a cache miss which will cause
the pixels to be |
| 369 // read and reuploaded to a texture with a content key. |
| 370 if (params && !context->getGpu()->caps()->npotTextureTileSupport() && |
| 371 (params->isTiled() || GrTextureParams::kMipMap_FilterMode == params-
>filterMode())) { |
| 372 return NULL; |
| 373 } |
| 374 return texture; |
| 375 } |
| 376 return NULL; |
| 377 } |
| 378 |
| 363 bool GrIsBitmapInCache(const GrContext* ctx, | 379 bool GrIsBitmapInCache(const GrContext* ctx, |
| 364 const SkBitmap& bitmap, | 380 const SkBitmap& bitmap, |
| 365 const GrTextureParams* params) { | 381 const GrTextureParams* params) { |
| 382 if (get_texture_backing_bmp(bitmap, ctx, params)) { |
| 383 return true; |
| 384 } |
| 385 |
| 366 GrCacheID cacheID; | 386 GrCacheID cacheID; |
| 367 generate_bitmap_cache_id(bitmap, &cacheID); | 387 generate_bitmap_cache_id(bitmap, &cacheID); |
| 368 | 388 |
| 369 GrSurfaceDesc desc; | 389 GrSurfaceDesc desc; |
| 370 generate_bitmap_texture_desc(bitmap, &desc); | 390 generate_bitmap_texture_desc(bitmap, &desc); |
| 371 return ctx->isTextureInCache(desc, cacheID, params); | 391 return ctx->isTextureInCache(desc, cacheID, params); |
| 372 } | 392 } |
| 373 | 393 |
| 374 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, | 394 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 375 const SkBitmap& bitmap, | 395 const SkBitmap& bitmap, |
| 376 const GrTextureParams* params) { | 396 const GrTextureParams* params) { |
| 377 GrTexture* result = NULL; | 397 GrTexture* result = get_texture_backing_bmp(bitmap, ctx, params); |
| 398 if (result) { |
| 399 return SkRef(result); |
| 400 } |
| 378 | 401 |
| 379 bool cache = !bitmap.isVolatile(); | 402 bool cache = !bitmap.isVolatile(); |
| 380 | 403 |
| 381 if (cache) { | 404 if (cache) { |
| 382 // If the bitmap isn't changing try to find a cached copy first. | 405 // If the bitmap isn't changing try to find a cached copy first. |
| 383 | 406 |
| 384 GrCacheID cacheID; | 407 GrCacheID cacheID; |
| 385 generate_bitmap_cache_id(bitmap, &cacheID); | 408 generate_bitmap_cache_id(bitmap, &cacheID); |
| 386 | 409 |
| 387 GrSurfaceDesc desc; | 410 GrSurfaceDesc desc; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { | 569 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { |
| 547 grPaint->addColorProcessor(fp)->unref(); | 570 grPaint->addColorProcessor(fp)->unref(); |
| 548 constantColor = false; | 571 constantColor = false; |
| 549 } | 572 } |
| 550 } | 573 } |
| 551 | 574 |
| 552 // The grcolor is automatically set when calling asFragmentProcessor. | 575 // The grcolor is automatically set when calling asFragmentProcessor. |
| 553 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 576 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 554 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 577 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 555 } | 578 } |
| OLD | NEW |