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