aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-01-06 08:26:09 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-06 08:26:09 -0800
commit1de610a5287cf61d4f3a1fdc7413bd74827a8b6a (patch)
tree627973d2ea356962462fbfb9484c2bdf4cdfc82b /src
parente114dd63161b5efffbffb17e4d3facad77f34507 (diff)
Create debug only SkSingleOwner
This is so Gpu code can guard against improper multithreaded usage in debug builds TBR=bsalomon@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1555953004 Review URL: https://codereview.chromium.org/1555953004
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp33
-rw-r--r--src/gpu/GrDrawContext.cpp25
2 files changed, 57 insertions, 1 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2b20e17ae1..854ff742f3 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -23,6 +23,8 @@
#include "text/GrTextBlobCache.h"
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
+#define ASSERT_SINGLE_OWNER \
+ 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; }
@@ -66,6 +68,7 @@ GrContext::GrContext() : fUniqueID(next_id()) {
bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
const GrContextOptions& options) {
+ ASSERT_SINGLE_OWNER
SkASSERT(!fGpu);
fGpu = GrGpu::Create(backend, backendContext, options, this);
@@ -77,6 +80,8 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
}
void GrContext::initCommon(const GrContextOptions& options) {
+ ASSERT_SINGLE_OWNER
+
fCaps = SkRef(fGpu->caps());
fResourceCache = new GrResourceCache(fCaps);
fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
@@ -99,6 +104,8 @@ void GrContext::initCommon(const GrContextOptions& options) {
}
GrContext::~GrContext() {
+ ASSERT_SINGLE_OWNER
+
if (!fGpu) {
SkASSERT(!fCaps);
return;
@@ -121,6 +128,8 @@ GrContext::~GrContext() {
}
void GrContext::abandonContext() {
+ ASSERT_SINGLE_OWNER
+
fResourceProvider->abandon();
// Need to abandon the drawing manager first so all the render targets
@@ -139,10 +148,13 @@ void GrContext::abandonContext() {
}
void GrContext::resetContext(uint32_t state) {
+ ASSERT_SINGLE_OWNER
fGpu->markContextDirty(state);
}
void GrContext::freeGpuResources() {
+ ASSERT_SINGLE_OWNER
+
this->flush();
fBatchFontCache->freeAll();
@@ -154,6 +166,8 @@ void GrContext::freeGpuResources() {
}
void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
+ ASSERT_SINGLE_OWNER
+
if (resourceCount) {
*resourceCount = fResourceCache->getBudgetedResourceCount();
}
@@ -187,6 +201,7 @@ void GrContext::TextBlobCacheOverBudgetCB(void* data) {
////////////////////////////////////////////////////////////////////////////////
void GrContext::flush(int flagsBitfield) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
if (kDiscard_FlushBit & flagsBitfield) {
@@ -221,6 +236,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
int left, int top, int width, int height,
GrPixelConfig srcConfig, const void* buffer, size_t rowBytes,
uint32_t pixelOpsFlags) {
+ ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
ASSERT_OWNED_RESOURCE(surface);
SkASSERT(surface);
@@ -359,6 +375,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
int left, int top, int width, int height,
GrPixelConfig dstConfig, void* buffer, size_t rowBytes,
uint32_t flags) {
+ ASSERT_SINGLE_OWNER
RETURN_FALSE_IF_ABANDONED
ASSERT_OWNED_RESOURCE(src);
SkASSERT(src);
@@ -486,6 +503,7 @@ bool GrContext::readSurfacePixels(GrSurface* src,
}
void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkASSERT(surface);
ASSERT_OWNED_RESOURCE(surface);
@@ -500,6 +518,7 @@ void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) {
void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint, uint32_t pixelOpsFlags) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
if (!src || !dst) {
return;
@@ -526,6 +545,7 @@ void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
}
void GrContext::flushSurfaceWrites(GrSurface* surface) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
if (surface->surfacePriv().hasPendingWrite()) {
this->flush();
@@ -535,6 +555,8 @@ void GrContext::flushSurfaceWrites(GrSurface* surface) {
////////////////////////////////////////////////////////////////////////////////
int GrContext::getRecommendedSampleCount(GrPixelConfig config,
SkScalar dpi) const {
+ ASSERT_SINGLE_OWNER
+
if (!this->caps()->isConfigRenderable(config, true)) {
return 0;
}
@@ -552,10 +574,12 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config,
GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) {
+ ASSERT_SINGLE_OWNER
return fDrawingManager->drawContext(rt, surfaceProps);
}
-bool GrContext::abandoned() const {
+bool GrContext::abandoned() const {
+ ASSERT_SINGLE_OWNER
return fDrawingManager->abandoned();
}
@@ -570,6 +594,7 @@ void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
}
void GrContext::testPMConversionsIfNecessary(uint32_t flags) {
+ ASSERT_SINGLE_OWNER
if (SkToBool(kUnpremul_PixelOpsFlag & flags)) {
SkAutoMutexAcquire ama(fTestPMConversionsMutex);
if (!fDidTestPMConversions) {
@@ -582,6 +607,7 @@ void GrContext::testPMConversionsIfNecessary(uint32_t flags) {
const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture,
bool swapRAndB,
const SkMatrix& matrix) const {
+ ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
GrConfigConversionEffect::PMConversion pmToUPM =
@@ -596,6 +622,7 @@ const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture,
const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture,
bool swapRAndB,
const SkMatrix& matrix) const {
+ ASSERT_SINGLE_OWNER
// We should have already called this->testPMConversionsIfNecessary().
SkASSERT(fDidTestPMConversions);
GrConfigConversionEffect::PMConversion upmToPM =
@@ -608,6 +635,7 @@ const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture,
}
bool GrContext::didFailPMUPMConversionTest() const {
+ ASSERT_SINGLE_OWNER
// 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 +645,7 @@ bool GrContext::didFailPMUPMConversionTest() const {
//////////////////////////////////////////////////////////////////////////////
void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const {
+ ASSERT_SINGLE_OWNER
if (maxTextures) {
*maxTextures = fResourceCache->getMaxResourceCount();
}
@@ -626,11 +655,13 @@ void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes
}
void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
+ ASSERT_SINGLE_OWNER
fResourceCache->setLimits(maxTextures, maxTextureBytes);
}
//////////////////////////////////////////////////////////////////////////////
void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
+ ASSERT_SINGLE_OWNER
fResourceCache->dumpMemoryStatistics(traceMemoryDump);
}
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index c0e3d02095..fcdb1b4078 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -27,6 +27,8 @@
#include "text/GrStencilAndCoverTextContext.h"
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fDrawingManager->getContext())
+#define ASSERT_SINGLE_OWNER \
+ 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; }
@@ -69,10 +71,12 @@ void GrDrawContext::validate() const {
#endif
GrDrawContext::~GrDrawContext() {
+ ASSERT_SINGLE_OWNER
SkSafeUnref(fDrawTarget);
}
GrDrawTarget* GrDrawContext::getDrawTarget() {
+ ASSERT_SINGLE_OWNER
SkDEBUGCODE(this->validate();)
if (!fDrawTarget || fDrawTarget->isClosed()) {
@@ -83,6 +87,7 @@ GrDrawTarget* GrDrawContext::getDrawTarget() {
}
void GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -94,6 +99,7 @@ void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& clipBounds) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -111,6 +117,7 @@ void GrDrawContext::drawPosText(const GrClip& clip, const GrPaint& grPaint,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& clipBounds) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -127,6 +134,7 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkTextBlob* blob,
SkScalar x, SkScalar y,
SkDrawFilter* filter, const SkIRect& clipBounds) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -138,6 +146,7 @@ void GrDrawContext::drawTextBlob(const GrClip& clip, const SkPaint& skPaint,
}
void GrDrawContext::discard() {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -148,6 +157,7 @@ void GrDrawContext::discard() {
void GrDrawContext::clear(const SkIRect* rect,
const GrColor color,
bool canIgnoreRect) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -159,6 +169,7 @@ void GrDrawContext::clear(const SkIRect* rect,
void GrDrawContext::drawPaint(const GrClip& clip,
const GrPaint& origPaint,
const SkMatrix& viewMatrix) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -224,6 +235,7 @@ void GrDrawContext::drawRect(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRect& rect,
const GrStrokeInfo* strokeInfo) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -323,6 +335,7 @@ void GrDrawContext::fillRectToRect(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
const SkRect& localRect) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -350,6 +363,7 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRect& rectToDraw,
const SkMatrix& localMatrix) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -381,6 +395,7 @@ void GrDrawContext::drawVertices(const GrClip& clip,
const GrColor colors[],
const uint16_t indices[],
int indexCount) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -424,6 +439,7 @@ void GrDrawContext::drawAtlas(const GrClip& clip,
const SkRSXform xform[],
const SkRect texRect[],
const SkColor colors[]) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -446,6 +462,7 @@ void GrDrawContext::drawRRect(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRRect& rrect,
const GrStrokeInfo& strokeInfo) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -482,6 +499,7 @@ void GrDrawContext::drawDRRect(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRRect& outer,
const SkRRect& inner) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -519,6 +537,7 @@ void GrDrawContext::drawOval(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkRect& oval,
const GrStrokeInfo& strokeInfo) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -555,6 +574,7 @@ void GrDrawContext::drawImageNine(const GrClip& clip,
int imageHeight,
const SkIRect& center,
const SkRect& dst) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -621,6 +641,7 @@ static bool is_nested_rects(const SkMatrix& viewMatrix,
void GrDrawContext::drawBatch(const GrClip& clip,
const GrPaint& paint, GrDrawBatch* batch) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -632,6 +653,7 @@ void GrDrawContext::drawBatch(const GrClip& clip,
void GrDrawContext::drawPathBatch(const GrPipelineBuilder& pipelineBuilder,
GrDrawPathBatchBase* batch) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -645,6 +667,7 @@ void GrDrawContext::drawPath(const GrClip& clip,
const SkMatrix& viewMatrix,
const SkPath& path,
const GrStrokeInfo& strokeInfo) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)
@@ -704,6 +727,7 @@ void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder,
bool useAA,
const SkPath& path,
const GrStrokeInfo& strokeInfo) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkASSERT(!path.isEmpty());
@@ -800,6 +824,7 @@ void GrDrawContext::internalDrawPath(GrPipelineBuilder* pipelineBuilder,
}
void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch) {
+ ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
SkDEBUGCODE(this->validate();)