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
This commit is contained in:
joshualitt 2016-01-07 11:32:39 -08:00 committed by Commit bot
parent bfd5f171e6
commit f9bc796e0d
7 changed files with 22 additions and 9 deletions

View File

@ -392,7 +392,9 @@ private:
SkMutex fTestPMConversionsMutex; SkMutex fTestPMConversionsMutex;
// In debug builds we guard against improper thread handling // 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 { struct CleanUpData {
PFCleanUpFunc fFunc; PFCleanUpFunc fFunc;

View File

@ -283,7 +283,8 @@ private:
SkDEBUGCODE(void validate() const;) SkDEBUGCODE(void validate() const;)
GrDrawContext(GrDrawingManager*, GrRenderTarget*, const SkSurfaceProps* surfaceProps); GrDrawContext(GrDrawingManager*, GrRenderTarget*, const SkSurfaceProps* surfaceProps,
GrSingleOwner*);
void internalDrawPath(GrPipelineBuilder*, void internalDrawPath(GrPipelineBuilder*,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -309,7 +310,7 @@ private:
SkSurfaceProps fSurfaceProps; SkSurfaceProps fSurfaceProps;
// In debug builds we guard against improper thread handling // In debug builds we guard against improper thread handling
SkDEBUGCODE(mutable GrSingleOwner fSingleOwner;) mutable GrSingleOwner* fSingleOwner;
}; };
#endif #endif

View File

@ -48,6 +48,8 @@ private:
SkThreadID fOwner; // guarded by fMutex SkThreadID fOwner; // guarded by fMutex
int fReentranceCount; // guarded by fMutex int fReentranceCount; // guarded by fMutex
}; };
#else
class GrSingleOwner {}; // Provide a dummy implementation so we can pass pointers to constructors
#endif #endif
#endif #endif

View File

@ -95,7 +95,7 @@ void GrContext::initCommon(const GrContextOptions& options) {
dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; dtOptions.fClipBatchToBounds = options.fClipBatchToBounds;
dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; dtOptions.fDrawBatchBounds = options.fDrawBatchBounds;
dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; dtOptions.fMaxBatchLookback = options.fMaxBatchLookback;
fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner));
// GrBatchFontCache will eventually replace GrFontCache // GrBatchFontCache will eventually replace GrFontCache
fBatchFontCache = new GrBatchFontCache(this); fBatchFontCache = new GrBatchFontCache(this);

View File

@ -28,7 +28,7 @@
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext()) #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext())
#define ASSERT_SINGLE_OWNER \ #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_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; } #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; }
#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; } #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; }
@ -50,12 +50,14 @@ private:
// when the drawContext attempts to use it (via getDrawTarget). // when the drawContext attempts to use it (via getDrawTarget).
GrDrawContext::GrDrawContext(GrDrawingManager* drawingMgr, GrDrawContext::GrDrawContext(GrDrawingManager* drawingMgr,
GrRenderTarget* rt, GrRenderTarget* rt,
const SkSurfaceProps* surfaceProps) const SkSurfaceProps* surfaceProps,
GrSingleOwner* singleOwner)
: fDrawingManager(drawingMgr) : fDrawingManager(drawingMgr)
, fRenderTarget(rt) , fRenderTarget(rt)
, fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) , fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
, fTextContext(nullptr) , fTextContext(nullptr)
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) { , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fSingleOwner(singleOwner) {
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)
} }

View File

@ -202,5 +202,5 @@ GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt,
return nullptr; return nullptr;
} }
return new GrDrawContext(this, rt, surfaceProps); return new GrDrawContext(this, rt, surfaceProps, fSingleOwner);
} }

View File

@ -16,6 +16,7 @@
class GrContext; class GrContext;
class GrDrawContext; class GrDrawContext;
class GrSingleOWner;
class GrSoftwarePathRenderer; class GrSoftwarePathRenderer;
class GrTextContext; class GrTextContext;
@ -53,9 +54,11 @@ public:
static bool ProgramUnitTest(GrContext* context, int maxStages); static bool ProgramUnitTest(GrContext* context, int maxStages);
private: private:
GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets) GrDrawingManager(GrContext* context, const GrDrawTarget::Options& optionsForDrawTargets,
GrSingleOwner* singleOwner)
: fContext(context) : fContext(context)
, fOptionsForDrawTargets(optionsForDrawTargets) , fOptionsForDrawTargets(optionsForDrawTargets)
, fSingleOwner(singleOwner)
, fAbandoned(false) , fAbandoned(false)
, fNVPRTextContext(nullptr) , fNVPRTextContext(nullptr)
, fPathRendererChain(nullptr) , fPathRendererChain(nullptr)
@ -78,6 +81,9 @@ private:
GrContext* fContext; GrContext* fContext;
GrDrawTarget::Options fOptionsForDrawTargets; GrDrawTarget::Options fOptionsForDrawTargets;
// In debug builds we guard against improper thread handling
GrSingleOwner* fSingleOwner;
bool fAbandoned; bool fAbandoned;
SkTDArray<GrDrawTarget*> fDrawTargets; SkTDArray<GrDrawTarget*> fDrawTargets;