| 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| 11 #include "GrDrawingManager.h" | 11 #include "GrDrawingManager.h" |
| 12 #include "GrDrawContext.h" | 12 #include "GrDrawContext.h" |
| 13 #include "GrLayerCache.h" | 13 #include "GrLayerCache.h" |
| 14 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
| 15 #include "GrResourceProvider.h" | 15 #include "GrResourceProvider.h" |
| 16 #include "GrSoftwarePathRenderer.h" | 16 #include "GrSoftwarePathRenderer.h" |
| 17 #include "GrSurfacePriv.h" | 17 #include "GrSurfacePriv.h" |
| 18 | 18 |
| 19 #include "SkConfig8888.h" | 19 #include "SkConfig8888.h" |
| 20 #include "SkGrPriv.h" | 20 #include "SkGrPriv.h" |
| 21 | 21 |
| 22 #include "effects/GrConfigConversionEffect.h" | 22 #include "effects/GrConfigConversionEffect.h" |
| 23 #include "text/GrTextBlobCache.h" | 23 #include "text/GrTextBlobCache.h" |
| 24 | 24 |
| 25 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 25 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 26 #define ASSERT_SINGLE_OWNER \ |
| 27 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) |
| 26 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } | 28 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
| 27 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fal
se; } | 29 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fal
se; } |
| 28 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return null
ptr; } | 30 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return null
ptr; } |
| 29 | 31 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 31 | 33 |
| 32 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 34 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 33 GrContextOptions defaultOptions; | 35 GrContextOptions defaultOptions; |
| 34 return Create(backend, backendContext, defaultOptions); | 36 return Create(backend, backendContext, defaultOptions); |
| 35 } | 37 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 fGpu = nullptr; | 61 fGpu = nullptr; |
| 60 fCaps = nullptr; | 62 fCaps = nullptr; |
| 61 fResourceCache = nullptr; | 63 fResourceCache = nullptr; |
| 62 fResourceProvider = nullptr; | 64 fResourceProvider = nullptr; |
| 63 fBatchFontCache = nullptr; | 65 fBatchFontCache = nullptr; |
| 64 fFlushToReduceCacheSize = false; | 66 fFlushToReduceCacheSize = false; |
| 65 } | 67 } |
| 66 | 68 |
| 67 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, | 69 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 68 const GrContextOptions& options) { | 70 const GrContextOptions& options) { |
| 71 ASSERT_SINGLE_OWNER |
| 69 SkASSERT(!fGpu); | 72 SkASSERT(!fGpu); |
| 70 | 73 |
| 71 fGpu = GrGpu::Create(backend, backendContext, options, this); | 74 fGpu = GrGpu::Create(backend, backendContext, options, this); |
| 72 if (!fGpu) { | 75 if (!fGpu) { |
| 73 return false; | 76 return false; |
| 74 } | 77 } |
| 75 this->initCommon(options); | 78 this->initCommon(options); |
| 76 return true; | 79 return true; |
| 77 } | 80 } |
| 78 | 81 |
| 79 void GrContext::initCommon(const GrContextOptions& options) { | 82 void GrContext::initCommon(const GrContextOptions& options) { |
| 83 ASSERT_SINGLE_OWNER |
| 84 |
| 80 fCaps = SkRef(fGpu->caps()); | 85 fCaps = SkRef(fGpu->caps()); |
| 81 fResourceCache = new GrResourceCache(fCaps); | 86 fResourceCache = new GrResourceCache(fCaps); |
| 82 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); | 87 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
| 83 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache); | 88 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache); |
| 84 | 89 |
| 85 fLayerCache.reset(new GrLayerCache(this)); | 90 fLayerCache.reset(new GrLayerCache(this)); |
| 86 | 91 |
| 87 fDidTestPMConversions = false; | 92 fDidTestPMConversions = false; |
| 88 | 93 |
| 89 GrDrawTarget::Options dtOptions; | 94 GrDrawTarget::Options dtOptions; |
| 90 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; | 95 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; |
| 91 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; | 96 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; |
| 92 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; | 97 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; |
| 93 fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); | 98 fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); |
| 94 | 99 |
| 95 // GrBatchFontCache will eventually replace GrFontCache | 100 // GrBatchFontCache will eventually replace GrFontCache |
| 96 fBatchFontCache = new GrBatchFontCache(this); | 101 fBatchFontCache = new GrBatchFontCache(this); |
| 97 | 102 |
| 98 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); | 103 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); |
| 99 } | 104 } |
| 100 | 105 |
| 101 GrContext::~GrContext() { | 106 GrContext::~GrContext() { |
| 107 ASSERT_SINGLE_OWNER |
| 108 |
| 102 if (!fGpu) { | 109 if (!fGpu) { |
| 103 SkASSERT(!fCaps); | 110 SkASSERT(!fCaps); |
| 104 return; | 111 return; |
| 105 } | 112 } |
| 106 | 113 |
| 107 this->flush(); | 114 this->flush(); |
| 108 | 115 |
| 109 fDrawingManager->cleanup(); | 116 fDrawingManager->cleanup(); |
| 110 | 117 |
| 111 for (int i = 0; i < fCleanUpData.count(); ++i) { | 118 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 112 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 119 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 113 } | 120 } |
| 114 | 121 |
| 115 delete fResourceProvider; | 122 delete fResourceProvider; |
| 116 delete fResourceCache; | 123 delete fResourceCache; |
| 117 delete fBatchFontCache; | 124 delete fBatchFontCache; |
| 118 | 125 |
| 119 fGpu->unref(); | 126 fGpu->unref(); |
| 120 fCaps->unref(); | 127 fCaps->unref(); |
| 121 } | 128 } |
| 122 | 129 |
| 123 void GrContext::abandonContext() { | 130 void GrContext::abandonContext() { |
| 131 ASSERT_SINGLE_OWNER |
| 132 |
| 124 fResourceProvider->abandon(); | 133 fResourceProvider->abandon(); |
| 125 | 134 |
| 126 // Need to abandon the drawing manager first so all the render targets | 135 // Need to abandon the drawing manager first so all the render targets |
| 127 // will be released/forgotten before they too are abandoned. | 136 // will be released/forgotten before they too are abandoned. |
| 128 fDrawingManager->abandon(); | 137 fDrawingManager->abandon(); |
| 129 | 138 |
| 130 // abandon first to so destructors | 139 // abandon first to so destructors |
| 131 // don't try to free the resources in the API. | 140 // don't try to free the resources in the API. |
| 132 fResourceCache->abandonAll(); | 141 fResourceCache->abandonAll(); |
| 133 | 142 |
| 134 fGpu->contextAbandoned(); | 143 fGpu->contextAbandoned(); |
| 135 | 144 |
| 136 fBatchFontCache->freeAll(); | 145 fBatchFontCache->freeAll(); |
| 137 fLayerCache->freeAll(); | 146 fLayerCache->freeAll(); |
| 138 fTextBlobCache->freeAll(); | 147 fTextBlobCache->freeAll(); |
| 139 } | 148 } |
| 140 | 149 |
| 141 void GrContext::resetContext(uint32_t state) { | 150 void GrContext::resetContext(uint32_t state) { |
| 151 ASSERT_SINGLE_OWNER |
| 142 fGpu->markContextDirty(state); | 152 fGpu->markContextDirty(state); |
| 143 } | 153 } |
| 144 | 154 |
| 145 void GrContext::freeGpuResources() { | 155 void GrContext::freeGpuResources() { |
| 156 ASSERT_SINGLE_OWNER |
| 157 |
| 146 this->flush(); | 158 this->flush(); |
| 147 | 159 |
| 148 fBatchFontCache->freeAll(); | 160 fBatchFontCache->freeAll(); |
| 149 fLayerCache->freeAll(); | 161 fLayerCache->freeAll(); |
| 150 | 162 |
| 151 fDrawingManager->freeGpuResources(); | 163 fDrawingManager->freeGpuResources(); |
| 152 | 164 |
| 153 fResourceCache->purgeAllUnlocked(); | 165 fResourceCache->purgeAllUnlocked(); |
| 154 } | 166 } |
| 155 | 167 |
| 156 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 168 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
| 169 ASSERT_SINGLE_OWNER |
| 170 |
| 157 if (resourceCount) { | 171 if (resourceCount) { |
| 158 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 172 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 159 } | 173 } |
| 160 if (resourceBytes) { | 174 if (resourceBytes) { |
| 161 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 175 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 162 } | 176 } |
| 163 } | 177 } |
| 164 | 178 |
| 165 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
| 166 | 180 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 180 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The
solution is to move | 194 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The
solution is to move |
| 181 // drawText calls to below the GrContext level, but this is not trivial beca
use they call | 195 // drawText calls to below the GrContext level, but this is not trivial beca
use they call |
| 182 // drawPath on SkGpuDevice | 196 // drawPath on SkGpuDevice |
| 183 GrContext* context = reinterpret_cast<GrContext*>(data); | 197 GrContext* context = reinterpret_cast<GrContext*>(data); |
| 184 context->flush(); | 198 context->flush(); |
| 185 } | 199 } |
| 186 | 200 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 201 //////////////////////////////////////////////////////////////////////////////// |
| 188 | 202 |
| 189 void GrContext::flush(int flagsBitfield) { | 203 void GrContext::flush(int flagsBitfield) { |
| 204 ASSERT_SINGLE_OWNER |
| 190 RETURN_IF_ABANDONED | 205 RETURN_IF_ABANDONED |
| 191 | 206 |
| 192 if (kDiscard_FlushBit & flagsBitfield) { | 207 if (kDiscard_FlushBit & flagsBitfield) { |
| 193 fDrawingManager->reset(); | 208 fDrawingManager->reset(); |
| 194 } else { | 209 } else { |
| 195 fDrawingManager->flush(); | 210 fDrawingManager->flush(); |
| 196 } | 211 } |
| 197 fResourceCache->notifyFlushOccurred(); | 212 fResourceCache->notifyFlushOccurred(); |
| 198 fFlushToReduceCacheSize = false; | 213 fFlushToReduceCacheSize = false; |
| 199 } | 214 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 214 dstPI.fPixels = outPixels; | 229 dstPI.fPixels = outPixels; |
| 215 dstPI.fRowBytes = outRowBytes; | 230 dstPI.fRowBytes = outRowBytes; |
| 216 | 231 |
| 217 return srcPI.convertPixelsTo(&dstPI, width, height); | 232 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 218 } | 233 } |
| 219 | 234 |
| 220 bool GrContext::writeSurfacePixels(GrSurface* surface, | 235 bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 221 int left, int top, int width, int height, | 236 int left, int top, int width, int height, |
| 222 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, | 237 GrPixelConfig srcConfig, const void* buffer,
size_t rowBytes, |
| 223 uint32_t pixelOpsFlags) { | 238 uint32_t pixelOpsFlags) { |
| 239 ASSERT_SINGLE_OWNER |
| 224 RETURN_FALSE_IF_ABANDONED | 240 RETURN_FALSE_IF_ABANDONED |
| 225 ASSERT_OWNED_RESOURCE(surface); | 241 ASSERT_OWNED_RESOURCE(surface); |
| 226 SkASSERT(surface); | 242 SkASSERT(surface); |
| 227 | 243 |
| 228 this->testPMConversionsIfNecessary(pixelOpsFlags); | 244 this->testPMConversionsIfNecessary(pixelOpsFlags); |
| 229 | 245 |
| 230 // Trim the params here so that if we wind up making a temporary surface it
can be as small as | 246 // Trim the params here so that if we wind up making a temporary surface it
can be as small as |
| 231 // necessary and because GrGpu::getWritePixelsInfo requires it. | 247 // necessary and because GrGpu::getWritePixelsInfo requires it. |
| 232 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height
(), | 248 if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height
(), |
| 233 GrBytesPerPixel(srcConfig), &left
, &top, &width, | 249 GrBytesPerPixel(srcConfig), &left
, &top, &width, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 368 } |
| 353 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b
uffer, rowBytes); | 369 return fGpu->writePixels(surface, left, top, width, height, srcConfig, b
uffer, rowBytes); |
| 354 } | 370 } |
| 355 return true; | 371 return true; |
| 356 } | 372 } |
| 357 | 373 |
| 358 bool GrContext::readSurfacePixels(GrSurface* src, | 374 bool GrContext::readSurfacePixels(GrSurface* src, |
| 359 int left, int top, int width, int height, | 375 int left, int top, int width, int height, |
| 360 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, | 376 GrPixelConfig dstConfig, void* buffer, size_t
rowBytes, |
| 361 uint32_t flags) { | 377 uint32_t flags) { |
| 378 ASSERT_SINGLE_OWNER |
| 362 RETURN_FALSE_IF_ABANDONED | 379 RETURN_FALSE_IF_ABANDONED |
| 363 ASSERT_OWNED_RESOURCE(src); | 380 ASSERT_OWNED_RESOURCE(src); |
| 364 SkASSERT(src); | 381 SkASSERT(src); |
| 365 | 382 |
| 366 this->testPMConversionsIfNecessary(flags); | 383 this->testPMConversionsIfNecessary(flags); |
| 367 SkAutoMutexAcquire ama(fReadPixelsMutex); | 384 SkAutoMutexAcquire ama(fReadPixelsMutex); |
| 368 | 385 |
| 369 // Adjust the params so that if we wind up using an intermediate surface we'
ve already done | 386 // Adjust the params so that if we wind up using an intermediate surface we'
ve already done |
| 370 // all the trimming and the temporary can be the min size required. | 387 // all the trimming and the temporary can be the min size required. |
| 371 if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), | 388 if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 srcPI.fAlphaType = kPremul_SkAlphaType; | 496 srcPI.fAlphaType = kPremul_SkAlphaType; |
| 480 srcPI.fPixels = buffer; | 497 srcPI.fPixels = buffer; |
| 481 srcPI.fRowBytes = rowBytes; | 498 srcPI.fRowBytes = rowBytes; |
| 482 | 499 |
| 483 return srcPI.convertPixelsTo(&dstPI, width, height); | 500 return srcPI.convertPixelsTo(&dstPI, width, height); |
| 484 } | 501 } |
| 485 return true; | 502 return true; |
| 486 } | 503 } |
| 487 | 504 |
| 488 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { | 505 void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
| 506 ASSERT_SINGLE_OWNER |
| 489 RETURN_IF_ABANDONED | 507 RETURN_IF_ABANDONED |
| 490 SkASSERT(surface); | 508 SkASSERT(surface); |
| 491 ASSERT_OWNED_RESOURCE(surface); | 509 ASSERT_OWNED_RESOURCE(surface); |
| 492 if (surface->surfacePriv().hasPendingIO()) { | 510 if (surface->surfacePriv().hasPendingIO()) { |
| 493 this->flush(); | 511 this->flush(); |
| 494 } | 512 } |
| 495 GrRenderTarget* rt = surface->asRenderTarget(); | 513 GrRenderTarget* rt = surface->asRenderTarget(); |
| 496 if (fGpu && rt) { | 514 if (fGpu && rt) { |
| 497 fGpu->resolveRenderTarget(rt); | 515 fGpu->resolveRenderTarget(rt); |
| 498 } | 516 } |
| 499 } | 517 } |
| 500 | 518 |
| 501 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, | 519 void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
ct, |
| 502 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { | 520 const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
| 521 ASSERT_SINGLE_OWNER |
| 503 RETURN_IF_ABANDONED | 522 RETURN_IF_ABANDONED |
| 504 if (!src || !dst) { | 523 if (!src || !dst) { |
| 505 return; | 524 return; |
| 506 } | 525 } |
| 507 ASSERT_OWNED_RESOURCE(src); | 526 ASSERT_OWNED_RESOURCE(src); |
| 508 ASSERT_OWNED_RESOURCE(dst); | 527 ASSERT_OWNED_RESOURCE(dst); |
| 509 | 528 |
| 510 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh | 529 // Since we're going to the draw target and not GPU, no need to check kNoFlu
sh |
| 511 // here. | 530 // here. |
| 512 if (!dst->asRenderTarget()) { | 531 if (!dst->asRenderTarget()) { |
| 513 return; | 532 return; |
| 514 } | 533 } |
| 515 | 534 |
| 516 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarge
t())); | 535 SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarge
t())); |
| 517 if (!drawContext) { | 536 if (!drawContext) { |
| 518 return; | 537 return; |
| 519 } | 538 } |
| 520 | 539 |
| 521 drawContext->copySurface(src, srcRect, dstPoint); | 540 drawContext->copySurface(src, srcRect, dstPoint); |
| 522 | 541 |
| 523 if (kFlushWrites_PixelOp & pixelOpsFlags) { | 542 if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 524 this->flush(); | 543 this->flush(); |
| 525 } | 544 } |
| 526 } | 545 } |
| 527 | 546 |
| 528 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 547 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| 548 ASSERT_SINGLE_OWNER |
| 529 RETURN_IF_ABANDONED | 549 RETURN_IF_ABANDONED |
| 530 if (surface->surfacePriv().hasPendingWrite()) { | 550 if (surface->surfacePriv().hasPendingWrite()) { |
| 531 this->flush(); | 551 this->flush(); |
| 532 } | 552 } |
| 533 } | 553 } |
| 534 | 554 |
| 535 //////////////////////////////////////////////////////////////////////////////// | 555 //////////////////////////////////////////////////////////////////////////////// |
| 536 int GrContext::getRecommendedSampleCount(GrPixelConfig config, | 556 int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 537 SkScalar dpi) const { | 557 SkScalar dpi) const { |
| 558 ASSERT_SINGLE_OWNER |
| 559 |
| 538 if (!this->caps()->isConfigRenderable(config, true)) { | 560 if (!this->caps()->isConfigRenderable(config, true)) { |
| 539 return 0; | 561 return 0; |
| 540 } | 562 } |
| 541 int chosenSampleCount = 0; | 563 int chosenSampleCount = 0; |
| 542 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { | 564 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
| 543 if (dpi >= 250.0f) { | 565 if (dpi >= 250.0f) { |
| 544 chosenSampleCount = 4; | 566 chosenSampleCount = 4; |
| 545 } else { | 567 } else { |
| 546 chosenSampleCount = 16; | 568 chosenSampleCount = 16; |
| 547 } | 569 } |
| 548 } | 570 } |
| 549 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? | 571 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? |
| 550 chosenSampleCount : 0; | 572 chosenSampleCount : 0; |
| 551 } | 573 } |
| 552 | 574 |
| 553 | 575 |
| 554 GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps*
surfaceProps) { | 576 GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps*
surfaceProps) { |
| 577 ASSERT_SINGLE_OWNER |
| 555 return fDrawingManager->drawContext(rt, surfaceProps); | 578 return fDrawingManager->drawContext(rt, surfaceProps); |
| 556 } | 579 } |
| 557 | 580 |
| 558 bool GrContext::abandoned() const { | 581 bool GrContext::abandoned() const { |
| 582 ASSERT_SINGLE_OWNER |
| 559 return fDrawingManager->abandoned(); | 583 return fDrawingManager->abandoned(); |
| 560 } | 584 } |
| 561 | 585 |
| 562 namespace { | 586 namespace { |
| 563 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { | 587 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 564 GrConfigConversionEffect::PMConversion pmToUPM; | 588 GrConfigConversionEffect::PMConversion pmToUPM; |
| 565 GrConfigConversionEffect::PMConversion upmToPM; | 589 GrConfigConversionEffect::PMConversion upmToPM; |
| 566 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); | 590 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm
ToPM); |
| 567 *pmToUPMValue = pmToUPM; | 591 *pmToUPMValue = pmToUPM; |
| 568 *upmToPMValue = upmToPM; | 592 *upmToPMValue = upmToPM; |
| 569 } | 593 } |
| 570 } | 594 } |
| 571 | 595 |
| 572 void GrContext::testPMConversionsIfNecessary(uint32_t flags) { | 596 void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| 597 ASSERT_SINGLE_OWNER |
| 573 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { | 598 if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 574 SkAutoMutexAcquire ama(fTestPMConversionsMutex); | 599 SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 575 if (!fDidTestPMConversions) { | 600 if (!fDidTestPMConversions) { |
| 576 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); | 601 test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 577 fDidTestPMConversions = true; | 602 fDidTestPMConversions = true; |
| 578 } | 603 } |
| 579 } | 604 } |
| 580 } | 605 } |
| 581 | 606 |
| 582 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, | 607 const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 583 bool swapRAndB, | 608 bool swapRAndB, |
| 584 const SkMatrix& matrix
) const { | 609 const SkMatrix& matrix
) const { |
| 610 ASSERT_SINGLE_OWNER |
| 585 // We should have already called this->testPMConversionsIfNecessary(). | 611 // We should have already called this->testPMConversionsIfNecessary(). |
| 586 SkASSERT(fDidTestPMConversions); | 612 SkASSERT(fDidTestPMConversions); |
| 587 GrConfigConversionEffect::PMConversion pmToUPM = | 613 GrConfigConversionEffect::PMConversion pmToUPM = |
| 588 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); | 614 static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 589 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { | 615 if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
| 590 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); | 616 return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, mat
rix); |
| 591 } else { | 617 } else { |
| 592 return nullptr; | 618 return nullptr; |
| 593 } | 619 } |
| 594 } | 620 } |
| 595 | 621 |
| 596 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, | 622 const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 597 bool swapRAndB, | 623 bool swapRAndB, |
| 598 const SkMatrix& matrix
) const { | 624 const SkMatrix& matrix
) const { |
| 625 ASSERT_SINGLE_OWNER |
| 599 // We should have already called this->testPMConversionsIfNecessary(). | 626 // We should have already called this->testPMConversionsIfNecessary(). |
| 600 SkASSERT(fDidTestPMConversions); | 627 SkASSERT(fDidTestPMConversions); |
| 601 GrConfigConversionEffect::PMConversion upmToPM = | 628 GrConfigConversionEffect::PMConversion upmToPM = |
| 602 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); | 629 static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 603 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { | 630 if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
| 604 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); | 631 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); |
| 605 } else { | 632 } else { |
| 606 return nullptr; | 633 return nullptr; |
| 607 } | 634 } |
| 608 } | 635 } |
| 609 | 636 |
| 610 bool GrContext::didFailPMUPMConversionTest() const { | 637 bool GrContext::didFailPMUPMConversionTest() const { |
| 638 ASSERT_SINGLE_OWNER |
| 611 // We should have already called this->testPMConversionsIfNecessary(). | 639 // We should have already called this->testPMConversionsIfNecessary(). |
| 612 SkASSERT(fDidTestPMConversions); | 640 SkASSERT(fDidTestPMConversions); |
| 613 // The PM<->UPM tests fail or succeed together so we only need to check one. | 641 // The PM<->UPM tests fail or succeed together so we only need to check one. |
| 614 return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; | 642 return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; |
| 615 } | 643 } |
| 616 | 644 |
| 617 ////////////////////////////////////////////////////////////////////////////// | 645 ////////////////////////////////////////////////////////////////////////////// |
| 618 | 646 |
| 619 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { | 647 void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
) const { |
| 648 ASSERT_SINGLE_OWNER |
| 620 if (maxTextures) { | 649 if (maxTextures) { |
| 621 *maxTextures = fResourceCache->getMaxResourceCount(); | 650 *maxTextures = fResourceCache->getMaxResourceCount(); |
| 622 } | 651 } |
| 623 if (maxTextureBytes) { | 652 if (maxTextureBytes) { |
| 624 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); | 653 *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
| 625 } | 654 } |
| 626 } | 655 } |
| 627 | 656 |
| 628 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 657 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 658 ASSERT_SINGLE_OWNER |
| 629 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 659 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 630 } | 660 } |
| 631 | 661 |
| 632 ////////////////////////////////////////////////////////////////////////////// | 662 ////////////////////////////////////////////////////////////////////////////// |
| 633 | 663 |
| 634 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 664 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 665 ASSERT_SINGLE_OWNER |
| 635 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 666 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 636 } | 667 } |
| OLD | NEW |