| OLD | NEW |
| 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 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "GrLayerCache.h" | 23 #include "GrLayerCache.h" |
| 24 #include "GrOvalRenderer.h" | 24 #include "GrOvalRenderer.h" |
| 25 #include "GrPathRenderer.h" | 25 #include "GrPathRenderer.h" |
| 26 #include "GrPathUtils.h" | 26 #include "GrPathUtils.h" |
| 27 #include "GrResourceCache.h" | 27 #include "GrResourceCache.h" |
| 28 #include "GrResourceCache2.h" | 28 #include "GrResourceCache2.h" |
| 29 #include "GrSoftwarePathRenderer.h" | 29 #include "GrSoftwarePathRenderer.h" |
| 30 #include "GrStencilBuffer.h" | 30 #include "GrStencilBuffer.h" |
| 31 #include "GrStencilAndCoverTextContext.h" | 31 #include "GrStencilAndCoverTextContext.h" |
| 32 #include "GrStrokeInfo.h" | 32 #include "GrStrokeInfo.h" |
| 33 #include "GrSurfacePriv.h" | |
| 34 #include "GrTextStrike.h" | 33 #include "GrTextStrike.h" |
| 35 #include "GrTexturePriv.h" | |
| 36 #include "GrTraceMarker.h" | 34 #include "GrTraceMarker.h" |
| 37 #include "GrTracing.h" | 35 #include "GrTracing.h" |
| 38 #include "SkDashPathPriv.h" | 36 #include "SkDashPathPriv.h" |
| 39 #include "SkGr.h" | 37 #include "SkGr.h" |
| 40 #include "SkRTConf.h" | 38 #include "SkRTConf.h" |
| 41 #include "SkRRect.h" | 39 #include "SkRRect.h" |
| 42 #include "SkStrokeRec.h" | 40 #include "SkStrokeRec.h" |
| 43 #include "SkTLazy.h" | 41 #include "SkTLazy.h" |
| 44 #include "SkTLS.h" | 42 #include "SkTLS.h" |
| 45 #include "SkTraceEvent.h" | 43 #include "SkTraceEvent.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; | 61 static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMI
T * 1024 * 1024; |
| 64 | 62 |
| 65 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; | 63 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
| 66 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 64 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 67 | 65 |
| 68 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; | 66 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 69 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; | 67 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
| 70 | 68 |
| 71 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 69 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 72 | 70 |
| 73 GrTexture* GrAutoScratchTexture::detach() { | |
| 74 if (NULL == fTexture) { | |
| 75 return NULL; | |
| 76 } | |
| 77 GrTexture* texture = fTexture; | |
| 78 fTexture = NULL; | |
| 79 | |
| 80 // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, which
we give up now. | |
| 81 // The cache also has a ref which we are lending to the caller of detach().
When the caller | |
| 82 // lets go of the ref and the ref count goes to 0 internal_dispose will see
this flag is | |
| 83 // set and re-ref the texture, thereby restoring the cache's ref. | |
| 84 SkASSERT(!texture->unique()); | |
| 85 texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnToCache_Fl
agBit); | |
| 86 texture->unref(); | |
| 87 SkASSERT(texture->getCacheEntry()); | |
| 88 | |
| 89 return texture; | |
| 90 } | |
| 91 | |
| 92 // Glorified typedef to avoid including GrDrawState.h in GrContext.h | 71 // Glorified typedef to avoid including GrDrawState.h in GrContext.h |
| 93 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; | 72 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; |
| 94 | 73 |
| 95 class GrContext::AutoCheckFlush { | 74 class GrContext::AutoCheckFlush { |
| 96 public: | 75 public: |
| 97 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} | 76 AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context);
} |
| 98 | 77 |
| 99 ~AutoCheckFlush() { | 78 ~AutoCheckFlush() { |
| 100 if (fContext->fFlushToReduceCacheSize) { | 79 if (fContext->fFlushToReduceCacheSize) { |
| 101 fContext->flush(); | 80 fContext->flush(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 255 } |
| 277 return SkNEW_ARGS(GrDistanceFieldTextContext, (this, leakyProperties, | 256 return SkNEW_ARGS(GrDistanceFieldTextContext, (this, leakyProperties, |
| 278 enableDistanceFieldFonts)); | 257 enableDistanceFieldFonts)); |
| 279 } | 258 } |
| 280 | 259 |
| 281 //////////////////////////////////////////////////////////////////////////////// | 260 //////////////////////////////////////////////////////////////////////////////// |
| 282 | 261 |
| 283 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, | 262 GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, |
| 284 const GrCacheID& cacheID, | 263 const GrCacheID& cacheID, |
| 285 const GrTextureParams* params) { | 264 const GrTextureParams* params) { |
| 286 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 265 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); |
| 287 GrGpuResource* resource = fResourceCache->find(resourceKey); | 266 GrGpuResource* resource = fResourceCache->find(resourceKey); |
| 288 SkSafeRef(resource); | 267 SkSafeRef(resource); |
| 289 return static_cast<GrTexture*>(resource); | 268 return static_cast<GrTexture*>(resource); |
| 290 } | 269 } |
| 291 | 270 |
| 292 bool GrContext::isTextureInCache(const GrTextureDesc& desc, | 271 bool GrContext::isTextureInCache(const GrTextureDesc& desc, |
| 293 const GrCacheID& cacheID, | 272 const GrCacheID& cacheID, |
| 294 const GrTextureParams* params) const { | 273 const GrTextureParams* params) const { |
| 295 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 274 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); |
| 296 return fResourceCache->hasKey(resourceKey); | 275 return fResourceCache->hasKey(resourceKey); |
| 297 } | 276 } |
| 298 | 277 |
| 299 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { | 278 void GrContext::addStencilBuffer(GrStencilBuffer* sb) { |
| 300 ASSERT_OWNED_RESOURCE(sb); | 279 ASSERT_OWNED_RESOURCE(sb); |
| 301 | 280 |
| 302 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), | 281 GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), |
| 303 sb->height(), | 282 sb->height(), |
| 304 sb->numSamples()); | 283 sb->numSamples()); |
| 305 fResourceCache->addResource(resourceKey, sb); | 284 fResourceCache->addResource(resourceKey, sb); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 403 |
| 425 return texture; | 404 return texture; |
| 426 } | 405 } |
| 427 | 406 |
| 428 GrTexture* GrContext::createTexture(const GrTextureParams* params, | 407 GrTexture* GrContext::createTexture(const GrTextureParams* params, |
| 429 const GrTextureDesc& desc, | 408 const GrTextureDesc& desc, |
| 430 const GrCacheID& cacheID, | 409 const GrCacheID& cacheID, |
| 431 const void* srcData, | 410 const void* srcData, |
| 432 size_t rowBytes, | 411 size_t rowBytes, |
| 433 GrResourceKey* cacheKey) { | 412 GrResourceKey* cacheKey) { |
| 434 GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, ca
cheID); | 413 GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, ca
cheID); |
| 435 | 414 |
| 436 GrTexture* texture; | 415 GrTexture* texture; |
| 437 if (GrTexturePriv::NeedsResizing(resourceKey)) { | 416 if (GrTextureImpl::NeedsResizing(resourceKey)) { |
| 438 // We do not know how to resize compressed textures. | 417 // We do not know how to resize compressed textures. |
| 439 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); | 418 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 440 | 419 |
| 441 texture = this->createResizedTexture(desc, cacheID, | 420 texture = this->createResizedTexture(desc, cacheID, |
| 442 srcData, rowBytes, | 421 srcData, rowBytes, |
| 443 GrTexturePriv::NeedsBilerp(resource
Key)); | 422 GrTextureImpl::NeedsBilerp(resource
Key)); |
| 444 } else { | 423 } else { |
| 445 texture = fGpu->createTexture(desc, srcData, rowBytes); | 424 texture = fGpu->createTexture(desc, srcData, rowBytes); |
| 446 } | 425 } |
| 447 | 426 |
| 448 if (texture) { | 427 if (texture) { |
| 449 // Adding a resource could put us overbudget. Try to free up the | 428 // Adding a resource could put us overbudget. Try to free up the |
| 450 // necessary space before adding it. | 429 // necessary space before adding it. |
| 451 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); | 430 fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 452 fResourceCache->addResource(resourceKey, texture); | 431 fResourceCache->addResource(resourceKey, texture); |
| 453 | 432 |
| 454 if (cacheKey) { | 433 if (cacheKey) { |
| 455 *cacheKey = resourceKey; | 434 *cacheKey = resourceKey; |
| 456 } | 435 } |
| 457 } | 436 } |
| 458 | 437 |
| 459 return texture; | 438 return texture; |
| 460 } | 439 } |
| 461 | 440 |
| 462 static GrTexture* create_scratch_texture(GrGpu* gpu, | 441 static GrTexture* create_scratch_texture(GrGpu* gpu, |
| 463 GrResourceCache* resourceCache, | 442 GrResourceCache* resourceCache, |
| 464 const GrTextureDesc& desc) { | 443 const GrTextureDesc& desc) { |
| 465 GrTexture* texture = gpu->createTexture(desc, NULL, 0); | 444 GrTexture* texture = gpu->createTexture(desc, NULL, 0); |
| 466 if (texture) { | 445 if (texture) { |
| 467 GrResourceKey key = GrTexturePriv::ComputeScratchKey(texture->desc()); | 446 GrResourceKey key = GrTextureImpl::ComputeScratchKey(texture->desc()); |
| 468 // Adding a resource could put us overbudget. Try to free up the | 447 // Adding a resource could put us overbudget. Try to free up the |
| 469 // necessary space before adding it. | 448 // necessary space before adding it. |
| 470 resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); | 449 resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 471 // Make the resource exclusive so future 'find' calls don't return it | 450 // Make the resource exclusive so future 'find' calls don't return it |
| 472 resourceCache->addResource(key, texture, GrResourceCache::kHide_Ownershi
pFlag); | 451 resourceCache->addResource(key, texture, GrResourceCache::kHide_Ownershi
pFlag); |
| 473 } | 452 } |
| 474 return texture; | 453 return texture; |
| 475 } | 454 } |
| 476 | 455 |
| 477 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
tchTexMatch match) { | 456 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
tchTexMatch match) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 497 static const int MIN_SIZE = 16; | 476 static const int MIN_SIZE = 16; |
| 498 desc.fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc.fWidth)); | 477 desc.fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc.fWidth)); |
| 499 desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight)); | 478 desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight)); |
| 500 } | 479 } |
| 501 | 480 |
| 502 GrGpuResource* resource = NULL; | 481 GrGpuResource* resource = NULL; |
| 503 int origWidth = desc.fWidth; | 482 int origWidth = desc.fWidth; |
| 504 int origHeight = desc.fHeight; | 483 int origHeight = desc.fHeight; |
| 505 | 484 |
| 506 do { | 485 do { |
| 507 GrResourceKey key = GrTexturePriv::ComputeScratchKey(desc); | 486 GrResourceKey key = GrTextureImpl::ComputeScratchKey(desc); |
| 508 // Ensure we have exclusive access to the texture so future 'find' calls
don't return it | 487 // Ensure we have exclusive access to the texture so future 'find' calls
don't return it |
| 509 resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFla
g); | 488 resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFla
g); |
| 510 if (resource) { | 489 if (resource) { |
| 511 resource->ref(); | 490 resource->ref(); |
| 512 break; | 491 break; |
| 513 } | 492 } |
| 514 if (kExact_ScratchTexMatch == match) { | 493 if (kExact_ScratchTexMatch == match) { |
| 515 break; | 494 break; |
| 516 } | 495 } |
| 517 // We had a cache miss and we are in approx mode, relax the fit of the f
lags. | 496 // We had a cache miss and we are in approx mode, relax the fit of the f
lags. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 // reusing scratch textures (in this code path) it would just be | 571 // reusing scratch textures (in this code path) it would just be |
| 593 // wasting time sitting in the cache. | 572 // wasting time sitting in the cache. |
| 594 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 573 fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 595 fResourceCache->deleteResource(texture->getCacheEntry()); | 574 fResourceCache->deleteResource(texture->getCacheEntry()); |
| 596 } else { | 575 } else { |
| 597 // In this case (there is still a non-cache ref) but we don't really | 576 // In this case (there is still a non-cache ref) but we don't really |
| 598 // want to readd it to the cache (since it will never be reused). | 577 // want to readd it to the cache (since it will never be reused). |
| 599 // Instead, give up the cache's ref and leave the decision up to | 578 // Instead, give up the cache's ref and leave the decision up to |
| 600 // addExistingTextureToCache once its ref count reaches 0. For | 579 // addExistingTextureToCache once its ref count reaches 0. For |
| 601 // this to work we need to leave it in the exclusive list. | 580 // this to work we need to leave it in the exclusive list. |
| 602 texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnTo
Cache_FlagBit); | 581 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa
che_FlagBit); |
| 603 // Give up the cache's ref to the texture | 582 // Give up the cache's ref to the texture |
| 604 texture->unref(); | 583 texture->unref(); |
| 605 } | 584 } |
| 606 } | 585 } |
| 607 } | 586 } |
| 608 | 587 |
| 609 void GrContext::purgeCache() { | 588 void GrContext::purgeCache() { |
| 610 if (fResourceCache) { | 589 if (fResourceCache) { |
| 611 fResourceCache->purgeAsNeeded(); | 590 fResourceCache->purgeAsNeeded(); |
| 612 } | 591 } |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture
, config)) { | 1340 if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture
, config)) { |
| 1362 if (texture->asRenderTarget()) { | 1341 if (texture->asRenderTarget()) { |
| 1363 return this->writeRenderTargetPixels(texture->asRenderTarget(), | 1342 return this->writeRenderTargetPixels(texture->asRenderTarget(), |
| 1364 left, top, width, height, | 1343 left, top, width, height, |
| 1365 config, buffer, rowBytes, flags
); | 1344 config, buffer, rowBytes, flags
); |
| 1366 } else { | 1345 } else { |
| 1367 return false; | 1346 return false; |
| 1368 } | 1347 } |
| 1369 } | 1348 } |
| 1370 | 1349 |
| 1371 if (!(kDontFlush_PixelOpsFlag & flags) && texture->surfacePriv().hasPendingI
O()) { | 1350 if (!(kDontFlush_PixelOpsFlag & flags) && texture->hasPendingIO()) { |
| 1372 this->flush(); | 1351 this->flush(); |
| 1373 } | 1352 } |
| 1374 | 1353 |
| 1375 return fGpu->writeTexturePixels(texture, left, top, width, height, | 1354 return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1376 config, buffer, rowBytes); | 1355 config, buffer, rowBytes); |
| 1377 } | 1356 } |
| 1378 | 1357 |
| 1379 bool GrContext::readTexturePixels(GrTexture* texture, | 1358 bool GrContext::readTexturePixels(GrTexture* texture, |
| 1380 int left, int top, int width, int height, | 1359 int left, int top, int width, int height, |
| 1381 GrPixelConfig config, void* buffer, size_t row
Bytes, | 1360 GrPixelConfig config, void* buffer, size_t row
Bytes, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 uint32_t flags) { | 1411 uint32_t flags) { |
| 1433 ASSERT_OWNED_RESOURCE(target); | 1412 ASSERT_OWNED_RESOURCE(target); |
| 1434 | 1413 |
| 1435 if (NULL == target) { | 1414 if (NULL == target) { |
| 1436 target = fRenderTarget.get(); | 1415 target = fRenderTarget.get(); |
| 1437 if (NULL == target) { | 1416 if (NULL == target) { |
| 1438 return false; | 1417 return false; |
| 1439 } | 1418 } |
| 1440 } | 1419 } |
| 1441 | 1420 |
| 1442 if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWr
ite()) { | 1421 if (!(kDontFlush_PixelOpsFlag & flags) && target->hasPendingWrite()) { |
| 1443 this->flush(); | 1422 this->flush(); |
| 1444 } | 1423 } |
| 1445 | 1424 |
| 1446 // Determine which conversions have to be applied: flipY, swapRAnd, and/or u
npremul. | 1425 // Determine which conversions have to be applied: flipY, swapRAnd, and/or u
npremul. |
| 1447 | 1426 |
| 1448 // If fGpu->readPixels would incur a y-flip cost then we will read the pixel
s upside down. We'll | 1427 // If fGpu->readPixels would incur a y-flip cost then we will read the pixel
s upside down. We'll |
| 1449 // either do the flipY by drawing into a scratch with a matrix or on the cpu
after the read. | 1428 // either do the flipY by drawing into a scratch with a matrix or on the cpu
after the read. |
| 1450 bool flipY = fGpu->readPixelsWillPayForYFlip(target, left, top, | 1429 bool flipY = fGpu->readPixelsWillPayForYFlip(target, left, top, |
| 1451 width, height, dstConfig, | 1430 width, height, dstConfig, |
| 1452 rowBytes); | 1431 rowBytes); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 fResourceCache->printStats(); | 1933 fResourceCache->printStats(); |
| 1955 } | 1934 } |
| 1956 #endif | 1935 #endif |
| 1957 | 1936 |
| 1958 #if GR_GPU_STATS | 1937 #if GR_GPU_STATS |
| 1959 const GrContext::GPUStats* GrContext::gpuStats() const { | 1938 const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1960 return fGpu->gpuStats(); | 1939 return fGpu->gpuStats(); |
| 1961 } | 1940 } |
| 1962 #endif | 1941 #endif |
| 1963 | 1942 |
| OLD | NEW |