Chromium Code Reviews| Index: src/gpu/GrContext.cpp |
| diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp |
| index 2b20e17ae16369155ba60ab6045f689db5f44341..728ef7249febc73d0e1d502fd0ecdf3a5c44f9da 100644 |
| --- a/src/gpu/GrContext.cpp |
| +++ b/src/gpu/GrContext.cpp |
| @@ -23,9 +23,16 @@ |
| #include "text/GrTextBlobCache.h" |
| #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| -#define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
| -#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; } |
| -#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; } |
| +#define TAKE_DEBUG_MUTEX \ |
| + SkASSERT(1 == fSafetyMutex.fSemaphore.fCount || fSafetyMutex.fOwner == SkGetThreadID()); \ |
| + SkDEBUGCODE(SkAutoTAcquire<SkRecursiveMutex> debug_SafetyMutex(fSafetyMutex);) |
| +#define RETURN_IF_ABANDONED TAKE_DEBUG_MUTEX if (fDrawingManager->abandoned()) { return; } |
| +#define RETURN_FALSE_IF_ABANDONED \ |
| + TAKE_DEBUG_MUTEX \ |
| + if (fDrawingManager->abandoned()) { return false; } |
| +#define RETURN_NULL_IF_ABANDONED \ |
| + TAKE_DEBUG_MUTEX \ |
| + if (fDrawingManager->abandoned()) { return nullptr; } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -77,6 +84,8 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| } |
| void GrContext::initCommon(const GrContextOptions& options) { |
| + TAKE_DEBUG_MUTEX |
|
mtklein
2016/01/05 22:47:50
What is the constraint that you are trying to enfo
joshualitt
2016/01/06 14:03:27
No, but a GrContext may only ever be used from one
mtklein
2016/01/06 14:33:46
So what do we need the reentrant mutex for? We're
|
| + |
| fCaps = SkRef(fGpu->caps()); |
| fResourceCache = new GrResourceCache(fCaps); |
| fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
| @@ -99,6 +108,8 @@ void GrContext::initCommon(const GrContextOptions& options) { |
| } |
| GrContext::~GrContext() { |
| + TAKE_DEBUG_MUTEX |
| + |
| if (!fGpu) { |
| SkASSERT(!fCaps); |
| return; |
| @@ -121,6 +132,8 @@ GrContext::~GrContext() { |
| } |
| void GrContext::abandonContext() { |
| + TAKE_DEBUG_MUTEX |
| + |
| fResourceProvider->abandon(); |
| // Need to abandon the drawing manager first so all the render targets |
| @@ -139,10 +152,14 @@ void GrContext::abandonContext() { |
| } |
| void GrContext::resetContext(uint32_t state) { |
| + TAKE_DEBUG_MUTEX |
| + |
| fGpu->markContextDirty(state); |
| } |
| void GrContext::freeGpuResources() { |
| + TAKE_DEBUG_MUTEX |
| + |
| this->flush(); |
| fBatchFontCache->freeAll(); |
| @@ -154,6 +171,8 @@ void GrContext::freeGpuResources() { |
| } |
| void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
| + TAKE_DEBUG_MUTEX |
| + |
| if (resourceCount) { |
| *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| } |
| @@ -535,6 +554,8 @@ void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| //////////////////////////////////////////////////////////////////////////////// |
| int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| SkScalar dpi) const { |
| + TAKE_DEBUG_MUTEX |
| + |
| if (!this->caps()->isConfigRenderable(config, true)) { |
| return 0; |
| } |
| @@ -552,10 +573,12 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) { |
| + TAKE_DEBUG_MUTEX |
| return fDrawingManager->drawContext(rt, surfaceProps); |
| } |
| -bool GrContext::abandoned() const { |
| +bool GrContext::abandoned() const { |
| + TAKE_DEBUG_MUTEX |
| return fDrawingManager->abandoned(); |
| } |
| @@ -570,6 +593,7 @@ void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| } |
| void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| + TAKE_DEBUG_MUTEX |
| if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| if (!fDidTestPMConversions) { |
| @@ -582,6 +606,7 @@ void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| bool swapRAndB, |
| const SkMatrix& matrix) const { |
| + TAKE_DEBUG_MUTEX |
| // We should have already called this->testPMConversionsIfNecessary(). |
| SkASSERT(fDidTestPMConversions); |
| GrConfigConversionEffect::PMConversion pmToUPM = |
| @@ -596,6 +621,7 @@ const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| bool swapRAndB, |
| const SkMatrix& matrix) const { |
| + TAKE_DEBUG_MUTEX |
| // We should have already called this->testPMConversionsIfNecessary(). |
| SkASSERT(fDidTestPMConversions); |
| GrConfigConversionEffect::PMConversion upmToPM = |
| @@ -608,6 +634,7 @@ const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| } |
| bool GrContext::didFailPMUPMConversionTest() const { |
| + TAKE_DEBUG_MUTEX |
| // We should have already called this->testPMConversionsIfNecessary(). |
| SkASSERT(fDidTestPMConversions); |
| // The PM<->UPM tests fail or succeed together so we only need to check one. |
| @@ -617,6 +644,7 @@ bool GrContext::didFailPMUPMConversionTest() const { |
| ////////////////////////////////////////////////////////////////////////////// |
| void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
| + TAKE_DEBUG_MUTEX |
| if (maxTextures) { |
| *maxTextures = fResourceCache->getMaxResourceCount(); |
| } |
| @@ -626,11 +654,13 @@ void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes |
| } |
| void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
| + TAKE_DEBUG_MUTEX |
| fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| } |
| ////////////////////////////////////////////////////////////////////////////// |
| void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| + TAKE_DEBUG_MUTEX |
| fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| } |