SkSurfaceProps fSurfaceProps;
// In debug builds we guard against improper thread handling
- mutable GrSingleOwner* fSingleOwner;
+ SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
};
#endif
#include "GrTexture.h"
#include "SkImageFilter.h"
+class GrSingleOwner;
+
class SK_API GrTextureProvider {
public:
///////////////////////////////////////////////////////////////////////////
}
/** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
- GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key) {
- GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
- if (resource) {
- GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
- SkASSERT(texture);
- return texture;
- }
- return NULL;
- }
+ GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
/**
* Determines whether a texture is associated with the unique key. If the texture is found it
GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
protected:
- GrTextureProvider(GrGpu* gpu, GrResourceCache* cache) : fCache(cache), fGpu(gpu) {}
+ GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* singleOwner);
/**
* Assigns a unique key to a resource. If the key is associated with another resource that
private:
GrResourceCache* fCache;
GrGpu* fGpu;
+
+ // In debug builds we guard against improper thread handling
+ SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
};
#endif
fCaps = SkRef(fGpu->caps());
fResourceCache = new GrResourceCache(fCaps);
fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
- fResourceProvider = new GrResourceProvider(fGpu, fResourceCache);
+ fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner);
fLayerCache.reset(new GrLayerCache(this));
, fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
, fTextContext(nullptr)
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
- , fSingleOwner(singleOwner) {
+#ifdef SK_DEBUG
+ , fSingleOwner(singleOwner)
+#endif
+{
SkDEBUGCODE(this->validate();)
}
GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
-GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cache) {
+GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner)
+ : INHERITED(gpu, cache, owner) {
GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
fQuadIndexBufferKey = gQuadIndexBufferKey;
}
class GrIndexBuffer;
class GrPath;
class GrRenderTarget;
+class GrSingleOwner;
class GrStencilAttachment;
class GrStrokeInfo;
class GrVertexBuffer;
*/
class GrResourceProvider : protected GrTextureProvider {
public:
- GrResourceProvider(GrGpu* gpu, GrResourceCache* cache);
+ GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner);
template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) {
return static_cast<T*>(this->findAndRefResourceByUniqueKey(key));
#include "GrTexturePriv.h"
#include "GrResourceCache.h"
#include "GrGpu.h"
+#include "../private/GrSingleOwner.h"
+
+#define ASSERT_SINGLE_OWNER \
+ SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
enum ScratchTextureFlags {
kExact_ScratchTextureFlag = 0x1,
kNoCreate_ScratchTextureFlag = 0x4,
};
+GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* singleOwner)
+ : fCache(cache)
+ , fGpu(gpu)
+#ifdef SK_DEBUG
+ , fSingleOwner(singleOwner)
+#endif
+ {
+}
+
GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budgeted,
const void* srcData, size_t rowBytes) {
+ ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
}
GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
+ ASSERT_SINGLE_OWNER
return this->internalCreateApproxTexture(desc, 0);
}
GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& desc,
uint32_t scratchFlags) {
+ ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
uint32_t flags) {
+ ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc,
GrWrapOwnership ownership) {
+ ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
}
GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
+ ASSERT_SINGLE_OWNER
return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc,
- kBorrow_GrWrapOwnership);
+ kBorrow_GrWrapOwnership);
}
void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuResource* resource) {
+ ASSERT_SINGLE_OWNER
if (this->isAbandoned() || !resource) {
return;
}
}
bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) const {
+ ASSERT_SINGLE_OWNER
return this->isAbandoned() ? false : fCache->hasUniqueKey(key);
}
GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKey& key) {
+ ASSERT_SINGLE_OWNER
return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key);
}
+
+GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& key) {
+ ASSERT_SINGLE_OWNER
+ GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
+ if (resource) {
+ GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
+ SkASSERT(texture);
+ return texture;
+ }
+ return NULL;
+}