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

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

Issue 608883003: GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: fix and document hack Created 6 years, 2 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
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 #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
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 = bitmap.getTexture(); 375 GrTexture* result = bitmap.getTexture();
376 if (result) { 376 if (result) {
377 return SkRef(result); 377 return SkRef(result);
378 } 378 }
379 379
380 bool cache = !bitmap.isVolatile(); 380 bool cache = !bitmap.isVolatile();
381 381
382 if (cache) { 382 if (cache) {
383 // If the bitmap isn't changing try to find a cached copy first. 383 // If the bitmap isn't changing try to find a cached copy first.
384 384
385 GrCacheID cacheID; 385 GrCacheID cacheID;
386 generate_bitmap_cache_id(bitmap, &cacheID); 386 generate_bitmap_cache_id(bitmap, &cacheID);
387 387
388 GrTextureDesc desc; 388 GrTextureDesc desc;
389 generate_bitmap_texture_desc(bitmap, &desc); 389 generate_bitmap_texture_desc(bitmap, &desc);
390 390
391 result = ctx->findAndRefTexture(desc, cacheID, params); 391 result = ctx->findAndRefTexture(desc, cacheID, params);
392 } 392 }
393 if (NULL == result) { 393 if (NULL == result) {
394 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap); 394 result = sk_gr_create_bitmap_texture(ctx, cache, params, bitmap);
395 } 395 }
396 if (NULL == result) { 396 if (NULL == result) {
397 GrPrintf("---- failed to create texture for cache [%d %d]\n", 397 GrPrintf("---- failed to create texture for cache [%d %d]\n",
398 bitmap.width(), bitmap.height()); 398 bitmap.width(), bitmap.height());
399 } 399 }
400 return result; 400 return result;
401 } 401 }
402 402
403 void GrUnlockAndUnrefCachedBitmapTexture(GrTexture* texture) {
404 SkASSERT(texture->getContext());
405
406 if (texture->getCacheEntry()) {
407 texture->getContext()->unlockScratchTexture(texture);
408 }
409 texture->unref();
410 }
411
412 /////////////////////////////////////////////////////////////////////////////// 403 ///////////////////////////////////////////////////////////////////////////////
413 404
414 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass 405 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
415 // alpha info, that will be considered. 406 // alpha info, that will be considered.
416 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) { 407 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType) {
417 switch (ct) { 408 switch (ct) {
418 case kUnknown_SkColorType: 409 case kUnknown_SkColorType:
419 return kUnknown_GrPixelConfig; 410 return kUnknown_GrPixelConfig;
420 case kAlpha_8_SkColorType: 411 case kAlpha_8_SkColorType:
421 return kAlpha_8_GrPixelConfig; 412 return kAlpha_8_GrPixelConfig;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) { 573 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) {
583 grPaint->addColorProcessor(fp)->unref(); 574 grPaint->addColorProcessor(fp)->unref();
584 constantColor = false; 575 constantColor = false;
585 } 576 }
586 } 577 }
587 578
588 // The grcolor is automatically set when calling asFragmentProcessor. 579 // 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. 580 // 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 ); 581 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint );
591 } 582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698