| 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 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
| 10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 const SkBitmap& bitmap, | 362 const SkBitmap& bitmap, |
| 363 const GrTextureParams* params) { | 363 const GrTextureParams* params) { |
| 364 GrCacheID cacheID; | 364 GrCacheID cacheID; |
| 365 generate_bitmap_cache_id(bitmap, &cacheID); | 365 generate_bitmap_cache_id(bitmap, &cacheID); |
| 366 | 366 |
| 367 GrTextureDesc desc; | 367 GrTextureDesc desc; |
| 368 generate_bitmap_texture_desc(bitmap, &desc); | 368 generate_bitmap_texture_desc(bitmap, &desc); |
| 369 return ctx->isTextureInCache(desc, cacheID, params); | 369 return ctx->isTextureInCache(desc, cacheID, params); |
| 370 } | 370 } |
| 371 | 371 |
| 372 GrTexture* GrLockAndRefCachedBitmapTexture(GrContext* ctx, | 372 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, |
| 373 const SkBitmap& bitmap, | 373 const SkBitmap& bitmap, |
| 374 const GrTextureParams* params) { | 374 const GrTextureParams* params) { |
| 375 GrTexture* result = NULL; | 375 GrTexture* result = NULL; |
| 376 | 376 |
| 377 bool cache = !bitmap.isVolatile(); | 377 bool cache = !bitmap.isVolatile(); |
| 378 | 378 |
| 379 if (cache) { | 379 if (cache) { |
| 380 // If the bitmap isn't changing try to find a cached copy first. | 380 // If the bitmap isn't changing try to find a cached copy first. |
| 381 | 381 |
| 382 GrCacheID cacheID; | 382 GrCacheID cacheID; |
| 383 generate_bitmap_cache_id(bitmap, &cacheID); | 383 generate_bitmap_cache_id(bitmap, &cacheID); |
| 384 | 384 |
| 385 GrTextureDesc desc; | 385 GrTextureDesc desc; |
| 386 generate_bitmap_texture_desc(bitmap, &desc); | 386 generate_bitmap_texture_desc(bitmap, &desc); |
| 387 | 387 |
| 388 result = ctx->findAndRefTexture(desc, cacheID, params); | 388 result = ctx->findAndRefTexture(desc, cacheID, params); |
| 389 } | 389 } |
| 390 if (NULL == result) { | 390 if (NULL == result) { |
| 391 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); | 391 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); |
| 392 } | 392 } |
| 393 if (NULL == result) { | 393 if (NULL == result) { |
| 394 GrPrintf("---- failed to create texture for cache [%d %d]\n", | 394 GrPrintf("---- failed to create texture for cache [%d %d]\n", |
| 395 bitmap.width(), bitmap.height()); | 395 bitmap.width(), bitmap.height()); |
| 396 } | 396 } |
| 397 return result; | 397 return result; |
| 398 } | 398 } |
| 399 | 399 |
| 400 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture* texture) { | |
| 401 SkASSERT(texture->getContext()); | |
| 402 | |
| 403 texture->getContext()->unlockScratchTexture(texture); | |
| 404 texture->unref(); | |
| 405 } | |
| 406 | |
| 407 /////////////////////////////////////////////////////////////////////////////// | 400 /////////////////////////////////////////////////////////////////////////////// |
| 408 | 401 |
| 409 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 402 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
| 410 // alpha info, that will be considered. | 403 // alpha info, that will be considered. |
| 411 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { | 404 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { |
| 412 switch (ct) { | 405 switch (ct) { |
| 413 case kUnknown_SkColorType: | 406 case kUnknown_SkColorType: |
| 414 return kUnknown_GrPixelConfig; | 407 return kUnknown_GrPixelConfig; |
| 415 case kAlpha_8_SkColorType: | 408 case kAlpha_8_SkColorType: |
| 416 return kAlpha_8_GrPixelConfig; | 409 return kAlpha_8_GrPixelConfig; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 570 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
| 578 grPaint->addColorProcessor(fp)->unref(); | 571 grPaint->addColorProcessor(fp)->unref(); |
| 579 constantColor = false; | 572 constantColor = false; |
| 580 } | 573 } |
| 581 } | 574 } |
| 582 | 575 |
| 583 // The grcolor is automatically set when calling asFragmentProcessor. | 576 // The grcolor is automatically set when calling asFragmentProcessor. |
| 584 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 577 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 585 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 578 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 586 } | 579 } |
| OLD | NEW |