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

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

Issue 902873002: Reimplement gpu message bus for invalidated bitmap gen IDs (Closed) Base URL: https://skia.googlesource.com/skia.git@one_tex
Patch Set: fix speeling error 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 | « src/gpu/GrResourceCache2.cpp ('k') | tests/MessageBusTest.cpp » ('j') | 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 "GrXferProcessor.h" 10 #include "GrXferProcessor.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return kNearest_Stretch; 99 return kNearest_Stretch;
100 case GrTextureParams::kBilerp_FilterMode: 100 case GrTextureParams::kBilerp_FilterMode:
101 case GrTextureParams::kMipMap_FilterMode: 101 case GrTextureParams::kMipMap_FilterMode:
102 return kBilerp_Stretch; 102 return kBilerp_Stretch;
103 } 103 }
104 } 104 }
105 } 105 }
106 return kNo_Stretch; 106 return kNo_Stretch;
107 } 107 }
108 108
109 static bool make_resize_key(const GrContentKey& origKey, Stretch stretch, GrCont entKey* resizeKey) { 109 static bool make_stretched_key(const GrContentKey& origKey, Stretch stretch,
110 GrContentKey* stretchedKey) {
110 if (origKey.isValid() && kNo_Stretch != stretch) { 111 if (origKey.isValid() && kNo_Stretch != stretch) {
111 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain (); 112 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain ();
112 GrContentKey::Builder builder(resizeKey, origKey, kDomain, 1); 113 GrContentKey::Builder builder(stretchedKey, origKey, kDomain, 1);
113 builder[0] = stretch; 114 builder[0] = stretch;
114 builder.finish(); 115 builder.finish();
115 return true; 116 return true;
116 } 117 }
117 SkASSERT(!resizeKey->isValid()); 118 SkASSERT(!stretchedKey->isValid());
118 return false; 119 return false;
119 } 120 }
120 121
121 static void generate_bitmap_keys(const SkBitmap& bitmap, 122 static void make_unstretched_key(const SkBitmap& bitmap, GrContentKey* key) {
122 Stretch stretch,
123 GrContentKey* key,
124 GrContentKey* resizedKey) {
125 // Our id includes the offset, width, and height so that bitmaps created by extractSubset() 123 // Our id includes the offset, width, and height so that bitmaps created by extractSubset()
126 // are unique. 124 // are unique.
127 uint32_t genID = bitmap.getGenerationID(); 125 uint32_t genID = bitmap.getGenerationID();
128 SkIPoint origin = bitmap.pixelRefOrigin(); 126 SkIPoint origin = bitmap.pixelRefOrigin();
129 uint32_t width = SkToU16(bitmap.width()); 127 uint32_t width = SkToU16(bitmap.width());
130 uint32_t height = SkToU16(bitmap.height()); 128 uint32_t height = SkToU16(bitmap.height());
131 129
132 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); 130 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain();
133 GrContentKey::Builder builder(key, kDomain, 4); 131 GrContentKey::Builder builder(key, kDomain, 4);
134 builder[0] = genID; 132 builder[0] = genID;
135 builder[1] = origin.fX; 133 builder[1] = origin.fX;
136 builder[2] = origin.fY; 134 builder[2] = origin.fY;
137 builder[3] = width | (height << 16); 135 builder[3] = width | (height << 16);
138 builder.finish(); 136 }
139 137
138 static void make_bitmap_keys(const SkBitmap& bitmap,
139 Stretch stretch,
140 GrContentKey* key,
141 GrContentKey* stretchedKey) {
142 make_unstretched_key(bitmap, key);
140 if (kNo_Stretch != stretch) { 143 if (kNo_Stretch != stretch) {
141 make_resize_key(*key, stretch, resizedKey); 144 make_stretched_key(*key, stretch, stretchedKey);
142 } 145 }
143 } 146 }
144 147
145 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrSurfaceDesc* desc) { 148 static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrSurfaceDesc* desc) {
146 desc->fFlags = kNone_GrSurfaceFlags; 149 desc->fFlags = kNone_GrSurfaceFlags;
147 desc->fWidth = bitmap.width(); 150 desc->fWidth = bitmap.width();
148 desc->fHeight = bitmap.height(); 151 desc->fHeight = bitmap.height();
149 desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info()); 152 desc->fConfig = SkImageInfo2GrPixelConfig(bitmap.info());
150 desc->fSampleCnt = 0; 153 desc->fSampleCnt = 0;
151 } 154 }
152 155
153 namespace { 156 namespace {
154 157
155 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc ribed by key. 158 // When the SkPixelRef genID changes, invalidate a corresponding GrResource desc ribed by key.
156 class GrResourceInvalidator : public SkPixelRef::GenIDChangeListener { 159 class BitmapInvalidator : public SkPixelRef::GenIDChangeListener {
157 public: 160 public:
158 explicit GrResourceInvalidator(const GrContentKey& key) : fKey(key) {} 161 explicit BitmapInvalidator(const GrContentKey& key) : fMsg(key) {}
159 private: 162 private:
160 GrContentKey fKey; 163 GrContentKeyInvalidatedMessage fMsg;
161 164
162 void onChange() SK_OVERRIDE { 165 void onChange() SK_OVERRIDE {
163 const GrResourceInvalidatedMessage message = { fKey }; 166 SkMessageBus<GrContentKeyInvalidatedMessage>::Post(fMsg);
164 SkMessageBus<GrResourceInvalidatedMessage>::Post(message);
165 } 167 }
166 }; 168 };
167 169
168 } // namespace 170 } // namespace
169 171
170 #if 0 // TODO: plug this back up
171 static void add_genID_listener(const GrContentKey& key, SkPixelRef* pixelRef) {
172 SkASSERT(pixelRef);
173 pixelRef->addGenIDChangeListener(SkNEW_ARGS(GrResourceInvalidator, (key)));
174 }
175 #endif
176 172
177 static GrTexture* create_texture_for_bmp(GrContext* ctx, 173 static GrTexture* create_texture_for_bmp(GrContext* ctx,
178 const GrContentKey& optionalKey, 174 const GrContentKey& optionalKey,
179 GrSurfaceDesc desc, 175 GrSurfaceDesc desc,
176 SkPixelRef* pixelRefForInvalidationNoti fication,
180 const void* pixels, 177 const void* pixels,
181 size_t rowBytes) { 178 size_t rowBytes) {
182 GrTexture* result = ctx->createTexture(desc, true, pixels, rowBytes); 179 GrTexture* result = ctx->createTexture(desc, true, pixels, rowBytes);
183 if (result && optionalKey.isValid()) { 180 if (result && optionalKey.isValid()) {
181 BitmapInvalidator* listener = SkNEW_ARGS(BitmapInvalidator, (optionalKey ));
182 pixelRefForInvalidationNotification->addGenIDChangeListener(listener);
184 SkAssertResult(ctx->addResourceToCache(optionalKey, result)); 183 SkAssertResult(ctx->addResourceToCache(optionalKey, result));
185 } 184 }
186 return result; 185 return result;
187 } 186 }
188 187
189 // creates a new texture that is the input texture scaled up to the next power o f two in 188 // creates a new texture that is the input texture scaled up to the next power o f two in
190 // width or height. If optionalKey is valid it will be set on the new texture. s tretch 189 // width or height. If optionalKey is valid it will be set on the new texture. s tretch
191 // controls whether the scaling is done using nearest or bilerp filtering. 190 // controls whether the scaling is done using nearest or bilerp filtering.
192 GrTexture* resize_texture(GrTexture* inputTexture, Stretch stretch, 191 GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch,
193 const GrContentKey& optionalKey) { 192 SkPixelRef* pixelRef,
193 const GrContentKey& optionalKey) {
194 SkASSERT(kNo_Stretch != stretch); 194 SkASSERT(kNo_Stretch != stretch);
195 195
196 GrContext* context = inputTexture->getContext(); 196 GrContext* context = inputTexture->getContext();
197 SkASSERT(context); 197 SkASSERT(context);
198 198
199 // Either it's a cache miss or the original wasn't cached to begin with. 199 // Either it's a cache miss or the original wasn't cached to begin with.
200 GrSurfaceDesc rtDesc = inputTexture->desc(); 200 GrSurfaceDesc rtDesc = inputTexture->desc();
201 rtDesc.fFlags = rtDesc.fFlags | 201 rtDesc.fFlags = rtDesc.fFlags |
202 kRenderTarget_GrSurfaceFlag | 202 kRenderTarget_GrSurfaceFlag |
203 kNoStencil_GrSurfaceFlag; 203 kNoStencil_GrSurfaceFlag;
(...skipping 17 matching lines...) Expand all
221 if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { 221 if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
222 rtDesc.fConfig = kSkia8888_GrPixelConfig; 222 rtDesc.fConfig = kSkia8888_GrPixelConfig;
223 } else { 223 } else {
224 return NULL; 224 return NULL;
225 } 225 }
226 } else { 226 } else {
227 return NULL; 227 return NULL;
228 } 228 }
229 } 229 }
230 230
231 GrTexture* resized = create_texture_for_bmp(context, optionalKey, rtDesc, NU LL, 0); 231 GrTexture* stretched = create_texture_for_bmp(context, optionalKey, rtDesc, pixelRef, NULL, 0);
232 232
233 if (!resized) { 233 if (!stretched) {
234 return NULL; 234 return NULL;
235 } 235 }
236 GrPaint paint; 236 GrPaint paint;
237 237
238 // If filtering is not desired then we want to ensure all texels in the resa mpled image are 238 // If filtering is not desired then we want to ensure all texels in the resa mpled image are
239 // copies of texels from the original. 239 // copies of texels from the original.
240 GrTextureParams params(SkShader::kClamp_TileMode, 240 GrTextureParams params(SkShader::kClamp_TileMode,
241 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode : 241 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode :
242 GrTextureParams::kNone_F ilterMode); 242 GrTextureParams::kNone_F ilterMode);
243 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params); 243 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params);
244 244
245 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD esc.fHeight)); 245 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD esc.fHeight));
246 SkRect localRect = SkRect::MakeWH(1.f, 1.f); 246 SkRect localRect = SkRect::MakeWH(1.f, 1.f);
247 247
248 GrContext::AutoRenderTarget autoRT(context, resized->asRenderTarget()); 248 GrContext::AutoRenderTarget autoRT(context, stretched->asRenderTarget());
249 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); 249 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
250 context->drawNonAARectToRect(paint, SkMatrix::I(), rect, localRect); 250 context->drawNonAARectToRect(paint, SkMatrix::I(), rect, localRect);
251 251
252 return resized; 252 return stretched;
253 } 253 }
254 254
255 #ifndef SK_IGNORE_ETC1_SUPPORT 255 #ifndef SK_IGNORE_ETC1_SUPPORT
256 static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optional Key, 256 static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optional Key,
257 const SkBitmap &bm, GrSurfaceDesc desc) { 257 const SkBitmap &bm, GrSurfaceDesc desc) {
258 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); 258 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData());
259 259
260 // Is this even encoded data? 260 // Is this even encoded data?
261 if (NULL == data) { 261 if (NULL == data) {
262 return NULL; 262 return NULL;
(...skipping 28 matching lines...) Expand all
291 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { 291 if (ktx.width() != bm.width() || ktx.height() != bm.height()) {
292 return NULL; 292 return NULL;
293 } 293 }
294 294
295 bytes = ktx.pixelData(); 295 bytes = ktx.pixelData();
296 desc.fConfig = kETC1_GrPixelConfig; 296 desc.fConfig = kETC1_GrPixelConfig;
297 } else { 297 } else {
298 return NULL; 298 return NULL;
299 } 299 }
300 300
301 return create_texture_for_bmp(ctx, optionalKey, desc, bytes, 0); 301 return create_texture_for_bmp(ctx, optionalKey, desc, bm.pixelRef(), bytes, 0);
302 } 302 }
303 #endif // SK_IGNORE_ETC1_SUPPORT 303 #endif // SK_IGNORE_ETC1_SUPPORT
304 304
305 static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK ey, 305 static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK ey,
306 const SkBitmap& bm, const GrSurfaceDesc& desc ) { 306 const SkBitmap& bm, const GrSurfaceDesc& desc ) {
307 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding 307 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding
308 SkPixelRef* pixelRef = bm.pixelRef(); 308 SkPixelRef* pixelRef = bm.pixelRef();
309 if ((NULL == pixelRef) || 309 if ((NULL == pixelRef) ||
310 (pixelRef->info().width() != bm.info().width()) || 310 (pixelRef->info().width() != bm.info().width()) ||
311 (pixelRef->info().height() != bm.info().height())) { 311 (pixelRef->info().height() != bm.info().height())) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 yuvDesc.fConfig, planes[i], yuvInfo.fRo wBytes[i])) { 374 yuvDesc.fConfig, planes[i], yuvInfo.fRo wBytes[i])) {
375 return NULL; 375 return NULL;
376 } 376 }
377 } 377 }
378 378
379 GrSurfaceDesc rtDesc = desc; 379 GrSurfaceDesc rtDesc = desc;
380 rtDesc.fFlags = rtDesc.fFlags | 380 rtDesc.fFlags = rtDesc.fFlags |
381 kRenderTarget_GrSurfaceFlag | 381 kRenderTarget_GrSurfaceFlag |
382 kNoStencil_GrSurfaceFlag; 382 kNoStencil_GrSurfaceFlag;
383 383
384 GrTexture* result = create_texture_for_bmp(ctx, optionalKey, rtDesc, NULL, 0 ); 384 GrTexture* result = create_texture_for_bmp(ctx, optionalKey, rtDesc, pixelRe f, NULL, 0);
385 if (!result) { 385 if (!result) {
386 return NULL; 386 return NULL;
387 } 387 }
388 388
389 GrRenderTarget* renderTarget = result->asRenderTarget(); 389 GrRenderTarget* renderTarget = result->asRenderTarget();
390 SkASSERT(renderTarget); 390 SkASSERT(renderTarget);
391 391
392 SkAutoTUnref<GrFragmentProcessor> 392 SkAutoTUnref<GrFragmentProcessor>
393 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1 ], yuvTextures[2], 393 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1 ], yuvTextures[2],
394 yuvInfo.fColorSpace)); 394 yuvInfo.fColorSpace));
(...skipping 20 matching lines...) Expand all
415 415
416 if (kIndex_8_SkColorType == bitmap->colorType()) { 416 if (kIndex_8_SkColorType == bitmap->colorType()) {
417 if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) { 417 if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) {
418 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 418 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
419 bitmap->width(), bitma p->height()); 419 bitmap->width(), bitma p->height());
420 SkAutoMalloc storage(imageSize); 420 SkAutoMalloc storage(imageSize);
421 build_index8_data(storage.get(), origBitmap); 421 build_index8_data(storage.get(), origBitmap);
422 422
423 // our compressed data will be trimmed, so pass width() for its 423 // our compressed data will be trimmed, so pass width() for its
424 // "rowBytes", since they are the same now. 424 // "rowBytes", since they are the same now.
425 return create_texture_for_bmp(ctx, optionalKey, desc, storage.get(), bitmap->width()); 425 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pix elRef(),
426 storage.get(), bitmap->width());
426 } else { 427 } else {
427 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); 428 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType);
428 // now bitmap points to our temp, which has been promoted to 32bits 429 // now bitmap points to our temp, which has been promoted to 32bits
429 bitmap = &tmpBitmap; 430 bitmap = &tmpBitmap;
430 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); 431 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info());
431 } 432 }
432 } 433 }
433 434
434 // Is this an ETC1 encoded texture? 435 // Is this an ETC1 encoded texture?
435 #ifndef SK_IGNORE_ETC1_SUPPORT 436 #ifndef SK_IGNORE_ETC1_SUPPORT
(...skipping 15 matching lines...) Expand all
451 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); 452 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc);
452 if (texture) { 453 if (texture) {
453 return texture; 454 return texture;
454 } 455 }
455 456
456 SkAutoLockPixels alp(*bitmap); 457 SkAutoLockPixels alp(*bitmap);
457 if (!bitmap->readyToDraw()) { 458 if (!bitmap->readyToDraw()) {
458 return NULL; 459 return NULL;
459 } 460 }
460 461
461 return create_texture_for_bmp(ctx, optionalKey, desc, bitmap->getPixels(), b itmap->rowBytes()); 462 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pixelRef(),
463 bitmap->getPixels(), bitmap->rowBytes());
462 } 464 }
463 465
464 static GrTexture* create_bitmap_texture(GrContext* ctx, 466 static GrTexture* create_bitmap_texture(GrContext* ctx,
465 const SkBitmap& bmp, 467 const SkBitmap& bmp,
466 Stretch stretch, 468 Stretch stretch,
467 const GrContentKey& unstretchedKey, 469 const GrContentKey& unstretchedKey,
468 const GrContentKey& stretchedKey) { 470 const GrContentKey& stretchedKey) {
469 if (kNo_Stretch != stretch) { 471 if (kNo_Stretch != stretch) {
470 SkAutoTUnref<GrTexture> unstretched; 472 SkAutoTUnref<GrTexture> unstretched;
471 // Check if we have the unstretched version in the cache, if not create it. 473 // Check if we have the unstretched version in the cache, if not create it.
472 if (unstretchedKey.isValid()) { 474 if (unstretchedKey.isValid()) {
473 unstretched.reset(ctx->findAndRefCachedTexture(unstretchedKey)); 475 unstretched.reset(ctx->findAndRefCachedTexture(unstretchedKey));
474 } 476 }
475 if (!unstretched) { 477 if (!unstretched) {
476 unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstre tchedKey)); 478 unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstre tchedKey));
477 if (!unstretched) { 479 if (!unstretched) {
478 return NULL; 480 return NULL;
479 } 481 }
480 } 482 }
481 GrTexture* resized = resize_texture(unstretched, stretch, stretchedKey); 483 GrTexture* stretched = stretch_texture_to_next_pot(unstretched, stretch, bmp.pixelRef(),
482 return resized; 484 stretchedKey);
485 return stretched;
483 } 486 }
484 487
485 return create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey); 488 return create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey);
486 489
487 } 490 }
488 491
489 bool GrIsBitmapInCache(const GrContext* ctx, 492 bool GrIsBitmapInCache(const GrContext* ctx,
490 const SkBitmap& bitmap, 493 const SkBitmap& bitmap,
491 const GrTextureParams* params) { 494 const GrTextureParams* params) {
492 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams); 495 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
493 496
494 // Handle the case where the bitmap is explicitly texture backed. 497 // Handle the case where the bitmap is explicitly texture backed.
495 GrTexture* texture = bitmap.getTexture(); 498 GrTexture* texture = bitmap.getTexture();
496 if (texture) { 499 if (texture) {
497 if (kNo_Stretch == stretch) { 500 if (kNo_Stretch == stretch) {
498 return true; 501 return true;
499 } 502 }
500 // No keys for volatile bitmaps. 503 // No keys for volatile bitmaps.
501 if (bitmap.isVolatile()) { 504 if (bitmap.isVolatile()) {
502 return false; 505 return false;
503 } 506 }
504 const GrContentKey& key = texture->getContentKey(); 507 const GrContentKey& key = texture->getContentKey();
505 if (!key.isValid()) { 508 if (!key.isValid()) {
506 return false; 509 return false;
507 } 510 }
508 GrContentKey resizedKey; 511 GrContentKey stretchedKey;
509 make_resize_key(key, stretch, &resizedKey); 512 make_stretched_key(key, stretch, &stretchedKey);
510 return ctx->isResourceInCache(resizedKey); 513 return ctx->isResourceInCache(stretchedKey);
511 } 514 }
512 515
513 // We don't cache volatile bitmaps 516 // We don't cache volatile bitmaps
514 if (bitmap.isVolatile()) { 517 if (bitmap.isVolatile()) {
515 return false; 518 return false;
516 } 519 }
517 520
518 GrContentKey key, resizedKey; 521 GrContentKey key, stretchedKey;
519 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey); 522 make_bitmap_keys(bitmap, stretch, &key, &stretchedKey);
520 return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : resizedKey); 523 return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : stretchedKey) ;
521 } 524 }
522 525
523 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, 526 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
524 const SkBitmap& bitmap, 527 const SkBitmap& bitmap,
525 const GrTextureParams* params) { 528 const GrTextureParams* params) {
526 529
527 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams); 530 Stretch stretch = get_stretch_type(ctx, bitmap.width(), bitmap.height(), par ams);
528 531
529 GrTexture* result = bitmap.getTexture(); 532 GrTexture* result = bitmap.getTexture();
530 if (result) { 533 if (result) {
531 if (kNo_Stretch == stretch) { 534 if (kNo_Stretch == stretch) {
532 return SkRef(result); 535 return SkRef(result);
533 } 536 }
534 GrContentKey resizedKey; 537 GrContentKey stretchedKey;
535 // Don't create a key for the resized version if the bmp is volatile. 538 // Don't create a key for the resized version if the bmp is volatile.
536 if (!bitmap.isVolatile()) { 539 if (!bitmap.isVolatile()) {
537 const GrContentKey& key = result->getContentKey(); 540 const GrContentKey& key = result->getContentKey();
538 if (key.isValid()) { 541 if (key.isValid()) {
539 make_resize_key(key, stretch, &resizedKey); 542 make_stretched_key(key, stretch, &stretchedKey);
540 GrTexture* stretched = ctx->findAndRefCachedTexture(resizedKey); 543 GrTexture* stretched = ctx->findAndRefCachedTexture(stretchedKey );
541 if (stretched) { 544 if (stretched) {
542 return stretched; 545 return stretched;
543 } 546 }
544 } 547 }
545 } 548 }
546 return resize_texture(result, stretch, resizedKey); 549 return stretch_texture_to_next_pot(result, stretch, bitmap.pixelRef(), s tretchedKey);
547 } 550 }
548 551
549 GrContentKey key, resizedKey; 552 GrContentKey key, resizedKey;
550 553
551 if (!bitmap.isVolatile()) { 554 if (!bitmap.isVolatile()) {
552 // If the bitmap isn't changing try to find a cached copy first. 555 // If the bitmap isn't changing try to find a cached copy first.
553 generate_bitmap_keys(bitmap, stretch, &key, &resizedKey); 556 make_bitmap_keys(bitmap, stretch, &key, &resizedKey);
554 557
555 result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey : key); 558 result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey : key);
556 if (result) { 559 if (result) {
557 return result; 560 return result;
558 } 561 }
559 } 562 }
560 563
561 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); 564 result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey);
562 if (result) { 565 if (result) {
563 return result; 566 return result;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { 723 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) {
721 grPaint->addColorProcessor(fp)->unref(); 724 grPaint->addColorProcessor(fp)->unref();
722 constantColor = false; 725 constantColor = false;
723 } 726 }
724 } 727 }
725 728
726 // The grcolor is automatically set when calling asFragmentProcessor. 729 // The grcolor is automatically set when calling asFragmentProcessor.
727 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 730 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
728 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); 731 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint );
729 } 732 }
OLDNEW
« no previous file with comments | « src/gpu/GrResourceCache2.cpp ('k') | tests/MessageBusTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698