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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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* GrLockAndRefCachedBitmapTexture(GrContext* ctx, |
373 const SkBitmap& bitmap, | 373 const SkBitmap& bitmap, |
374 const GrTextureParams* params) { | 374 const GrTextureParams* params) { |
375 GrTexture* result = bitmap.getTexture(); | 375 GrTexture* result = NULL; |
376 if (result) { | |
377 return SkRef(result); | |
378 } | |
379 | 376 |
380 bool cache = !bitmap.isVolatile(); | 377 bool cache = !bitmap.isVolatile(); |
381 | 378 |
382 if (cache) { | 379 if (cache) { |
383 // 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. |
384 | 381 |
385 GrCacheID cacheID; | 382 GrCacheID cacheID; |
386 generate_bitmap_cache_id(bitmap, &cacheID); | 383 generate_bitmap_cache_id(bitmap, &cacheID); |
387 | 384 |
388 GrTextureDesc desc; | 385 GrTextureDesc desc; |
389 generate_bitmap_texture_desc(bitmap, &desc); | 386 generate_bitmap_texture_desc(bitmap, &desc); |
390 | 387 |
391 result = ctx->findAndRefTexture(desc, cacheID, params); | 388 result = ctx->findAndRefTexture(desc, cacheID, params); |
392 } | 389 } |
393 if (NULL == result) { | 390 if (NULL == result) { |
394 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); | 391 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); |
395 } | 392 } |
396 if (NULL == result) { | 393 if (NULL == result) { |
397 GrPrintf("---- failed to create texture for cache [%d %d]\n", | 394 GrPrintf("---- failed to create texture for cache [%d %d]\n", |
398 bitmap.width(), bitmap.height()); | 395 bitmap.width(), bitmap.height()); |
399 } | 396 } |
400 return result; | 397 return result; |
401 } | 398 } |
402 | 399 |
403 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture* texture) { | 400 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture* texture) { |
404 SkASSERT(texture->getContext()); | 401 SkASSERT(texture->getContext()); |
405 | 402 |
406 if (texture->getCacheEntry()) { | 403 texture->getContext()->unlockScratchTexture(texture); |
407 texture->getContext()->unlockScratchTexture(texture); | |
408 } | |
409 texture->unref(); | 404 texture->unref(); |
410 } | 405 } |
411 | 406 |
412 /////////////////////////////////////////////////////////////////////////////// | 407 /////////////////////////////////////////////////////////////////////////////// |
413 | 408 |
414 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 409 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
415 // alpha info, that will be considered. | 410 // alpha info, that will be considered. |
416 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { | 411 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { |
417 switch (ct) { | 412 switch (ct) { |
418 case kUnknown_SkColorType: | 413 case kUnknown_SkColorType: |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 577 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
583 grPaint->addColorProcessor(fp)->unref(); | 578 grPaint->addColorProcessor(fp)->unref(); |
584 constantColor = false; | 579 constantColor = false; |
585 } | 580 } |
586 } | 581 } |
587 | 582 |
588 // The grcolor is automatically set when calling asFragmentProcessor. | 583 // The grcolor is automatically set when calling asFragmentProcessor. |
589 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 584 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
590 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 585 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
591 } | 586 } |
OLD | NEW |