Make a single GrSingleOwner in GrContext
authorjoshualitt <joshualitt@chromium.org>
Thu, 7 Jan 2016 19:32:39 +0000 (11:32 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 7 Jan 2016 19:32:40 +0000 (11:32 -0800)
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
include/gpu/GrDrawContext.h
include/private/GrSingleOwner.h
src/gpu/GrContext.cpp
src/gpu/GrDrawContext.cpp
src/gpu/GrDrawingManager.cpp
src/gpu/GrDrawingManager.h

index 39477e0..baf9978 100644 (file)
@@ -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;
index 21977be..7ae6f5e 100644 (file)
@@ -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
index dea982e..64e63d3 100644 (file)
@@ -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
index 854ff74..2bf887c 100644 (file)
@@ -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);
index fcdb1b4..01bd161 100644 (file)
@@ -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();)
 }
 
index 2a27f6a..266aa47 100644 (file)
@@ -202,5 +202,5 @@ GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt,
         return nullptr;
     }
 
-    return new GrDrawContext(this, rt, surfaceProps);
+    return new GrDrawContext(this, rt, surfaceProps, fSingleOwner);
 }
index c72dad9..df6c71a 100644 (file)
@@ -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<GrDrawTarget*>    fDrawTargets;