From f9bc796e0dbd31674c22b34761913ee6e8fdd66a Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 7 Jan 2016 11:32:39 -0800 Subject: [PATCH] Make a single GrSingleOwner in GrContext TBR=bsalomon@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1563703004 Review URL: https://codereview.chromium.org/1563703004 --- include/gpu/GrContext.h | 4 +++- include/gpu/GrDrawContext.h | 5 +++-- include/private/GrSingleOwner.h | 2 ++ src/gpu/GrContext.cpp | 2 +- src/gpu/GrDrawContext.cpp | 8 +++++--- src/gpu/GrDrawingManager.cpp | 2 +- src/gpu/GrDrawingManager.h | 8 +++++++- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 39477e0..baf9978 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -392,7 +392,9 @@ private: SkMutex fTestPMConversionsMutex; // In debug builds we guard against improper thread handling - SkDEBUGCODE(mutable GrSingleOwner fSingleOwner;) + // This guard is passed to the GrDrawingManager and, from there to all the + // GrDrawContexts. It is also passed to the GrTextureProvider and SkGpuDevice. + mutable GrSingleOwner fSingleOwner; struct CleanUpData { PFCleanUpFunc fFunc; diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index 21977be..7ae6f5e 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -283,7 +283,8 @@ private: SkDEBUGCODE(void validate() const;) - GrDrawContext(GrDrawingManager*, GrRenderTarget*, const SkSurfaceProps* surfaceProps); + GrDrawContext(GrDrawingManager*, GrRenderTarget*, const SkSurfaceProps* surfaceProps, + GrSingleOwner*); void internalDrawPath(GrPipelineBuilder*, const SkMatrix& viewMatrix, @@ -309,7 +310,7 @@ private: SkSurfaceProps fSurfaceProps; // In debug builds we guard against improper thread handling - SkDEBUGCODE(mutable GrSingleOwner fSingleOwner;) + mutable GrSingleOwner* fSingleOwner; }; #endif diff --git a/include/private/GrSingleOwner.h b/include/private/GrSingleOwner.h index dea982e..64e63d3 100644 --- a/include/private/GrSingleOwner.h +++ b/include/private/GrSingleOwner.h @@ -48,6 +48,8 @@ private: SkThreadID fOwner; // guarded by fMutex int fReentranceCount; // guarded by fMutex }; +#else +class GrSingleOwner {}; // Provide a dummy implementation so we can pass pointers to constructors #endif #endif diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 854ff74..2bf887c 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -95,7 +95,7 @@ void GrContext::initCommon(const GrContextOptions& options) { dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; - fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); + fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner)); // GrBatchFontCache will eventually replace GrFontCache fBatchFontCache = new GrBatchFontCache(this); diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index fcdb1b4..01bd161 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -28,7 +28,7 @@ #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext()) #define ASSERT_SINGLE_OWNER \ - SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) + SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) #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; } @@ -50,12 +50,14 @@ private: // when the drawContext attempts to use it (via getDrawTarget). GrDrawContext::GrDrawContext(GrDrawingManager* drawingMgr, GrRenderTarget* rt, - const SkSurfaceProps* surfaceProps) + const SkSurfaceProps* surfaceProps, + GrSingleOwner* singleOwner) : fDrawingManager(drawingMgr) , fRenderTarget(rt) , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) , fTextContext(nullptr) - , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { + , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) + , fSingleOwner(singleOwner) { SkDEBUGCODE(this->validate();) } diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 2a27f6a..266aa47 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -202,5 +202,5 @@ GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt, return nullptr; } - return new GrDrawContext(this, rt, surfaceProps); + return new GrDrawContext(this, rt, surfaceProps, fSingleOwner); } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index c72dad9..df6c71a 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -16,6 +16,7 @@ class GrContext; class GrDrawContext; +class GrSingleOWner; class GrSoftwarePathRenderer; class GrTextContext; @@ -53,9 +54,11 @@ public: static bool ProgramUnitTest(GrContext* context, int maxStages); private: - GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets) + GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets, + GrSingleOwner* singleOwner) : fContext(context) , fOptionsForDrawTargets(optionsForDrawTargets) + , fSingleOwner(singleOwner) , fAbandoned(false) , fNVPRTextContext(nullptr) , fPathRendererChain(nullptr) @@ -78,6 +81,9 @@ private: GrContext* fContext; GrDrawTarget::Options fOptionsForDrawTargets; + // In debug builds we guard against improper thread handling + GrSingleOwner* fSingleOwner; + bool fAbandoned; SkTDArray fDrawTargets; -- 2.7.4