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

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

Issue 846303002: Make uncached textures uncached from the get go. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment Created 5 years, 11 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/GrAtlas.cpp ('k') | src/gpu/GrDistanceFieldTextContext.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 10
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 } 292 }
293 293
294 GrSurfaceDesc rtDesc = desc; 294 GrSurfaceDesc rtDesc = desc;
295 rtDesc.fFlags = rtDesc.fFlags | 295 rtDesc.fFlags = rtDesc.fFlags |
296 kRenderTarget_GrSurfaceFlag | 296 kRenderTarget_GrSurfaceFlag |
297 kNoStencil_GrSurfaceFlag; 297 kNoStencil_GrSurfaceFlag;
298 rtDesc.fWidth = GrNextPow2(desc.fWidth); 298 rtDesc.fWidth = GrNextPow2(desc.fWidth);
299 rtDesc.fHeight = GrNextPow2(desc.fHeight); 299 rtDesc.fHeight = GrNextPow2(desc.fHeight);
300 300
301 GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); 301 GrTexture* texture = fGpu->createTexture(rtDesc, true, NULL, 0);
302 302
303 if (texture) { 303 if (texture) {
304 GrDrawState drawState; 304 GrDrawState drawState;
305 drawState.setRenderTarget(texture->asRenderTarget()); 305 drawState.setRenderTarget(texture->asRenderTarget());
306 306
307 // if filtering is not desired then we want to ensure all 307 // if filtering is not desired then we want to ensure all
308 // texels in the resampled image are copies of texels from 308 // texels in the resampled image are copies of texels from
309 // the original. 309 // the original.
310 GrTextureParams params(SkShader::kClamp_TileMode, 310 GrTextureParams params(SkShader::kClamp_TileMode,
311 filter ? GrTextureParams::kBilerp_FilterMode : 311 filter ? GrTextureParams::kBilerp_FilterMode :
(...skipping 28 matching lines...) Expand all
340 // We shouldn't be resizing a compressed texture. 340 // We shouldn't be resizing a compressed texture.
341 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); 341 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
342 342
343 size_t bpp = GrBytesPerPixel(desc.fConfig); 343 size_t bpp = GrBytesPerPixel(desc.fConfig);
344 GrAutoMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHe ight); 344 GrAutoMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHe ight);
345 stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight, 345 stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight,
346 srcData, desc.fWidth, desc.fHeight, bpp); 346 srcData, desc.fWidth, desc.fHeight, bpp);
347 347
348 size_t stretchedRowBytes = rtDesc.fWidth * bpp; 348 size_t stretchedRowBytes = rtDesc.fWidth * bpp;
349 349
350 texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRo wBytes); 350 texture = fGpu->createTexture(rtDesc, true, stretchedPixels.get(), stret chedRowBytes);
351 SkASSERT(texture); 351 SkASSERT(texture);
352 } 352 }
353 353
354 return texture; 354 return texture;
355 } 355 }
356 356
357 GrTexture* GrContext::createTexture(const GrTextureParams* params, 357 GrTexture* GrContext::createTexture(const GrTextureParams* params,
358 const GrSurfaceDesc& desc, 358 const GrSurfaceDesc& desc,
359 const GrCacheID& cacheID, 359 const GrCacheID& cacheID,
360 const void* srcData, 360 const void* srcData,
361 size_t rowBytes, 361 size_t rowBytes,
362 GrResourceKey* cacheKey) { 362 GrResourceKey* cacheKey) {
363 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID); 363 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca cheID);
364 364
365 GrTexture* texture; 365 GrTexture* texture;
366 if (GrTexturePriv::NeedsResizing(resourceKey)) { 366 if (GrTexturePriv::NeedsResizing(resourceKey)) {
367 // We do not know how to resize compressed textures. 367 // We do not know how to resize compressed textures.
368 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); 368 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
369 369
370 texture = this->createResizedTexture(desc, cacheID, 370 texture = this->createResizedTexture(desc, cacheID,
371 srcData, rowBytes, 371 srcData, rowBytes,
372 GrTexturePriv::NeedsBilerp(resource Key)); 372 GrTexturePriv::NeedsBilerp(resource Key));
373 } else { 373 } else {
374 texture = fGpu->createTexture(desc, srcData, rowBytes); 374 texture = fGpu->createTexture(desc, true, srcData, rowBytes);
375 } 375 }
376 376
377 if (texture) { 377 if (texture) {
378 if (texture->cacheAccess().setContentKey(resourceKey)) { 378 if (texture->cacheAccess().setContentKey(resourceKey)) {
379 if (cacheKey) { 379 if (cacheKey) {
380 *cacheKey = resourceKey; 380 *cacheKey = resourceKey;
381 } 381 }
382 } else { 382 } else {
383 texture->unref(); 383 texture->unref();
384 texture = NULL; 384 texture = NULL;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag; 438 desc.writable()->fFlags = desc->fFlags & ~kNoStencil_GrSurfaceFl ag;
439 } else { 439 } else {
440 break; 440 break;
441 } 441 }
442 442
443 } while (true); 443 } while (true);
444 444
445 desc.writable()->fFlags = origFlags; 445 desc.writable()->fFlags = origFlags;
446 } 446 }
447 447
448 GrTexture* texture = fGpu->createTexture(*desc, NULL, 0); 448 GrTexture* texture = fGpu->createTexture(*desc, true, NULL, 0);
449 #ifdef SK_DEBUG 449 #ifdef SK_DEBUG
450 GrScratchKey key; 450 GrScratchKey key;
451 GrTexturePriv::ComputeScratchKey(*desc, &key); 451 GrTexturePriv::ComputeScratchKey(*desc, &key);
452 SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() == key); 452 SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() == key);
453 #endif 453 #endif
454 return texture; 454 return texture;
455 } 455 }
456 456
457 void GrContext::OverBudgetCB(void* data) { 457 void GrContext::OverBudgetCB(void* data) {
458 SkASSERT(data); 458 SkASSERT(data);
459 459
460 GrContext* context = reinterpret_cast<GrContext*>(data); 460 GrContext* context = reinterpret_cast<GrContext*>(data);
461 461
462 // Flush the InOrderDrawBuffer to possibly free up some textures 462 // Flush the InOrderDrawBuffer to possibly free up some textures
463 context->fFlushToReduceCacheSize = true; 463 context->fFlushToReduceCacheSize = true;
464 } 464 }
465 465
466 466
467 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& descIn, 467 GrTexture* GrContext::createUncachedTexture(const GrSurfaceDesc& desc,
468 void* srcData, 468 void* srcData,
469 size_t rowBytes) { 469 size_t rowBytes) {
470 GrSurfaceDesc descCopy = descIn; 470 return fGpu->createTexture(desc, false, srcData, rowBytes);
471 GrTexture* texture = fGpu->createTexture(descCopy, srcData, rowBytes);
472 if (texture) {
473 // TODO: It'd be nice to be able to do this before creation so we don't boot something
474 // out of the cache. We could temporarily boost the cache budget.
475 texture->cacheAccess().setBudgeted(false);
476 }
477 return texture;
478 } 471 }
479 472
480 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const { 473 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes ) const {
481 if (maxTextures) { 474 if (maxTextures) {
482 *maxTextures = fResourceCache2->getMaxResourceCount(); 475 *maxTextures = fResourceCache2->getMaxResourceCount();
483 } 476 }
484 if (maxTextureBytes) { 477 if (maxTextureBytes) {
485 *maxTextureBytes = fResourceCache2->getMaxResourceBytes(); 478 *maxTextureBytes = fResourceCache2->getMaxResourceBytes();
486 } 479 }
487 } 480 }
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 fResourceCache2->printStats(); 1744 fResourceCache2->printStats();
1752 } 1745 }
1753 #endif 1746 #endif
1754 1747
1755 #if GR_GPU_STATS 1748 #if GR_GPU_STATS
1756 const GrContext::GPUStats* GrContext::gpuStats() const { 1749 const GrContext::GPUStats* GrContext::gpuStats() const {
1757 return fGpu->gpuStats(); 1750 return fGpu->gpuStats();
1758 } 1751 }
1759 #endif 1752 #endif
1760 1753
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.cpp ('k') | src/gpu/GrDistanceFieldTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698