Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state: a) instance is budgeted or not budgeted b) instance references wrapped backend objects or not The "object lifecycle" was also attached to backend object handles (ids), which made the code a bit unclear. Backend objects would be associated with GrGpuResource::LifeCycle, even though GrGpuResource::LifeCycle refers to the GpuResource, and individual backend objects in one GpuResource might be governed with different "lifecycle". Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo. This was previously GrGpuResource::kCached_LifeCycle, GrGpuResource::kUncached_LifeCycle. Mark the "references wrapped object" with boolean. This was previously GrGpuResource::kBorrowed_LifeCycle, GrGpuResource::kAdopted_LifeCycle for GrGpuResource. Associate the backend object ownership status with GrBackendObjectOwnership for the backend object handles. The resource type leaf constuctors, such has GrGLTexture or GrGLTextureRenderTarget take "budgeted" parameter. This parameter is passed to GrGpuResource::registerWithCache(). The resource type intermediary constructors, such as GrGLTexture constructors for class GrGLTextureRenderTarget do not take "budgeted" parameters, intermediary construtors do not call registerWithCache. Removes the need for tagging GrGpuResource -derived subclass constructors with "Derived" parameter. Makes instances that wrap backend objects be registered with a new function GrGpuResource::registerWithCacheWrapped(). Removes "budgeted" parameter from classes such as StencilAttahment, as they are always cached and never wrap any external backend objects. Removes the use of concept "external" from the member function names. The API refers to the objects as "wrapped", so make all related functions use the term consistently. No change in functionality. Resources referencing wrapped objects are always inserted to the cache with budget decision kNo. BUG=594928 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002 Review URL: https://codereview.chromium.org/1862043002
This commit is contained in:
parent
cb61a6452f
commit
2e6055b3ea
@ -23,8 +23,8 @@ enum {
|
|||||||
class BenchResource : public GrGpuResource {
|
class BenchResource : public GrGpuResource {
|
||||||
public:
|
public:
|
||||||
BenchResource (GrGpu* gpu)
|
BenchResource (GrGpu* gpu)
|
||||||
: INHERITED(gpu, kCached_LifeCycle) {
|
: INHERITED(gpu) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ComputeKey(int i, int keyData32Count, GrUniqueKey* key) {
|
static void ComputeKey(int i, int keyData32Count, GrUniqueKey* key) {
|
||||||
|
@ -110,22 +110,24 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType,
|
GrBuffer(GrGpu* gpu, size_t gpuMemorySize, GrBufferType intendedType,
|
||||||
GrAccessPattern accessPattern, bool cpuBacked)
|
GrAccessPattern accessPattern, bool cpuBacked)
|
||||||
: INHERITED(gpu, kCached_LifeCycle),
|
: INHERITED(gpu),
|
||||||
fMapPtr(nullptr),
|
fMapPtr(nullptr),
|
||||||
fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers?
|
fGpuMemorySize(gpuMemorySize), // TODO: Zero for cpu backed buffers?
|
||||||
fAccessPattern(accessPattern),
|
fAccessPattern(accessPattern),
|
||||||
fCPUBacked(cpuBacked) {
|
fCPUBacked(cpuBacked),
|
||||||
|
fIntendedType(intendedType) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void computeScratchKey(GrScratchKey* key) const override {
|
||||||
if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern == fAccessPattern) {
|
if (!fCPUBacked && SkIsPow2(fGpuMemorySize) && kDynamic_GrAccessPattern == fAccessPattern) {
|
||||||
GrScratchKey key;
|
ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, fIntendedType, key);
|
||||||
ComputeScratchKeyForDynamicBuffer(fGpuMemorySize, intendedType, &key);
|
|
||||||
this->setScratchKey(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* fMapPtr;
|
void* fMapPtr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual size_t onGpuMemorySize() const { return fGpuMemorySize; }
|
size_t onGpuMemorySize() const override { return fGpuMemorySize; }
|
||||||
|
|
||||||
virtual void onMap() = 0;
|
virtual void onMap() = 0;
|
||||||
virtual void onUnmap() = 0;
|
virtual void onUnmap() = 0;
|
||||||
@ -134,7 +136,7 @@ private:
|
|||||||
size_t fGpuMemorySize;
|
size_t fGpuMemorySize;
|
||||||
GrAccessPattern fAccessPattern;
|
GrAccessPattern fAccessPattern;
|
||||||
bool fCPUBacked;
|
bool fCPUBacked;
|
||||||
|
GrBufferType fIntendedType;
|
||||||
typedef GrGpuResource INHERITED;
|
typedef GrGpuResource INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -140,34 +140,6 @@ private:
|
|||||||
class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
|
class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
enum LifeCycle {
|
|
||||||
/**
|
|
||||||
* The resource is cached and owned by Skia. Resources with this status may be kept alive
|
|
||||||
* by the cache as either scratch or unique resources even when there are no refs to them.
|
|
||||||
* The cache may release them whenever there are no refs.
|
|
||||||
*/
|
|
||||||
kCached_LifeCycle,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The resource is uncached. As soon as there are no more refs to it, it is released. Under
|
|
||||||
* the hood the cache may opaquely recycle it as a cached resource.
|
|
||||||
*/
|
|
||||||
kUncached_LifeCycle,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Similar to uncached, but Skia does not manage the lifetime of the underlying backend
|
|
||||||
* 3D API object(s). The client is responsible for freeing those. Used to inject client-
|
|
||||||
* created GPU resources into Skia (e.g. to render to a client-created texture).
|
|
||||||
*/
|
|
||||||
kBorrowed_LifeCycle,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An external resource with ownership transfered into Skia. Skia will free the resource.
|
|
||||||
*/
|
|
||||||
kAdopted_LifeCycle,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether a object has been abandoned or released. All objects will
|
* Tests whether a object has been abandoned or released. All objects will
|
||||||
* be in this state after their creating GrContext is destroyed or has
|
* be in this state after their creating GrContext is destroyed or has
|
||||||
@ -261,11 +233,16 @@ public:
|
|||||||
virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// This must be called by every GrGpuObject. It should be called once the object is fully
|
// This must be called by every non-wrapped GrGpuObject. It should be called once the object is
|
||||||
// initialized (i.e. not in a base class constructor).
|
// fully initialized (i.e. only from the constructors of the final class).
|
||||||
void registerWithCache();
|
void registerWithCache(SkBudgeted);
|
||||||
|
|
||||||
GrGpuResource(GrGpu*, LifeCycle);
|
// This must be called by every GrGpuObject that references any wrapped backend objects. It
|
||||||
|
// should be called once the object is fully initialized (i.e. only from the constructors of the
|
||||||
|
// final class).
|
||||||
|
void registerWithCacheWrapped();
|
||||||
|
|
||||||
|
GrGpuResource(GrGpu*);
|
||||||
virtual ~GrGpuResource();
|
virtual ~GrGpuResource();
|
||||||
|
|
||||||
GrGpu* getGpu() const { return fGpu; }
|
GrGpu* getGpu() const { return fGpu; }
|
||||||
@ -277,25 +254,12 @@ protected:
|
|||||||
backend API calls should be made. */
|
backend API calls should be made. */
|
||||||
virtual void onAbandon() { }
|
virtual void onAbandon() { }
|
||||||
|
|
||||||
bool shouldFreeResources() const { return fLifeCycle != kBorrowed_LifeCycle; }
|
|
||||||
|
|
||||||
bool isExternal() const {
|
|
||||||
return GrGpuResource::kAdopted_LifeCycle == fLifeCycle ||
|
|
||||||
GrGpuResource::kBorrowed_LifeCycle == fLifeCycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This entry point should be called whenever gpuMemorySize() should report a different size.
|
* This entry point should be called whenever gpuMemorySize() should report a different size.
|
||||||
* The cache will call gpuMemorySize() to update the current size of the resource.
|
* The cache will call gpuMemorySize() to update the current size of the resource.
|
||||||
*/
|
*/
|
||||||
void didChangeGpuMemorySize() const;
|
void didChangeGpuMemorySize() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Optionally called by the GrGpuResource subclass if the resource can be used as scratch.
|
|
||||||
* By default resources are not usable as scratch. This should only be called once.
|
|
||||||
**/
|
|
||||||
void setScratchKey(const GrScratchKey& scratchKey);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows subclasses to add additional backing information to the SkTraceMemoryDump. Called by
|
* Allows subclasses to add additional backing information to the SkTraceMemoryDump. Called by
|
||||||
* onMemoryDump. The default implementation adds no backing information.
|
* onMemoryDump. The default implementation adds no backing information.
|
||||||
@ -303,6 +267,14 @@ protected:
|
|||||||
virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {}
|
virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Called by the registerWithCache if the resource is available to be used as scratch.
|
||||||
|
* Resource subclasses should override this if the instances should be recycled as scratch
|
||||||
|
* resources and populate the scratchKey with the key.
|
||||||
|
* By default resources are not recycled as scratch.
|
||||||
|
**/
|
||||||
|
virtual void computeScratchKey(GrScratchKey*) const { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the object in the underlying 3D API. Called by CacheAccess.
|
* Frees the object in the underlying 3D API. Called by CacheAccess.
|
||||||
*/
|
*/
|
||||||
@ -341,7 +313,8 @@ private:
|
|||||||
GrGpu* fGpu;
|
GrGpu* fGpu;
|
||||||
mutable size_t fGpuMemorySize;
|
mutable size_t fGpuMemorySize;
|
||||||
|
|
||||||
LifeCycle fLifeCycle;
|
SkBudgeted fBudgeted;
|
||||||
|
bool fRefsWrappedObjects;
|
||||||
const uint32_t fUniqueID;
|
const uint32_t fUniqueID;
|
||||||
|
|
||||||
SkAutoTUnref<const SkData> fData;
|
SkAutoTUnref<const SkData> fData;
|
||||||
|
@ -156,9 +156,9 @@ public:
|
|||||||
GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; }
|
GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GrRenderTarget(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
|
GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc,
|
||||||
SampleConfig sampleConfig, GrStencilAttachment* stencil = nullptr)
|
SampleConfig sampleConfig, GrStencilAttachment* stencil = nullptr)
|
||||||
: INHERITED(gpu, lifeCycle, desc)
|
: INHERITED(gpu, desc)
|
||||||
, fStencilAttachment(stencil)
|
, fStencilAttachment(stencil)
|
||||||
, fSampleConfig(sampleConfig)
|
, fSampleConfig(sampleConfig)
|
||||||
, fLastDrawTarget(nullptr) {
|
, fLastDrawTarget(nullptr) {
|
||||||
|
@ -146,8 +146,8 @@ protected:
|
|||||||
// Provides access to methods that should be public within Skia code.
|
// Provides access to methods that should be public within Skia code.
|
||||||
friend class GrSurfacePriv;
|
friend class GrSurfacePriv;
|
||||||
|
|
||||||
GrSurface(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
|
GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
|
||||||
: INHERITED(gpu, lifeCycle)
|
: INHERITED(gpu)
|
||||||
, fDesc(desc)
|
, fDesc(desc)
|
||||||
, fReleaseProc(NULL)
|
, fReleaseProc(NULL)
|
||||||
, fReleaseCtx(NULL)
|
, fReleaseCtx(NULL)
|
||||||
|
@ -46,11 +46,12 @@ public:
|
|||||||
inline const GrTexturePriv texturePriv() const;
|
inline const GrTexturePriv texturePriv() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GrTexture(GrGpu*, LifeCycle, const GrSurfaceDesc&, GrSLType, bool wasMipMapDataProvided);
|
GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType, bool wasMipMapDataProvided);
|
||||||
|
|
||||||
void validateDesc() const;
|
void validateDesc() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void computeScratchKey(GrScratchKey*) const override;
|
||||||
size_t onGpuMemorySize() const override;
|
size_t onGpuMemorySize() const override;
|
||||||
void dirtyMipMaps(bool mipMapsDirty);
|
void dirtyMipMaps(bool mipMapsDirty);
|
||||||
|
|
||||||
|
@ -464,4 +464,14 @@ enum GrAccessPattern {
|
|||||||
#define GrCapsDebugf(caps, ...)
|
#define GrCapsDebugf(caps, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies if the holder owns the backend, OpenGL or Vulkan, object.
|
||||||
|
*/
|
||||||
|
enum class GrBackendObjectOwnership : bool {
|
||||||
|
/** Holder does not destroy the backend object. */
|
||||||
|
kBorrowed = false,
|
||||||
|
/** Holder destroys the backend object. */
|
||||||
|
kOwned = true
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -150,9 +150,6 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget
|
|||||||
desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
|
desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
|
||||||
|
|
||||||
GrTexture* tex = nullptr;
|
GrTexture* tex = nullptr;
|
||||||
GrGpuResource::LifeCycle lifeCycle = SkBudgeted::kYes == budgeted ?
|
|
||||||
GrGpuResource::kCached_LifeCycle :
|
|
||||||
GrGpuResource::kUncached_LifeCycle;
|
|
||||||
|
|
||||||
if (GrPixelConfigIsCompressed(desc.fConfig)) {
|
if (GrPixelConfigIsCompressed(desc.fConfig)) {
|
||||||
// We shouldn't be rendering into this
|
// We shouldn't be rendering into this
|
||||||
@ -165,10 +162,10 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->handleDirtyContext();
|
this->handleDirtyContext();
|
||||||
tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
|
tex = this->onCreateCompressedTexture(desc, budgeted, texels);
|
||||||
} else {
|
} else {
|
||||||
this->handleDirtyContext();
|
this->handleDirtyContext();
|
||||||
tex = this->onCreateTexture(desc, lifeCycle, texels);
|
tex = this->onCreateTexture(desc, budgeted, texels);
|
||||||
}
|
}
|
||||||
if (tex) {
|
if (tex) {
|
||||||
if (!caps->reuseScratchTextures() && !isRT) {
|
if (!caps->reuseScratchTextures() && !isRT) {
|
||||||
|
@ -529,10 +529,10 @@ private:
|
|||||||
// Texture size and sample size will have already been validated in base class before
|
// Texture size and sample size will have already been validated in base class before
|
||||||
// onCreateTexture/CompressedTexture are called.
|
// onCreateTexture/CompressedTexture are called.
|
||||||
virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
|
virtual GrTexture* onCreateTexture(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) = 0;
|
const SkTArray<GrMipLevel>& texels) = 0;
|
||||||
virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
virtual GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) = 0;
|
const SkTArray<GrMipLevel>& texels) = 0;
|
||||||
|
|
||||||
virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
|
virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
|
||||||
|
@ -19,15 +19,26 @@ static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
|
|||||||
return gpu->getContext()->getResourceCache();
|
return gpu->getContext()->getResourceCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle)
|
GrGpuResource::GrGpuResource(GrGpu* gpu)
|
||||||
: fGpu(gpu)
|
: fGpu(gpu)
|
||||||
, fGpuMemorySize(kInvalidGpuMemorySize)
|
, fGpuMemorySize(kInvalidGpuMemorySize)
|
||||||
, fLifeCycle(lifeCycle)
|
, fBudgeted(SkBudgeted::kNo)
|
||||||
|
, fRefsWrappedObjects(false)
|
||||||
, fUniqueID(CreateUniqueID()) {
|
, fUniqueID(CreateUniqueID()) {
|
||||||
SkDEBUGCODE(fCacheArrayIndex = -1);
|
SkDEBUGCODE(fCacheArrayIndex = -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuResource::registerWithCache() {
|
void GrGpuResource::registerWithCache(SkBudgeted budgeted) {
|
||||||
|
SkASSERT(fBudgeted == SkBudgeted::kNo);
|
||||||
|
fBudgeted = budgeted;
|
||||||
|
this->computeScratchKey(&fScratchKey);
|
||||||
|
get_resource_cache(fGpu)->resourceAccess().insertResource(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GrGpuResource::registerWithCacheWrapped() {
|
||||||
|
SkASSERT(fBudgeted == SkBudgeted::kNo);
|
||||||
|
// Currently resources referencing wrapped objects are not budgeted.
|
||||||
|
fRefsWrappedObjects = true;
|
||||||
get_resource_cache(fGpu)->resourceAccess().insertResource(this);
|
get_resource_cache(fGpu)->resourceAccess().insertResource(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,16 +175,6 @@ bool GrGpuResource::notifyRefCountIsZero() const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuResource::setScratchKey(const GrScratchKey& scratchKey) {
|
|
||||||
SkASSERT(!fScratchKey.isValid());
|
|
||||||
SkASSERT(scratchKey.isValid());
|
|
||||||
// Wrapped resources can never have a scratch key.
|
|
||||||
if (this->resourcePriv().isExternal()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fScratchKey = scratchKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GrGpuResource::removeScratchKey() {
|
void GrGpuResource::removeScratchKey() {
|
||||||
if (!this->wasDestroyed() && fScratchKey.isValid()) {
|
if (!this->wasDestroyed() && fScratchKey.isValid()) {
|
||||||
get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this);
|
get_resource_cache(fGpu)->resourceAccess().willRemoveScratchKey(this);
|
||||||
@ -182,16 +183,18 @@ void GrGpuResource::removeScratchKey() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuResource::makeBudgeted() {
|
void GrGpuResource::makeBudgeted() {
|
||||||
if (!this->wasDestroyed() && GrGpuResource::kUncached_LifeCycle == fLifeCycle) {
|
if (!this->wasDestroyed() && SkBudgeted::kNo == fBudgeted) {
|
||||||
fLifeCycle = kCached_LifeCycle;
|
// Currently resources referencing wrapped objects are not budgeted.
|
||||||
|
SkASSERT(!fRefsWrappedObjects);
|
||||||
|
fBudgeted = SkBudgeted::kYes;
|
||||||
get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
|
get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuResource::makeUnbudgeted() {
|
void GrGpuResource::makeUnbudgeted() {
|
||||||
if (!this->wasDestroyed() && GrGpuResource::kCached_LifeCycle == fLifeCycle &&
|
if (!this->wasDestroyed() && SkBudgeted::kYes == fBudgeted &&
|
||||||
!fUniqueKey.isValid()) {
|
!fUniqueKey.isValid()) {
|
||||||
fLifeCycle = kUncached_LifeCycle;
|
fBudgeted = SkBudgeted::kNo;
|
||||||
get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
|
get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,18 +29,6 @@ private:
|
|||||||
SkBudgeted::kYes == fResource->resourcePriv().isBudgeted();
|
SkBudgeted::kYes == fResource->resourcePriv().isBudgeted();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the resource object wrapping an externally allocated GPU resource that Skia has not taken
|
|
||||||
* ownership of.
|
|
||||||
*/
|
|
||||||
bool isBorrowed() const { return GrGpuResource::kBorrowed_LifeCycle == fResource->fLifeCycle; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the resource object wrapping an externally allocated GPU resource that Skia has taken
|
|
||||||
* ownership of.
|
|
||||||
*/
|
|
||||||
bool isAdopted() const { return GrGpuResource::kAdopted_LifeCycle == fResource->fLifeCycle; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the cache to delete the resource under normal circumstances.
|
* Called by the cache to delete the resource under normal circumstances.
|
||||||
*/
|
*/
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
* Does the resource count against the resource budget?
|
* Does the resource count against the resource budget?
|
||||||
*/
|
*/
|
||||||
SkBudgeted isBudgeted() const {
|
SkBudgeted isBudgeted() const {
|
||||||
bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle;
|
bool ret = SkBudgeted::kYes == fResource->fBudgeted;
|
||||||
SkASSERT(ret || !fResource->getUniqueKey().isValid());
|
SkASSERT(ret || !fResource->getUniqueKey().isValid());
|
||||||
return SkBudgeted(ret);
|
return SkBudgeted(ret);
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Is the resource object wrapping an externally allocated GPU resource?
|
* Is the resource object wrapping an externally allocated GPU resource?
|
||||||
*/
|
*/
|
||||||
bool isExternal() const { return fResource->isExternal(); }
|
bool refsWrappedObjects() const { return fResource->fRefsWrappedObjects; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this resource can be used as a scratch resource this returns a valid scratch key.
|
* If this resource can be used as a scratch resource this returns a valid scratch key.
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
* Initialize to a path with a fixed stroke. Stroke must not be hairline.
|
* Initialize to a path with a fixed stroke. Stroke must not be hairline.
|
||||||
*/
|
*/
|
||||||
GrPath(GrGpu* gpu, const SkPath& skPath, const GrStrokeInfo& stroke)
|
GrPath(GrGpu* gpu, const SkPath& skPath, const GrStrokeInfo& stroke)
|
||||||
: INHERITED(gpu, kCached_LifeCycle)
|
: INHERITED(gpu)
|
||||||
, fBounds(SkRect::MakeEmpty())
|
, fBounds(SkRect::MakeEmpty())
|
||||||
, fFillType(GrPathRendering::kWinding_FillType)
|
, fFillType(GrPathRendering::kWinding_FillType)
|
||||||
#ifdef SK_DEBUG
|
#ifdef SK_DEBUG
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
GrPathRange::GrPathRange(GrGpu* gpu,
|
GrPathRange::GrPathRange(GrGpu* gpu,
|
||||||
PathGenerator* pathGenerator)
|
PathGenerator* pathGenerator)
|
||||||
: INHERITED(gpu, kCached_LifeCycle),
|
: INHERITED(gpu),
|
||||||
fPathGenerator(SkRef(pathGenerator)),
|
fPathGenerator(SkRef(pathGenerator)),
|
||||||
fNumPaths(fPathGenerator->getNumPaths()) {
|
fNumPaths(fPathGenerator->getNumPaths()) {
|
||||||
const int numGroups = (fNumPaths + kPathsPerGroup - 1) / kPathsPerGroup;
|
const int numGroups = (fNumPaths + kPathsPerGroup - 1) / kPathsPerGroup;
|
||||||
@ -20,7 +20,7 @@ GrPathRange::GrPathRange(GrGpu* gpu,
|
|||||||
|
|
||||||
GrPathRange::GrPathRange(GrGpu* gpu,
|
GrPathRange::GrPathRange(GrGpu* gpu,
|
||||||
int numPaths)
|
int numPaths)
|
||||||
: INHERITED(gpu, kCached_LifeCycle),
|
: INHERITED(gpu),
|
||||||
fNumPaths(numPaths) {
|
fNumPaths(numPaths) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ void GrResourceCache::insertResource(GrGpuResource* resource) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (resource->resourcePriv().getScratchKey().isValid()) {
|
if (resource->resourcePriv().getScratchKey().isValid()) {
|
||||||
SkASSERT(!resource->resourcePriv().isExternal());
|
SkASSERT(!resource->resourcePriv().refsWrappedObjects());
|
||||||
fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
|
fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla
|
|||||||
|
|
||||||
if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
|
if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
|
||||||
// Check whether this resource could still be used as a scratch resource.
|
// Check whether this resource could still be used as a scratch resource.
|
||||||
if (!resource->resourcePriv().isExternal() &&
|
if (!resource->resourcePriv().refsWrappedObjects() &&
|
||||||
resource->resourcePriv().getScratchKey().isValid()) {
|
resource->resourcePriv().getScratchKey().isValid()) {
|
||||||
// We won't purge an existing resource to make room for this one.
|
// We won't purge an existing resource to make room for this one.
|
||||||
if (fBudgetedCount < fMaxCount &&
|
if (fBudgetedCount < fMaxCount &&
|
||||||
@ -661,19 +661,19 @@ void GrResourceCache::validate() const {
|
|||||||
SkASSERT(!resource->getUniqueKey().isValid());
|
SkASSERT(!resource->getUniqueKey().isValid());
|
||||||
++fScratch;
|
++fScratch;
|
||||||
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
|
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
|
||||||
SkASSERT(!resource->resourcePriv().isExternal());
|
SkASSERT(!resource->resourcePriv().refsWrappedObjects());
|
||||||
} else if (resource->resourcePriv().getScratchKey().isValid()) {
|
} else if (resource->resourcePriv().getScratchKey().isValid()) {
|
||||||
SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted() ||
|
SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted() ||
|
||||||
resource->getUniqueKey().isValid());
|
resource->getUniqueKey().isValid());
|
||||||
++fCouldBeScratch;
|
++fCouldBeScratch;
|
||||||
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
|
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
|
||||||
SkASSERT(!resource->resourcePriv().isExternal());
|
SkASSERT(!resource->resourcePriv().refsWrappedObjects());
|
||||||
}
|
}
|
||||||
const GrUniqueKey& uniqueKey = resource->getUniqueKey();
|
const GrUniqueKey& uniqueKey = resource->getUniqueKey();
|
||||||
if (uniqueKey.isValid()) {
|
if (uniqueKey.isValid()) {
|
||||||
++fContent;
|
++fContent;
|
||||||
SkASSERT(fUniqueHash->find(uniqueKey) == resource);
|
SkASSERT(fUniqueHash->find(uniqueKey) == resource);
|
||||||
SkASSERT(!resource->resourcePriv().isExternal());
|
SkASSERT(!resource->resourcePriv().refsWrappedObjects());
|
||||||
SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
|
SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +188,7 @@ public:
|
|||||||
int fNumNonPurgeable;
|
int fNumNonPurgeable;
|
||||||
|
|
||||||
int fScratch;
|
int fScratch;
|
||||||
int fExternal;
|
int fWrapped;
|
||||||
int fBorrowed;
|
|
||||||
int fAdopted;
|
|
||||||
size_t fUnbudgetedSize;
|
size_t fUnbudgetedSize;
|
||||||
|
|
||||||
Stats() { this->reset(); }
|
Stats() { this->reset(); }
|
||||||
@ -200,9 +198,7 @@ public:
|
|||||||
fNumPurgeable = 0;
|
fNumPurgeable = 0;
|
||||||
fNumNonPurgeable = 0;
|
fNumNonPurgeable = 0;
|
||||||
fScratch = 0;
|
fScratch = 0;
|
||||||
fExternal = 0;
|
fWrapped = 0;
|
||||||
fBorrowed = 0;
|
|
||||||
fAdopted = 0;
|
|
||||||
fUnbudgetedSize = 0;
|
fUnbudgetedSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,14 +206,8 @@ public:
|
|||||||
if (resource->cacheAccess().isScratch()) {
|
if (resource->cacheAccess().isScratch()) {
|
||||||
++fScratch;
|
++fScratch;
|
||||||
}
|
}
|
||||||
if (resource->resourcePriv().isExternal()) {
|
if (resource->resourcePriv().refsWrappedObjects()) {
|
||||||
++fExternal;
|
++fWrapped;
|
||||||
}
|
|
||||||
if (resource->cacheAccess().isBorrowed()) {
|
|
||||||
++fBorrowed;
|
|
||||||
}
|
|
||||||
if (resource->cacheAccess().isAdopted()) {
|
|
||||||
++fAdopted;
|
|
||||||
}
|
}
|
||||||
if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
|
if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
|
||||||
fUnbudgetedSize += resource->gpuMemorySize();
|
fUnbudgetedSize += resource->gpuMemorySize();
|
||||||
|
@ -52,9 +52,9 @@ public:
|
|||||||
GrUniqueKey* key);
|
GrUniqueKey* key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GrStencilAttachment(GrGpu* gpu, LifeCycle lifeCycle, int width, int height, int bits,
|
GrStencilAttachment(GrGpu* gpu, int width, int height, int bits,
|
||||||
int sampleCnt)
|
int sampleCnt)
|
||||||
: GrGpuResource(gpu, lifeCycle)
|
: GrGpuResource(gpu)
|
||||||
, fWidth(width)
|
, fWidth(width)
|
||||||
, fHeight(height)
|
, fHeight(height)
|
||||||
, fBits(bits)
|
, fBits(bits)
|
||||||
|
@ -86,16 +86,10 @@ GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
|
GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType,
|
||||||
GrSLType samplerType, bool wasMipMapDataProvided)
|
bool wasMipMapDataProvided)
|
||||||
: INHERITED(gpu, lifeCycle, desc)
|
: INHERITED(gpu, desc)
|
||||||
, fSamplerType(samplerType) {
|
, fSamplerType(samplerType) {
|
||||||
if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
|
|
||||||
GrScratchKey key;
|
|
||||||
GrTexturePriv::ComputeScratchKey(desc, &key);
|
|
||||||
this->setScratchKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wasMipMapDataProvided) {
|
if (wasMipMapDataProvided) {
|
||||||
fMipMapsStatus = kValid_MipMapsStatus;
|
fMipMapsStatus = kValid_MipMapsStatus;
|
||||||
fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeight);
|
fMaxMipMapLevel = SkMipMap::ComputeLevelCount(fDesc.fWidth, fDesc.fHeight);
|
||||||
@ -105,6 +99,12 @@ GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GrTexture::computeScratchKey(GrScratchKey* key) const {
|
||||||
|
if (!GrPixelConfigIsCompressed(fDesc.fConfig)) {
|
||||||
|
GrTexturePriv::ComputeScratchKey(fDesc, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
|
void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
|
||||||
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
|
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ GrGLBuffer::GrGLBuffer(GrGLGpu* gpu, size_t size, GrBufferType intendedType,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
VALIDATE();
|
VALIDATE();
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GrGLGpu* GrGLBuffer::glGpu() const {
|
inline GrGLGpu* GrGLBuffer::glGpu() const {
|
||||||
|
@ -649,13 +649,10 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ownership) {
|
if (kAdopt_GrWrapOwnership == ownership) {
|
||||||
case kAdopt_GrWrapOwnership:
|
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
|
||||||
idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle;
|
} else {
|
||||||
break;
|
idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed;
|
||||||
case kBorrow_GrWrapOwnership:
|
|
||||||
idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
|
surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags;
|
||||||
@ -676,13 +673,12 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
|
|||||||
GrGLTexture* texture = nullptr;
|
GrGLTexture* texture = nullptr;
|
||||||
if (renderTarget) {
|
if (renderTarget) {
|
||||||
GrGLRenderTarget::IDDesc rtIDDesc;
|
GrGLRenderTarget::IDDesc rtIDDesc;
|
||||||
if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle,
|
if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, &rtIDDesc)) {
|
||||||
idDesc.fInfo, &rtIDDesc)) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
texture = new GrGLTextureRenderTarget(this, surfDesc, idDesc, rtIDDesc);
|
texture = GrGLTextureRenderTarget::CreateWrapped(this, surfDesc, idDesc, rtIDDesc);
|
||||||
} else {
|
} else {
|
||||||
texture = new GrGLTexture(this, surfDesc, idDesc);
|
texture = GrGLTexture::CreateWrapped(this, surfDesc, idDesc);
|
||||||
}
|
}
|
||||||
if (nullptr == texture) {
|
if (nullptr == texture) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -697,13 +693,10 @@ GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
|
|||||||
idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
|
idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
|
||||||
idDesc.fMSColorRenderbufferID = 0;
|
idDesc.fMSColorRenderbufferID = 0;
|
||||||
idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
|
idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID;
|
||||||
switch (ownership) {
|
if (kAdopt_GrWrapOwnership == ownership) {
|
||||||
case kAdopt_GrWrapOwnership:
|
idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
|
||||||
idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle;
|
} else {
|
||||||
break;
|
idDesc.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed;
|
||||||
case kBorrow_GrWrapOwnership:
|
|
||||||
idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig;
|
idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig;
|
||||||
|
|
||||||
@ -765,8 +758,7 @@ GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrGLRenderTarget::IDDesc rtIDDesc;
|
GrGLRenderTarget::IDDesc rtIDDesc;
|
||||||
if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle,
|
if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) {
|
||||||
texInfo, &rtIDDesc)) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
|
return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
|
||||||
@ -1487,13 +1479,12 @@ static bool renderbuffer_storage_msaa(const GrGLContext& ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc,
|
bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrGLTextureInfo& texInfo,
|
const GrGLTextureInfo& texInfo,
|
||||||
GrGLRenderTarget::IDDesc* idDesc) {
|
GrGLRenderTarget::IDDesc* idDesc) {
|
||||||
idDesc->fMSColorRenderbufferID = 0;
|
idDesc->fMSColorRenderbufferID = 0;
|
||||||
idDesc->fRTFBOID = 0;
|
idDesc->fRTFBOID = 0;
|
||||||
|
idDesc->fRTFBOOwnership = GrBackendObjectOwnership::kOwned;
|
||||||
idDesc->fTexFBOID = 0;
|
idDesc->fTexFBOID = 0;
|
||||||
idDesc->fLifeCycle = lifeCycle;
|
|
||||||
idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps().msFBOType() &&
|
idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps().msFBOType() &&
|
||||||
desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_SampleConfig :
|
desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_SampleConfig :
|
||||||
GrRenderTarget::kUnified_SampleConfig;
|
GrRenderTarget::kUnified_SampleConfig;
|
||||||
@ -1605,12 +1596,11 @@ static size_t as_size_t(int x) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface,
|
static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface) {
|
||||||
GrGpuResource::LifeCycle lifeCycle) {
|
|
||||||
GrGLTexture::IDDesc idDesc;
|
GrGLTexture::IDDesc idDesc;
|
||||||
idDesc.fInfo.fID = 0;
|
idDesc.fInfo.fID = 0;
|
||||||
GR_GL_CALL(interface, GenTextures(1, &idDesc.fInfo.fID));
|
GR_GL_CALL(interface, GenTextures(1, &idDesc.fInfo.fID));
|
||||||
idDesc.fLifeCycle = lifeCycle;
|
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
|
||||||
// When we create the texture, we only
|
// When we create the texture, we only
|
||||||
// create GL_TEXTURE_2D at the moment.
|
// create GL_TEXTURE_2D at the moment.
|
||||||
// External clients can do something different.
|
// External clients can do something different.
|
||||||
@ -1645,7 +1635,7 @@ static void set_initial_texture_params(const GrGLInterface* interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) {
|
const SkTArray<GrMipLevel>& texels) {
|
||||||
// We fail if the MSAA was requested and is not available.
|
// We fail if the MSAA was requested and is not available.
|
||||||
if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
|
if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) {
|
||||||
@ -1656,7 +1646,7 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
|||||||
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
|
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
|
||||||
|
|
||||||
GrGLTexture::IDDesc idDesc;
|
GrGLTexture::IDDesc idDesc;
|
||||||
idDesc.fLifeCycle = lifeCycle;
|
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
|
||||||
GrGLTexture::TexParams initialTexParams;
|
GrGLTexture::TexParams initialTexParams;
|
||||||
if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexParams, texels)) {
|
if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexParams, texels)) {
|
||||||
return return_null_texture();
|
return return_null_texture();
|
||||||
@ -1668,17 +1658,17 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
|||||||
GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0));
|
GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0));
|
||||||
GrGLRenderTarget::IDDesc rtIDDesc;
|
GrGLRenderTarget::IDDesc rtIDDesc;
|
||||||
|
|
||||||
if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtIDDesc)) {
|
if (!this->createRenderTargetObjects(desc, idDesc.fInfo, &rtIDDesc)) {
|
||||||
GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
|
GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
|
||||||
return return_null_texture();
|
return return_null_texture();
|
||||||
}
|
}
|
||||||
tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc);
|
tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc);
|
||||||
} else {
|
} else {
|
||||||
bool wasMipMapDataProvided = false;
|
bool wasMipMapDataProvided = false;
|
||||||
if (texels.count() > 1) {
|
if (texels.count() > 1) {
|
||||||
wasMipMapDataProvided = true;
|
wasMipMapDataProvided = true;
|
||||||
}
|
}
|
||||||
tex = new GrGLTexture(this, desc, idDesc, wasMipMapDataProvided);
|
tex = new GrGLTexture(this, budgeted, desc, idDesc, wasMipMapDataProvided);
|
||||||
}
|
}
|
||||||
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
|
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
|
||||||
#ifdef TRACE_TEXTURE_CREATION
|
#ifdef TRACE_TEXTURE_CREATION
|
||||||
@ -1689,14 +1679,14 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) {
|
const SkTArray<GrMipLevel>& texels) {
|
||||||
// Make sure that we're not flipping Y.
|
// Make sure that we're not flipping Y.
|
||||||
if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
|
if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) {
|
||||||
return return_null_texture();
|
return return_null_texture();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface(), lifeCycle);
|
GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface());
|
||||||
if (!idDesc.fInfo.fID) {
|
if (!idDesc.fInfo.fID) {
|
||||||
return return_null_texture();
|
return return_null_texture();
|
||||||
}
|
}
|
||||||
@ -1713,7 +1703,7 @@ GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrGLTexture* tex;
|
GrGLTexture* tex;
|
||||||
tex = new GrGLTexture(this, desc, idDesc);
|
tex = new GrGLTexture(this, budgeted, desc, idDesc);
|
||||||
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
|
tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
|
||||||
#ifdef TRACE_TEXTURE_CREATION
|
#ifdef TRACE_TEXTURE_CREATION
|
||||||
SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n",
|
SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n",
|
||||||
|
@ -126,10 +126,10 @@ private:
|
|||||||
|
|
||||||
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
|
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
|
||||||
|
|
||||||
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
|
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) override;
|
const SkTArray<GrMipLevel>& texels) override;
|
||||||
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) override;
|
const SkTArray<GrMipLevel>& texels) override;
|
||||||
|
|
||||||
GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
|
GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
|
||||||
@ -347,8 +347,8 @@ private:
|
|||||||
int left = 0, int top = 0,
|
int left = 0, int top = 0,
|
||||||
int width = -1, int height = -1);
|
int width = -1, int height = -1);
|
||||||
|
|
||||||
bool createRenderTargetObjects(const GrSurfaceDesc&, GrGpuResource::LifeCycle lifeCycle,
|
bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
|
||||||
const GrGLTextureInfo& texInfo, GrGLRenderTarget::IDDesc*);
|
GrGLRenderTarget::IDDesc*);
|
||||||
|
|
||||||
enum TempFBOTarget {
|
enum TempFBOTarget {
|
||||||
kSrc_TempFBOTarget,
|
kSrc_TempFBOTarget,
|
||||||
|
@ -330,11 +330,11 @@ GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLPath::onRelease() {
|
void GrGLPath::onRelease() {
|
||||||
if (0 != fPathID && this->shouldFreeResources()) {
|
if (0 != fPathID) {
|
||||||
static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fPathID, 1);
|
static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fPathID, 1);
|
||||||
fPathID = 0;
|
fPathID = 0;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ GrGLPathRange::GrGLPathRange(GrGLGpu* gpu, PathGenerator* pathGenerator, const G
|
|||||||
fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())),
|
fBasePathID(gpu->glPathRendering()->genPaths(this->getNumPaths())),
|
||||||
fGpuMemorySize(0) {
|
fGpuMemorySize(0) {
|
||||||
this->init();
|
this->init();
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLPathRange::GrGLPathRange(GrGLGpu* gpu,
|
GrGLPathRange::GrGLPathRange(GrGLGpu* gpu,
|
||||||
@ -29,7 +29,7 @@ GrGLPathRange::GrGLPathRange(GrGLGpu* gpu,
|
|||||||
fBasePathID(basePathID),
|
fBasePathID(basePathID),
|
||||||
fGpuMemorySize(gpuMemorySize) {
|
fGpuMemorySize(gpuMemorySize) {
|
||||||
this->init();
|
this->init();
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLPathRange::init() {
|
void GrGLPathRange::init() {
|
||||||
@ -101,7 +101,7 @@ void GrGLPathRange::onInitPath(int index, const SkPath& origSkPath) const {
|
|||||||
void GrGLPathRange::onRelease() {
|
void GrGLPathRange::onRelease() {
|
||||||
SkASSERT(this->getGpu());
|
SkASSERT(this->getGpu());
|
||||||
|
|
||||||
if (0 != fBasePathID && this->shouldFreeResources()) {
|
if (0 != fBasePathID) {
|
||||||
static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID,
|
static_cast<GrGLGpu*>(this->getGpu())->glPathRendering()->deletePaths(fBasePathID,
|
||||||
this->getNumPaths());
|
this->getNumPaths());
|
||||||
fBasePathID = 0;
|
fBasePathID = 0;
|
||||||
|
@ -7,29 +7,31 @@
|
|||||||
|
|
||||||
#include "GrGLRenderTarget.h"
|
#include "GrGLRenderTarget.h"
|
||||||
|
|
||||||
#include "GrRenderTargetPriv.h"
|
|
||||||
#include "GrGLGpu.h"
|
#include "GrGLGpu.h"
|
||||||
#include "GrGLUtil.h"
|
#include "GrGLUtil.h"
|
||||||
|
#include "GrGpuResourcePriv.h"
|
||||||
|
#include "GrRenderTargetPriv.h"
|
||||||
#include "SkTraceMemoryDump.h"
|
#include "SkTraceMemoryDump.h"
|
||||||
|
|
||||||
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
|
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
|
||||||
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
|
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
|
||||||
|
|
||||||
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
||||||
|
// Constructor for wrapped render targets.
|
||||||
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
|
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
const IDDesc& idDesc,
|
const IDDesc& idDesc,
|
||||||
GrGLStencilAttachment* stencil)
|
GrGLStencilAttachment* stencil)
|
||||||
: GrSurface(gpu, idDesc.fLifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) {
|
, INHERITED(gpu, desc, idDesc.fSampleConfig, stencil) {
|
||||||
this->init(desc, idDesc);
|
this->init(desc, idDesc);
|
||||||
this->registerWithCache();
|
this->registerWithCacheWrapped();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
|
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc,
|
||||||
Derived)
|
const IDDesc& idDesc)
|
||||||
: GrSurface(gpu, idDesc.fLifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) {
|
, INHERITED(gpu, desc, idDesc.fSampleConfig) {
|
||||||
this->init(desc, idDesc);
|
this->init(desc, idDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
|
|||||||
fRTFBOID = idDesc.fRTFBOID;
|
fRTFBOID = idDesc.fRTFBOID;
|
||||||
fTexFBOID = idDesc.fTexFBOID;
|
fTexFBOID = idDesc.fTexFBOID;
|
||||||
fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
|
fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
|
||||||
fRTLifecycle = idDesc.fLifeCycle;
|
fRTFBOOwnership = idDesc.fRTFBOOwnership;
|
||||||
|
|
||||||
fViewport.fLeft = 0;
|
fViewport.fLeft = 0;
|
||||||
fViewport.fBottom = 0;
|
fViewport.fBottom = 0;
|
||||||
@ -127,7 +129,7 @@ bool GrGLRenderTarget::completeStencilAttachment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrGLRenderTarget::onRelease() {
|
void GrGLRenderTarget::onRelease() {
|
||||||
if (kBorrowed_LifeCycle != fRTLifecycle) {
|
if (GrBackendObjectOwnership::kBorrowed != fRTFBOOwnership) {
|
||||||
if (fTexFBOID) {
|
if (fTexFBOID) {
|
||||||
GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
|
GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
|
||||||
}
|
}
|
||||||
@ -156,6 +158,13 @@ GrGLGpu* GrGLRenderTarget::getGLGpu() const {
|
|||||||
return static_cast<GrGLGpu*>(this->getGpu());
|
return static_cast<GrGLGpu*>(this->getGpu());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GrGLRenderTarget::canAttemptStencilAttachment() const {
|
||||||
|
// When we have not created the FBO ID we do not attempt to modify its attachments.
|
||||||
|
// Direct GrGLRenderTarget instances are always created with CreateWrapped.
|
||||||
|
SkASSERT(this->resourcePriv().refsWrappedObjects());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
|
void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
|
||||||
// Don't log the backing texture's contribution to the memory size. This will be handled by the
|
// Don't log the backing texture's contribution to the memory size. This will be handled by the
|
||||||
// texture object.
|
// texture object.
|
||||||
|
@ -24,9 +24,9 @@ public:
|
|||||||
|
|
||||||
struct IDDesc {
|
struct IDDesc {
|
||||||
GrGLuint fRTFBOID;
|
GrGLuint fRTFBOID;
|
||||||
|
GrBackendObjectOwnership fRTFBOOwnership;
|
||||||
GrGLuint fTexFBOID;
|
GrGLuint fTexFBOID;
|
||||||
GrGLuint fMSColorRenderbufferID;
|
GrGLuint fMSColorRenderbufferID;
|
||||||
GrGpuResource::LifeCycle fLifeCycle;
|
|
||||||
GrRenderTarget::SampleConfig fSampleConfig;
|
GrRenderTarget::SampleConfig fSampleConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,21 +61,15 @@ public:
|
|||||||
|
|
||||||
GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; }
|
GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; }
|
||||||
|
|
||||||
/** When we don't own the FBO ID we don't attempt to modify its attachments. */
|
bool canAttemptStencilAttachment() const override;
|
||||||
bool canAttemptStencilAttachment() const override {
|
|
||||||
return kCached_LifeCycle == fRTLifecycle || kUncached_LifeCycle == fRTLifecycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
|
// GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
|
||||||
// components seperately.
|
// components seperately.
|
||||||
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
|
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// The public constructor registers this object with the cache. However, only the most derived
|
// Constructor for subclasses.
|
||||||
// class should register with the cache. This constructor does not do the registration and
|
GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
|
||||||
// rather moves that burden onto the derived class.
|
|
||||||
enum Derived { kDerived };
|
|
||||||
GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
|
|
||||||
|
|
||||||
void init(const GrSurfaceDesc&, const IDDesc&);
|
void init(const GrSurfaceDesc&, const IDDesc&);
|
||||||
|
|
||||||
@ -86,8 +80,7 @@ protected:
|
|||||||
size_t onGpuMemorySize() const override;
|
size_t onGpuMemorySize() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This ctor is used only for creating wrapped render targets and is only called for the static
|
// Constructor for instances wrapping backend objects.
|
||||||
// create function CreateWrapped(...).
|
|
||||||
GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
|
GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
|
||||||
|
|
||||||
GrGLGpu* getGLGpu() const;
|
GrGLGpu* getGLGpu() const;
|
||||||
@ -103,9 +96,7 @@ private:
|
|||||||
GrGLuint fTexFBOID;
|
GrGLuint fTexFBOID;
|
||||||
GrGLuint fMSColorRenderbufferID;
|
GrGLuint fMSColorRenderbufferID;
|
||||||
|
|
||||||
// We track this separately from GrGpuResource because this may be both a texture and a render
|
GrBackendObjectOwnership fRTFBOOwnership;
|
||||||
// target, and the texture may be wrapped while the render target is not.
|
|
||||||
LifeCycle fRTLifecycle;
|
|
||||||
|
|
||||||
// when we switch to this render target we want to set the viewport to
|
// when we switch to this render target we want to set the viewport to
|
||||||
// only render to content area (as opposed to the whole allocation) and
|
// only render to content area (as opposed to the whole allocation) and
|
||||||
|
@ -19,7 +19,7 @@ size_t GrGLStencilAttachment::onGpuMemorySize() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrGLStencilAttachment::onRelease() {
|
void GrGLStencilAttachment::onRelease() {
|
||||||
if (0 != fRenderbufferID && this->shouldFreeResources()) {
|
if (0 != fRenderbufferID) {
|
||||||
GrGLGpu* gpuGL = (GrGLGpu*) this->getGpu();
|
GrGLGpu* gpuGL = (GrGLGpu*) this->getGpu();
|
||||||
const GrGLInterface* gl = gpuGL->glInterface();
|
const GrGLInterface* gl = gpuGL->glInterface();
|
||||||
GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
|
GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
|
||||||
|
@ -24,20 +24,19 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct IDDesc {
|
struct IDDesc {
|
||||||
IDDesc() : fRenderbufferID(0), fLifeCycle(kCached_LifeCycle) {}
|
IDDesc() : fRenderbufferID(0) {}
|
||||||
GrGLuint fRenderbufferID;
|
GrGLuint fRenderbufferID;
|
||||||
GrGpuResource::LifeCycle fLifeCycle;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GrGLStencilAttachment(GrGpu* gpu,
|
GrGLStencilAttachment(GrGpu* gpu,
|
||||||
const IDDesc& idDesc,
|
const IDDesc& idDesc,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
const Format& format)
|
const Format& format)
|
||||||
: GrStencilAttachment(gpu, idDesc.fLifeCycle, width, height, format.fStencilBits, sampleCnt)
|
: GrStencilAttachment(gpu, width, height, format.fStencilBits, sampleCnt)
|
||||||
, fFormat(format)
|
, fFormat(format)
|
||||||
, fRenderbufferID(idDesc.fRenderbufferID) {
|
, fRenderbufferID(idDesc.fRenderbufferID) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLuint renderbufferID() const {
|
GrGLuint renderbufferID() const {
|
||||||
|
@ -26,24 +26,33 @@ inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrG
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
||||||
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
|
GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
|
||||||
: GrSurface(gpu, idDesc.fLifeCycle, desc)
|
const IDDesc& idDesc)
|
||||||
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) {
|
: GrSurface(gpu, desc)
|
||||||
|
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
|
||||||
this->init(desc, idDesc);
|
this->init(desc, idDesc);
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
|
GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
|
||||||
|
const IDDesc& idDesc,
|
||||||
bool wasMipMapDataProvided)
|
bool wasMipMapDataProvided)
|
||||||
: GrSurface(gpu, idDesc.fLifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
|
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
|
||||||
this->init(desc, idDesc);
|
this->init(desc, idDesc);
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
|
GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc)
|
||||||
: GrSurface(gpu, idDesc.fLifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) {
|
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
|
||||||
|
this->init(desc, idDesc);
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
|
||||||
|
: GrSurface(gpu, desc)
|
||||||
|
, INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
|
||||||
this->init(desc, idDesc);
|
this->init(desc, idDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +61,12 @@ void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
|
|||||||
fTexParams.invalidate();
|
fTexParams.invalidate();
|
||||||
fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
|
fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
|
||||||
fInfo = idDesc.fInfo;
|
fInfo = idDesc.fInfo;
|
||||||
fTextureIDLifecycle = idDesc.fLifeCycle;
|
fTextureIDOwnership = idDesc.fOwnership;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGLTexture::onRelease() {
|
void GrGLTexture::onRelease() {
|
||||||
if (fInfo.fID) {
|
if (fInfo.fID) {
|
||||||
if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) {
|
if (GrBackendObjectOwnership::kBorrowed != fTextureIDOwnership) {
|
||||||
GL_CALL(DeleteTextures(1, &fInfo.fID));
|
GL_CALL(DeleteTextures(1, &fInfo.fID));
|
||||||
}
|
}
|
||||||
fInfo.fID = 0;
|
fInfo.fID = 0;
|
||||||
@ -86,3 +95,9 @@ void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
|
|||||||
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
|
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
|
||||||
texture_id.c_str());
|
texture_id.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GrGLTexture* GrGLTexture::CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
|
||||||
|
const IDDesc& idDesc) {
|
||||||
|
return new GrGLTexture(gpu, kWrapped, desc, idDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
class GrGLGpu;
|
class GrGLGpu;
|
||||||
|
|
||||||
class GrGLTexture : public GrTexture {
|
class GrGLTexture : public GrTexture {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct TexParams {
|
struct TexParams {
|
||||||
GrGLenum fMinFilter;
|
GrGLenum fMinFilter;
|
||||||
@ -31,11 +30,11 @@ public:
|
|||||||
|
|
||||||
struct IDDesc {
|
struct IDDesc {
|
||||||
GrGLTextureInfo fInfo;
|
GrGLTextureInfo fInfo;
|
||||||
GrGpuResource::LifeCycle fLifeCycle;
|
GrBackendObjectOwnership fOwnership;
|
||||||
};
|
};
|
||||||
|
GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&);
|
||||||
GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
|
GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&,
|
||||||
GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
|
bool wasMipMapDataProvided);
|
||||||
|
|
||||||
GrBackendObject getTextureHandle() const override;
|
GrBackendObject getTextureHandle() const override;
|
||||||
|
|
||||||
@ -57,12 +56,14 @@ public:
|
|||||||
|
|
||||||
GrGLenum target() const { return fInfo.fTarget; }
|
GrGLenum target() const { return fInfo.fTarget; }
|
||||||
|
|
||||||
|
static GrGLTexture* CreateWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
|
||||||
protected:
|
protected:
|
||||||
// The public constructor registers this object with the cache. However, only the most derived
|
// Constructor for subclasses.
|
||||||
// class should register with the cache. This constructor does not do the registration and
|
GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
|
||||||
// rather moves that burden onto the derived class.
|
|
||||||
enum Derived { kDerived };
|
enum Wrapped { kWrapped };
|
||||||
GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
|
// Constructor for instances wrapping backend objects.
|
||||||
|
GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
|
||||||
|
|
||||||
void init(const GrSurfaceDesc&, const IDDesc&);
|
void init(const GrSurfaceDesc&, const IDDesc&);
|
||||||
|
|
||||||
@ -77,10 +78,7 @@ private:
|
|||||||
// Holds the texture target and ID. A pointer to this may be shared to external clients for
|
// Holds the texture target and ID. A pointer to this may be shared to external clients for
|
||||||
// direct interaction with the GL object.
|
// direct interaction with the GL object.
|
||||||
GrGLTextureInfo fInfo;
|
GrGLTextureInfo fInfo;
|
||||||
|
GrBackendObjectOwnership fTextureIDOwnership;
|
||||||
// We track this separately from GrGpuResource because this may be both a texture and a render
|
|
||||||
// target, and the texture may be wrapped while the render target is not.
|
|
||||||
LifeCycle fTextureIDLifecycle;
|
|
||||||
|
|
||||||
typedef GrTexture INHERITED;
|
typedef GrTexture INHERITED;
|
||||||
};
|
};
|
||||||
|
@ -37,3 +37,16 @@ void GrGLTextureRenderTarget::dumpMemoryStatistics(
|
|||||||
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
|
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
|
||||||
texture_id.c_str());
|
texture_id.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
|
||||||
|
// The RT FBO of GrGLTextureRenderTarget is never created from a
|
||||||
|
// wrapped FBO.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLTextureRenderTarget* GrGLTextureRenderTarget::CreateWrapped(GrGLGpu* gpu,
|
||||||
|
const GrSurfaceDesc& desc,
|
||||||
|
const GrGLTexture::IDDesc& texIDDesc,
|
||||||
|
const GrGLRenderTarget::IDDesc& rtIDDesc) {
|
||||||
|
return new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc);
|
||||||
|
}
|
||||||
|
@ -26,17 +26,23 @@ public:
|
|||||||
// We're virtually derived from GrSurface (via both GrGLTexture and GrGLRenderTarget) so its
|
// We're virtually derived from GrSurface (via both GrGLTexture and GrGLRenderTarget) so its
|
||||||
// constructor must be explicitly called.
|
// constructor must be explicitly called.
|
||||||
GrGLTextureRenderTarget(GrGLGpu* gpu,
|
GrGLTextureRenderTarget(GrGLGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
const GrGLTexture::IDDesc& texIDDesc,
|
const GrGLTexture::IDDesc& texIDDesc,
|
||||||
const GrGLRenderTarget::IDDesc& rtIDDesc)
|
const GrGLRenderTarget::IDDesc& rtIDDesc)
|
||||||
: GrSurface(gpu, texIDDesc.fLifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrGLTexture(gpu, desc, texIDDesc, GrGLTexture::kDerived)
|
, GrGLTexture(gpu, desc, texIDDesc)
|
||||||
, GrGLRenderTarget(gpu, desc, rtIDDesc, GrGLRenderTarget::kDerived) {
|
, GrGLRenderTarget(gpu, desc, rtIDDesc) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool canAttemptStencilAttachment() const override;
|
||||||
|
|
||||||
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
|
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
|
||||||
|
|
||||||
|
static GrGLTextureRenderTarget* CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
|
||||||
|
const GrGLTexture::IDDesc& texIDDesc,
|
||||||
|
const GrGLRenderTarget::IDDesc& rtIDDesc);
|
||||||
protected:
|
protected:
|
||||||
void onAbandon() override {
|
void onAbandon() override {
|
||||||
GrGLRenderTarget::onAbandon();
|
GrGLRenderTarget::onAbandon();
|
||||||
@ -49,6 +55,17 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Constructor for instances wrapping backend objects.
|
||||||
|
GrGLTextureRenderTarget(GrGLGpu* gpu,
|
||||||
|
const GrSurfaceDesc& desc,
|
||||||
|
const GrGLTexture::IDDesc& texIDDesc,
|
||||||
|
const GrGLRenderTarget::IDDesc& rtIDDesc)
|
||||||
|
: GrSurface(gpu, desc)
|
||||||
|
, GrGLTexture(gpu, desc, texIDDesc)
|
||||||
|
, GrGLRenderTarget(gpu, desc, rtIDDesc) {
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
|
}
|
||||||
|
|
||||||
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
|
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
|
||||||
size_t onGpuMemorySize() const override {
|
size_t onGpuMemorySize() const override {
|
||||||
return GrGLRenderTarget::onGpuMemorySize();
|
return GrGLRenderTarget::onGpuMemorySize();
|
||||||
|
@ -438,7 +438,7 @@ bool GrVkGpu::uploadTexData(GrVkTexture* tex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
|
GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) {
|
const SkTArray<GrMipLevel>& texels) {
|
||||||
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
|
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
|
||||||
|
|
||||||
@ -493,10 +493,10 @@ GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::Li
|
|||||||
|
|
||||||
GrVkTexture* tex;
|
GrVkTexture* tex;
|
||||||
if (renderTarget) {
|
if (renderTarget) {
|
||||||
tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, desc, lifeCycle,
|
tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, budgeted, desc,
|
||||||
imageDesc);
|
imageDesc);
|
||||||
} else {
|
} else {
|
||||||
tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc);
|
tex = GrVkTexture::CreateNewTexture(this, budgeted, desc, imageDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tex) {
|
if (!tex) {
|
||||||
@ -548,10 +548,6 @@ GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership)
|
|
||||||
? GrGpuResource::kAdopted_LifeCycle
|
|
||||||
: GrGpuResource::kBorrowed_LifeCycle;
|
|
||||||
|
|
||||||
GrSurfaceDesc surfDesc;
|
GrSurfaceDesc surfDesc;
|
||||||
// next line relies on GrBackendTextureDesc's flags matching GrTexture's
|
// next line relies on GrBackendTextureDesc's flags matching GrTexture's
|
||||||
surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags;
|
surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags;
|
||||||
@ -567,11 +563,10 @@ GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
|
|||||||
GrVkTexture* texture = nullptr;
|
GrVkTexture* texture = nullptr;
|
||||||
if (renderTarget) {
|
if (renderTarget) {
|
||||||
texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this, surfDesc,
|
texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this, surfDesc,
|
||||||
lifeCycle, format,
|
ownership, format,
|
||||||
info);
|
info);
|
||||||
} else {
|
} else {
|
||||||
texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, lifeCycle, format,
|
texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, format, info);
|
||||||
info);
|
|
||||||
}
|
}
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -590,10 +585,6 @@ GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership)
|
|
||||||
? GrGpuResource::kAdopted_LifeCycle
|
|
||||||
: GrGpuResource::kBorrowed_LifeCycle;
|
|
||||||
|
|
||||||
GrSurfaceDesc desc;
|
GrSurfaceDesc desc;
|
||||||
desc.fConfig = wrapDesc.fConfig;
|
desc.fConfig = wrapDesc.fConfig;
|
||||||
desc.fFlags = kCheckAllocation_GrSurfaceFlag;
|
desc.fFlags = kCheckAllocation_GrSurfaceFlag;
|
||||||
@ -604,7 +595,7 @@ GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
|
|||||||
desc.fOrigin = resolve_origin(wrapDesc.fOrigin);
|
desc.fOrigin = resolve_origin(wrapDesc.fOrigin);
|
||||||
|
|
||||||
GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, desc,
|
GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, desc,
|
||||||
lifeCycle,
|
ownership,
|
||||||
info);
|
info);
|
||||||
if (tgt && wrapDesc.fStencilBits) {
|
if (tgt && wrapDesc.fStencilBits) {
|
||||||
if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeight)) {
|
if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeight)) {
|
||||||
@ -652,7 +643,6 @@ GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(const GrRen
|
|||||||
const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat();
|
const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat();
|
||||||
|
|
||||||
GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this,
|
GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this,
|
||||||
GrGpuResource::kCached_LifeCycle,
|
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
samples,
|
samples,
|
||||||
|
@ -117,10 +117,10 @@ private:
|
|||||||
|
|
||||||
void onResetContext(uint32_t resetBits) override {}
|
void onResetContext(uint32_t resetBits) override {}
|
||||||
|
|
||||||
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
|
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>&) override;
|
const SkTArray<GrMipLevel>&) override;
|
||||||
|
|
||||||
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
|
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted,
|
||||||
const SkTArray<GrMipLevel>&) override { return NULL; }
|
const SkTArray<GrMipLevel>&) override { return NULL; }
|
||||||
|
|
||||||
GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
|
GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
|
||||||
|
@ -13,7 +13,7 @@ GrVkIndexBuffer::GrVkIndexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
|
|||||||
: INHERITED(gpu, desc.fSizeInBytes, kIndex_GrBufferType,
|
: INHERITED(gpu, desc.fSizeInBytes, kIndex_GrBufferType,
|
||||||
desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern, false)
|
desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern, false)
|
||||||
, GrVkBuffer(desc, bufferResource) {
|
, GrVkBuffer(desc, bufferResource) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkIndexBuffer* GrVkIndexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
|
GrVkIndexBuffer* GrVkIndexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
|
||||||
|
@ -22,16 +22,16 @@
|
|||||||
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
||||||
// constructor must be explicitly called.
|
// constructor must be explicitly called.
|
||||||
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImage::Resource* msaaResource,
|
const GrVkImage::Resource* msaaResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView,
|
||||||
const GrVkImageView* resolveAttachmentView)
|
const GrVkImageView* resolveAttachmentView)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
// for the moment we only support 1:1 color to stencil
|
// for the moment we only support 1:1 color to stencil
|
||||||
, GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
|
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
|
||||||
, fFramebuffer(nullptr)
|
, fFramebuffer(nullptr)
|
||||||
, fColorAttachmentView(colorAttachmentView)
|
, fColorAttachmentView(colorAttachmentView)
|
||||||
, fMSAAImageResource(msaaResource)
|
, fMSAAImageResource(msaaResource)
|
||||||
@ -41,7 +41,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
|||||||
// The plus 1 is to account for the resolve texture.
|
// The plus 1 is to account for the resolve texture.
|
||||||
fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct?
|
fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct?
|
||||||
this->createFramebuffer(gpu);
|
this->createFramebuffer(gpu);
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
msaaResource->ref();
|
msaaResource->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,16 +49,14 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
|||||||
// constructor must be explicitly called.
|
// constructor must be explicitly called.
|
||||||
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImage::Resource* msaaResource,
|
const GrVkImage::Resource* msaaResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView,
|
||||||
const GrVkImageView* resolveAttachmentView,
|
const GrVkImageView* resolveAttachmentView)
|
||||||
Derived)
|
: GrSurface(gpu, desc)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
// for the moment we only support 1:1 color to stencil
|
// for the moment we only support 1:1 color to stencil
|
||||||
, GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
|
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
|
||||||
, fFramebuffer(nullptr)
|
, fFramebuffer(nullptr)
|
||||||
, fColorAttachmentView(colorAttachmentView)
|
, fColorAttachmentView(colorAttachmentView)
|
||||||
, fMSAAImageResource(msaaResource)
|
, fMSAAImageResource(msaaResource)
|
||||||
@ -74,13 +72,13 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
|||||||
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
||||||
// constructor must be explicitly called.
|
// constructor must be explicitly called.
|
||||||
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* colorAttachmentView)
|
const GrVkImageView* colorAttachmentView)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
|
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
|
||||||
, fFramebuffer(nullptr)
|
, fFramebuffer(nullptr)
|
||||||
, fColorAttachmentView(colorAttachmentView)
|
, fColorAttachmentView(colorAttachmentView)
|
||||||
, fMSAAImageResource(nullptr)
|
, fMSAAImageResource(nullptr)
|
||||||
@ -89,20 +87,18 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
|||||||
SkASSERT(!desc.fSampleCnt);
|
SkASSERT(!desc.fSampleCnt);
|
||||||
fColorValuesPerPixel = 1;
|
fColorValuesPerPixel = 1;
|
||||||
this->createFramebuffer(gpu);
|
this->createFramebuffer(gpu);
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
// We're virtually derived from GrSurface (via GrRenderTarget) so its
|
||||||
// constructor must be explicitly called.
|
// constructor must be explicitly called.
|
||||||
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView)
|
||||||
Derived)
|
: GrSurface(gpu, desc)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
|
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
|
||||||
, fFramebuffer(nullptr)
|
, fFramebuffer(nullptr)
|
||||||
, fColorAttachmentView(colorAttachmentView)
|
, fColorAttachmentView(colorAttachmentView)
|
||||||
, fMSAAImageResource(nullptr)
|
, fMSAAImageResource(nullptr)
|
||||||
@ -115,8 +111,8 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
|
|||||||
|
|
||||||
GrVkRenderTarget*
|
GrVkRenderTarget*
|
||||||
GrVkRenderTarget::Create(GrVkGpu* gpu,
|
GrVkRenderTarget::Create(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource) {
|
const GrVkImage::Resource* imageResource) {
|
||||||
VkFormat pixelFormat;
|
VkFormat pixelFormat;
|
||||||
GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
|
GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
|
||||||
@ -172,11 +168,11 @@ GrVkRenderTarget::Create(GrVkGpu* gpu,
|
|||||||
|
|
||||||
GrVkRenderTarget* texRT;
|
GrVkRenderTarget* texRT;
|
||||||
if (msaaResource) {
|
if (msaaResource) {
|
||||||
texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, msaaResource,
|
texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, msaaResource,
|
||||||
colorAttachmentView, resolveAttachmentView);
|
colorAttachmentView, resolveAttachmentView);
|
||||||
msaaResource->unref(gpu);
|
msaaResource->unref(gpu);
|
||||||
} else {
|
} else {
|
||||||
texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource,
|
texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource,
|
||||||
colorAttachmentView);
|
colorAttachmentView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +181,8 @@ GrVkRenderTarget::Create(GrVkGpu* gpu,
|
|||||||
|
|
||||||
GrVkRenderTarget*
|
GrVkRenderTarget*
|
||||||
GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::ImageDesc& imageDesc) {
|
const GrVkImage::ImageDesc& imageDesc) {
|
||||||
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
|
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
|
||||||
|
|
||||||
@ -195,7 +191,7 @@ GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageResource);
|
GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, imageResource);
|
||||||
// Create() will increment the refCount of the image resource if it succeeds
|
// Create() will increment the refCount of the image resource if it succeeds
|
||||||
imageResource->unref(gpu);
|
imageResource->unref(gpu);
|
||||||
return rt;
|
return rt;
|
||||||
@ -204,18 +200,18 @@ GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
|
|||||||
GrVkRenderTarget*
|
GrVkRenderTarget*
|
||||||
GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
GrWrapOwnership ownership,
|
||||||
const GrVkTextureInfo* info) {
|
const GrVkTextureInfo* info) {
|
||||||
SkASSERT(info);
|
SkASSERT(info);
|
||||||
// We can wrap a rendertarget without its allocation, as long as we don't take ownership
|
// We can wrap a rendertarget without its allocation, as long as we don't take ownership
|
||||||
SkASSERT(VK_NULL_HANDLE != info->fImage);
|
SkASSERT(VK_NULL_HANDLE != info->fImage);
|
||||||
SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopted_LifeCycle != lifeCycle);
|
SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownership);
|
||||||
|
|
||||||
GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTiling)
|
GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTiling)
|
||||||
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
||||||
|
|
||||||
const GrVkImage::Resource* imageResource;
|
const GrVkImage::Resource* imageResource;
|
||||||
if (kBorrowed_LifeCycle == lifeCycle) {
|
if (kBorrow_GrWrapOwnership == ownership) {
|
||||||
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
||||||
info->fAlloc,
|
info->fAlloc,
|
||||||
flags,
|
flags,
|
||||||
@ -227,7 +223,7 @@ GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageResource);
|
GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, imageResource);
|
||||||
if (rt) {
|
if (rt) {
|
||||||
rt->fCurrentLayout = info->fImageLayout;
|
rt->fCurrentLayout = info->fImageLayout;
|
||||||
}
|
}
|
||||||
@ -367,12 +363,7 @@ void GrVkRenderTarget::abandonInternalObjects() {
|
|||||||
|
|
||||||
void GrVkRenderTarget::onRelease() {
|
void GrVkRenderTarget::onRelease() {
|
||||||
this->releaseInternalObjects();
|
this->releaseInternalObjects();
|
||||||
if (this->shouldFreeResources()) {
|
this->releaseImage(this->getVkGpu());
|
||||||
this->releaseImage(this->getVkGpu());
|
|
||||||
} else {
|
|
||||||
this->abandonImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
GrRenderTarget::onRelease();
|
GrRenderTarget::onRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,11 @@ struct GrVkTextureInfo;
|
|||||||
|
|
||||||
class GrVkRenderTarget: public GrRenderTarget, public virtual GrVkImage {
|
class GrVkRenderTarget: public GrRenderTarget, public virtual GrVkImage {
|
||||||
public:
|
public:
|
||||||
static GrVkRenderTarget* CreateNewRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkRenderTarget* CreateNewRenderTarget(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::ImageDesc&);
|
const GrVkImage::ImageDesc&);
|
||||||
|
|
||||||
static GrVkRenderTarget* CreateWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkRenderTarget* CreateWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
GrWrapOwnership,
|
||||||
const GrVkTextureInfo*);
|
const GrVkTextureInfo*);
|
||||||
|
|
||||||
~GrVkRenderTarget() override;
|
~GrVkRenderTarget() override;
|
||||||
@ -67,11 +66,9 @@ public:
|
|||||||
void addResources(GrVkCommandBuffer& commandBuffer) const;
|
void addResources(GrVkCommandBuffer& commandBuffer) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum Derived { kDerived };
|
|
||||||
|
|
||||||
GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImage::Resource* msaaImageResource,
|
const GrVkImage::Resource* msaaImageResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView,
|
||||||
@ -79,28 +76,23 @@ protected:
|
|||||||
|
|
||||||
GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImage::Resource* msaaImageResource,
|
const GrVkImage::Resource* msaaImageResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView,
|
||||||
const GrVkImageView* resolveAttachmentView,
|
const GrVkImageView* resolveAttachmentView);
|
||||||
Derived);
|
|
||||||
|
|
||||||
GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* colorAttachmentView);
|
const GrVkImageView* colorAttachmentView);
|
||||||
|
|
||||||
GrVkRenderTarget(GrVkGpu* gpu,
|
GrVkRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView);
|
||||||
Derived);
|
|
||||||
|
|
||||||
static GrVkRenderTarget* Create(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkRenderTarget* Create(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource);
|
const GrVkImage::Resource* imageResource);
|
||||||
|
|
||||||
GrVkGpu* getVkGpu() const;
|
GrVkGpu* getVkGpu() const;
|
||||||
|
@ -14,22 +14,20 @@
|
|||||||
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
|
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
|
||||||
|
|
||||||
GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu,
|
GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const Format& format,
|
const Format& format,
|
||||||
const GrVkImage::ImageDesc& desc,
|
const GrVkImage::ImageDesc& desc,
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* stencilView)
|
const GrVkImageView* stencilView)
|
||||||
: GrStencilAttachment(gpu, lifeCycle, desc.fWidth, desc.fHeight,
|
: GrStencilAttachment(gpu, desc.fWidth, desc.fHeight,
|
||||||
format.fStencilBits, desc.fSamples)
|
format.fStencilBits, desc.fSamples)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, fFormat(format)
|
, fFormat(format)
|
||||||
, fStencilView(stencilView) {
|
, fStencilView(stencilView) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
stencilView->ref();
|
stencilView->ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
|
GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int sampleCnt,
|
int sampleCnt,
|
||||||
@ -59,7 +57,7 @@ GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, lifeCycle, format, imageDesc,
|
GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, format, imageDesc,
|
||||||
imageResource, imageView);
|
imageResource, imageView);
|
||||||
imageResource->unref(gpu);
|
imageResource->unref(gpu);
|
||||||
imageView->unref(gpu);
|
imageView->unref(gpu);
|
||||||
|
@ -24,8 +24,7 @@ public:
|
|||||||
bool fPacked;
|
bool fPacked;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GrVkStencilAttachment* Create(GrVkGpu* gpu, GrGpuResource::LifeCycle lifeCycle,
|
static GrVkStencilAttachment* Create(GrVkGpu* gpu, int width, int height,
|
||||||
int width, int height,
|
|
||||||
int sampleCnt, const Format& format);
|
int sampleCnt, const Format& format);
|
||||||
|
|
||||||
~GrVkStencilAttachment() override;
|
~GrVkStencilAttachment() override;
|
||||||
@ -43,7 +42,6 @@ private:
|
|||||||
size_t onGpuMemorySize() const override;
|
size_t onGpuMemorySize() const override;
|
||||||
|
|
||||||
GrVkStencilAttachment(GrVkGpu* gpu,
|
GrVkStencilAttachment(GrVkGpu* gpu,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const Format& format,
|
const Format& format,
|
||||||
const GrVkImage::ImageDesc&,
|
const GrVkImage::ImageDesc&,
|
||||||
const GrVkImage::Resource*,
|
const GrVkImage::Resource*,
|
||||||
|
@ -16,35 +16,47 @@
|
|||||||
|
|
||||||
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
||||||
GrVkTexture::GrVkTexture(GrVkGpu* gpu,
|
GrVkTexture::GrVkTexture(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* view)
|
const GrVkImageView* view)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, INHERITED(gpu, lifeCycle, desc, kSampler2D_GrSLType,
|
, INHERITED(gpu, desc, kSampler2D_GrSLType,
|
||||||
false) // false because we don't upload MIP data in Vk yet
|
false) // false because we don't upload MIP data in Vk yet
|
||||||
, fTextureView(view) {
|
, fTextureView(view) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrVkTexture::GrVkTexture(GrVkGpu* gpu,
|
||||||
|
Wrapped,
|
||||||
|
const GrSurfaceDesc& desc,
|
||||||
|
const GrVkImage::Resource* imageResource,
|
||||||
|
const GrVkImageView* view)
|
||||||
|
: GrSurface(gpu, desc)
|
||||||
|
, GrVkImage(imageResource)
|
||||||
|
, INHERITED(gpu, desc, kSampler2D_GrSLType,
|
||||||
|
false) // false because we don't upload MIP data in Vk yet
|
||||||
|
, fTextureView(view) {
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
|
||||||
GrVkTexture::GrVkTexture(GrVkGpu* gpu,
|
GrVkTexture::GrVkTexture(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* view,
|
const GrVkImageView* view)
|
||||||
Derived)
|
: GrSurface(gpu, desc)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, INHERITED(gpu, lifeCycle, desc, kSampler2D_GrSLType,
|
, INHERITED(gpu, desc, kSampler2D_GrSLType,
|
||||||
false) // false because we don't upload MIP data in Vk yet
|
false) // false because we don't upload MIP data in Vk yet
|
||||||
, fTextureView(view) {}
|
, fTextureView(view) {}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ResourceType>
|
||||||
GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu,
|
GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu,
|
||||||
|
ResourceType type,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
const GrVkImage::Resource* imageResource) {
|
const GrVkImage::Resource* imageResource) {
|
||||||
VkImage image = imageResource->fImage;
|
VkImage image = imageResource->fImage;
|
||||||
@ -54,11 +66,11 @@ GrVkTexture* GrVkTexture::Create(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GrVkTexture(gpu, desc, lifeCycle, imageResource, imageView);
|
return new GrVkTexture(gpu, type, desc, imageResource, imageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, const GrSurfaceDesc& desc,
|
GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, SkBudgeted budgeted,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
const GrSurfaceDesc& desc,
|
||||||
const GrVkImage::ImageDesc& imageDesc) {
|
const GrVkImage::ImageDesc& imageDesc) {
|
||||||
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT);
|
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT);
|
||||||
|
|
||||||
@ -67,15 +79,16 @@ GrVkTexture* GrVkTexture::CreateNewTexture(GrVkGpu* gpu, const GrSurfaceDesc& de
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTexture* texture = Create(gpu, desc, lifeCycle, imageDesc.fFormat, imageResource);
|
GrVkTexture* texture = Create(gpu, budgeted, desc, imageDesc.fFormat, imageResource);
|
||||||
// Create() will increment the refCount of the image resource if it succeeds
|
// Create() will increment the refCount of the image resource if it succeeds
|
||||||
imageResource->unref(gpu);
|
imageResource->unref(gpu);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, const GrSurfaceDesc& desc,
|
GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
const GrSurfaceDesc& desc,
|
||||||
|
GrWrapOwnership ownership,
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
const GrVkTextureInfo* info) {
|
const GrVkTextureInfo* info) {
|
||||||
SkASSERT(info);
|
SkASSERT(info);
|
||||||
@ -86,7 +99,7 @@ GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, const GrSurfaceDesc
|
|||||||
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
||||||
|
|
||||||
const GrVkImage::Resource* imageResource;
|
const GrVkImage::Resource* imageResource;
|
||||||
if (kBorrowed_LifeCycle == lifeCycle) {
|
if (kBorrow_GrWrapOwnership == ownership) {
|
||||||
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
||||||
info->fAlloc,
|
info->fAlloc,
|
||||||
flags,
|
flags,
|
||||||
@ -98,7 +111,7 @@ GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu, const GrSurfaceDesc
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTexture* texture = Create(gpu, desc, lifeCycle, format, imageResource);
|
GrVkTexture* texture = Create(gpu, kWrapped, desc, format, imageResource);
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture->fCurrentLayout = info->fImageLayout;
|
texture->fCurrentLayout = info->fImageLayout;
|
||||||
}
|
}
|
||||||
@ -120,11 +133,7 @@ void GrVkTexture::onRelease() {
|
|||||||
fTextureView = nullptr;
|
fTextureView = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->shouldFreeResources()) {
|
this->releaseImage(this->getVkGpu());
|
||||||
this->releaseImage(this->getVkGpu());
|
|
||||||
} else {
|
|
||||||
this->abandonImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
INHERITED::onRelease();
|
INHERITED::onRelease();
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,11 @@ struct GrVkTextureInfo;
|
|||||||
|
|
||||||
class GrVkTexture : public GrTexture, public virtual GrVkImage {
|
class GrVkTexture : public GrTexture, public virtual GrVkImage {
|
||||||
public:
|
public:
|
||||||
static GrVkTexture* CreateNewTexture(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkTexture* CreateNewTexture(GrVkGpu*, SkBudgeted budgeted, const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::ImageDesc&);
|
const GrVkImage::ImageDesc&);
|
||||||
|
|
||||||
static GrVkTexture* CreateWrappedTexture(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkTexture* CreateWrappedTexture(GrVkGpu*, const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
GrWrapOwnership,
|
||||||
VkFormat, const GrVkTextureInfo*);
|
VkFormat, const GrVkTextureInfo*);
|
||||||
|
|
||||||
~GrVkTexture() override;
|
~GrVkTexture() override;
|
||||||
@ -35,16 +34,11 @@ public:
|
|||||||
const GrVkImageView* textureView() const { return fTextureView; }
|
const GrVkImageView* textureView() const { return fTextureView; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum Derived { kDerived };
|
GrVkTexture(GrVkGpu*, const GrSurfaceDesc&,
|
||||||
|
|
||||||
GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, GrGpuResource::LifeCycle,
|
|
||||||
const GrVkImage::Resource*, const GrVkImageView* imageView);
|
const GrVkImage::Resource*, const GrVkImageView* imageView);
|
||||||
|
|
||||||
GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, GrGpuResource::LifeCycle,
|
template<typename ResourceType>
|
||||||
const GrVkImage::Resource*, const GrVkImageView* imageView, Derived);
|
static GrVkTexture* Create(GrVkGpu*, ResourceType, const GrSurfaceDesc&, VkFormat,
|
||||||
|
|
||||||
static GrVkTexture* Create(GrVkGpu*, const GrSurfaceDesc&,
|
|
||||||
GrGpuResource::LifeCycle, VkFormat,
|
|
||||||
const GrVkImage::Resource* texImpl);
|
const GrVkImage::Resource* texImpl);
|
||||||
|
|
||||||
GrVkGpu* getVkGpu() const;
|
GrVkGpu* getVkGpu() const;
|
||||||
@ -53,6 +47,13 @@ protected:
|
|||||||
void onRelease() override;
|
void onRelease() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum Wrapped { kWrapped };
|
||||||
|
GrVkTexture(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
|
||||||
|
const GrVkImage::Resource*, const GrVkImageView* imageView);
|
||||||
|
GrVkTexture(GrVkGpu*, Wrapped, const GrSurfaceDesc&,
|
||||||
|
const GrVkImage::Resource*, const GrVkImageView* imageView);
|
||||||
|
|
||||||
|
|
||||||
const GrVkImageView* fTextureView;
|
const GrVkImageView* fTextureView;
|
||||||
|
|
||||||
typedef GrTexture INHERITED;
|
typedef GrTexture INHERITED;
|
||||||
|
@ -16,13 +16,12 @@
|
|||||||
|
|
||||||
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
|
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
|
||||||
|
|
||||||
GrVkTextureRenderTarget*
|
template<typename ResourceType>
|
||||||
GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
|
GrVkTextureRenderTarget* GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
ResourceType resourceType,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
const GrSurfaceDesc& desc,
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
const GrVkImage::Resource* imageResource) {
|
const GrVkImage::Resource* imageResource) {
|
||||||
|
|
||||||
VkImage image = imageResource->fImage;
|
VkImage image = imageResource->fImage;
|
||||||
// Create the texture ImageView
|
// Create the texture ImageView
|
||||||
const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format,
|
const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, format,
|
||||||
@ -99,16 +98,15 @@ GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTextureRenderTarget* texRT;
|
GrVkTextureRenderTarget* texRT;
|
||||||
if (msaaImageResource) {
|
if (msaaImageResource) {
|
||||||
texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle,
|
texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc,
|
||||||
imageResource, imageView, msaaImageResource,
|
imageResource, imageView, msaaImageResource,
|
||||||
colorAttachmentView,
|
colorAttachmentView,
|
||||||
resolveAttachmentView);
|
resolveAttachmentView);
|
||||||
msaaImageResource->unref(gpu);
|
msaaImageResource->unref(gpu);
|
||||||
} else {
|
} else {
|
||||||
texRT = new GrVkTextureRenderTarget(gpu, desc, lifeCycle,
|
texRT = new GrVkTextureRenderTarget(gpu, resourceType, desc,
|
||||||
imageResource, imageView,
|
imageResource, imageView,
|
||||||
colorAttachmentView);
|
colorAttachmentView);
|
||||||
}
|
}
|
||||||
@ -117,9 +115,9 @@ GrVkTextureRenderTarget::Create(GrVkGpu* gpu,
|
|||||||
|
|
||||||
GrVkTextureRenderTarget*
|
GrVkTextureRenderTarget*
|
||||||
GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu,
|
GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
SkBudgeted budgeted,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
const GrSurfaceDesc& desc,
|
||||||
const GrVkImage::ImageDesc& imageDesc) {
|
const GrVkImage::ImageDesc& imageDesc) {
|
||||||
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
|
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
|
||||||
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT);
|
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT);
|
||||||
|
|
||||||
@ -129,8 +127,8 @@ GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, lifeCycle,
|
GrVkTextureRenderTarget* trt = Create(gpu, budgeted, desc, imageDesc.fFormat,
|
||||||
imageDesc.fFormat, imageRsrc);
|
imageRsrc);
|
||||||
// Create() will increment the refCount of the image resource if it succeeds
|
// Create() will increment the refCount of the image resource if it succeeds
|
||||||
imageRsrc->unref(gpu);
|
imageRsrc->unref(gpu);
|
||||||
|
|
||||||
@ -140,7 +138,7 @@ GrVkTextureRenderTarget::CreateNewTextureRenderTarget(GrVkGpu* gpu,
|
|||||||
GrVkTextureRenderTarget*
|
GrVkTextureRenderTarget*
|
||||||
GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
|
GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
GrWrapOwnership ownership,
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
const GrVkTextureInfo* info) {
|
const GrVkTextureInfo* info) {
|
||||||
SkASSERT(info);
|
SkASSERT(info);
|
||||||
@ -151,7 +149,7 @@ GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
|
|||||||
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
|
||||||
|
|
||||||
const GrVkImage::Resource* imageResource;
|
const GrVkImage::Resource* imageResource;
|
||||||
if (kBorrowed_LifeCycle == lifeCycle) {
|
if (kBorrow_GrWrapOwnership == ownership) {
|
||||||
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
imageResource = new GrVkImage::BorrowedResource(info->fImage,
|
||||||
info->fAlloc,
|
info->fAlloc,
|
||||||
flags,
|
flags,
|
||||||
@ -162,9 +160,7 @@ GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
|
|||||||
if (!imageResource) {
|
if (!imageResource) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
GrVkTextureRenderTarget* trt = Create(gpu, kWrapped, desc, format, imageResource);
|
||||||
GrVkTextureRenderTarget* trt = GrVkTextureRenderTarget::Create(gpu, desc, lifeCycle,
|
|
||||||
format, imageResource);
|
|
||||||
if (trt) {
|
if (trt) {
|
||||||
trt->fCurrentLayout = info->fImageLayout;
|
trt->fCurrentLayout = info->fImageLayout;
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ struct GrVkTextureInfo;
|
|||||||
|
|
||||||
class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget {
|
class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget {
|
||||||
public:
|
public:
|
||||||
static GrVkTextureRenderTarget* CreateNewTextureRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
|
static GrVkTextureRenderTarget* CreateNewTextureRenderTarget(GrVkGpu*, SkBudgeted,
|
||||||
GrGpuResource::LifeCycle,
|
const GrSurfaceDesc&,
|
||||||
const GrVkImage::ImageDesc&);
|
const GrVkImage::ImageDesc&);
|
||||||
|
|
||||||
static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*,
|
static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*,
|
||||||
const GrSurfaceDesc&,
|
const GrSurfaceDesc&,
|
||||||
GrGpuResource::LifeCycle,
|
GrWrapOwnership,
|
||||||
VkFormat,
|
VkFormat,
|
||||||
const GrVkTextureInfo*);
|
const GrVkTextureInfo*);
|
||||||
|
|
||||||
@ -47,38 +47,68 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* texView,
|
const GrVkImageView* texView,
|
||||||
const GrVkImage::Resource* msaaResource,
|
const GrVkImage::Resource* msaaResource,
|
||||||
const GrVkImageView* colorAttachmentView,
|
const GrVkImageView* colorAttachmentView,
|
||||||
const GrVkImageView* resolveAttachmentView)
|
const GrVkImageView* resolveAttachmentView)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, GrVkTexture(gpu, desc, lifeCycle, imageResource, texView, GrVkTexture::kDerived)
|
, GrVkTexture(gpu, desc, imageResource, texView)
|
||||||
, GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, msaaResource, colorAttachmentView,
|
, GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView,
|
||||||
resolveAttachmentView, GrVkRenderTarget::kDerived) {
|
resolveAttachmentView) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
||||||
|
SkBudgeted budgeted,
|
||||||
const GrSurfaceDesc& desc,
|
const GrSurfaceDesc& desc,
|
||||||
GrGpuResource::LifeCycle lifeCycle,
|
|
||||||
const GrVkImage::Resource* imageResource,
|
const GrVkImage::Resource* imageResource,
|
||||||
const GrVkImageView* texView,
|
const GrVkImageView* texView,
|
||||||
const GrVkImageView* colorAttachmentView)
|
const GrVkImageView* colorAttachmentView)
|
||||||
: GrSurface(gpu, lifeCycle, desc)
|
: GrSurface(gpu, desc)
|
||||||
, GrVkImage(imageResource)
|
, GrVkImage(imageResource)
|
||||||
, GrVkTexture(gpu, desc, lifeCycle, imageResource, texView, GrVkTexture::kDerived)
|
, GrVkTexture(gpu, desc, imageResource, texView)
|
||||||
, GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, colorAttachmentView,
|
, GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) {
|
||||||
GrVkRenderTarget::kDerived) {
|
this->registerWithCache(budgeted);
|
||||||
this->registerWithCache();
|
}
|
||||||
|
enum Wrapped { kWrapped };
|
||||||
|
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
||||||
|
Wrapped,
|
||||||
|
const GrSurfaceDesc& desc,
|
||||||
|
const GrVkImage::Resource* imageResource,
|
||||||
|
const GrVkImageView* texView,
|
||||||
|
const GrVkImage::Resource* msaaResource,
|
||||||
|
const GrVkImageView* colorAttachmentView,
|
||||||
|
const GrVkImageView* resolveAttachmentView)
|
||||||
|
: GrSurface(gpu, desc)
|
||||||
|
, GrVkImage(imageResource)
|
||||||
|
, GrVkTexture(gpu, desc, imageResource, texView)
|
||||||
|
, GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView,
|
||||||
|
resolveAttachmentView) {
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
}
|
}
|
||||||
|
|
||||||
static GrVkTextureRenderTarget* Create(GrVkGpu*, const GrSurfaceDesc&,
|
GrVkTextureRenderTarget(GrVkGpu* gpu,
|
||||||
GrGpuResource::LifeCycle,
|
Wrapped,
|
||||||
VkFormat format,
|
const GrSurfaceDesc& desc,
|
||||||
|
const GrVkImage::Resource* imageResource,
|
||||||
|
const GrVkImageView* texView,
|
||||||
|
const GrVkImageView* colorAttachmentView)
|
||||||
|
: GrSurface(gpu, desc)
|
||||||
|
, GrVkImage(imageResource)
|
||||||
|
, GrVkTexture(gpu, desc, imageResource, texView)
|
||||||
|
, GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) {
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ResourceType>
|
||||||
|
static GrVkTextureRenderTarget* Create(GrVkGpu*,
|
||||||
|
ResourceType,
|
||||||
|
const GrSurfaceDesc&,
|
||||||
|
VkFormat,
|
||||||
const GrVkImage::Resource* imageResource);
|
const GrVkImage::Resource* imageResource);
|
||||||
|
|
||||||
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
|
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
|
||||||
|
@ -36,7 +36,7 @@ GrVkTransferBuffer::GrVkTransferBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& des
|
|||||||
kXferCpuToGpu_GrBufferType : kXferGpuToCpu_GrBufferType,
|
kXferCpuToGpu_GrBufferType : kXferGpuToCpu_GrBufferType,
|
||||||
kStream_GrAccessPattern, false)
|
kStream_GrAccessPattern, false)
|
||||||
, GrVkBuffer(desc, bufferResource) {
|
, GrVkBuffer(desc, bufferResource) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrVkTransferBuffer::onRelease() {
|
void GrVkTransferBuffer::onRelease() {
|
||||||
|
@ -13,7 +13,7 @@ GrVkVertexBuffer::GrVkVertexBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
|
|||||||
: INHERITED(gpu, desc.fSizeInBytes, kVertex_GrBufferType,
|
: INHERITED(gpu, desc.fSizeInBytes, kVertex_GrBufferType,
|
||||||
desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern, false)
|
desc.fDynamic ? kDynamic_GrAccessPattern : kStatic_GrAccessPattern, false)
|
||||||
, GrVkBuffer(desc, bufferResource) {
|
, GrVkBuffer(desc, bufferResource) {
|
||||||
this->registerWithCache();
|
this->registerWithCache(SkBudgeted::kYes);
|
||||||
}
|
}
|
||||||
|
|
||||||
GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
|
GrVkVertexBuffer* GrVkVertexBuffer::Create(GrVkGpu* gpu, size_t size, bool dynamic) {
|
||||||
|
@ -85,7 +85,7 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyM
|
|||||||
// If the original render target is a buffer originally created by the client, then we don't
|
// If the original render target is a buffer originally created by the client, then we don't
|
||||||
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
|
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
|
||||||
// copy-on-write.
|
// copy-on-write.
|
||||||
if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().isExternal()) {
|
if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWrappedObjects()) {
|
||||||
GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
|
GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
|
||||||
GrContext* ctx = fDevice->context();
|
GrContext* ctx = fDevice->context();
|
||||||
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
|
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
|
||||||
|
@ -249,35 +249,22 @@ public:
|
|||||||
* For example, textures have width, height, ... */
|
* For example, textures have width, height, ... */
|
||||||
enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
|
enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty };
|
||||||
|
|
||||||
TestResource(GrGpu* gpu, size_t size, GrGpuResource::LifeCycle lifeCycle)
|
TestResource(GrGpu* gpu, SkBudgeted budgeted = SkBudgeted::kYes, size_t size = kDefaultSize)
|
||||||
: INHERITED(gpu, lifeCycle)
|
: INHERITED(gpu)
|
||||||
, fToDelete(nullptr)
|
, fToDelete(nullptr)
|
||||||
, fSize(size)
|
, fSize(size)
|
||||||
, fProperty(kA_SimulatedProperty) {
|
, fProperty(kA_SimulatedProperty)
|
||||||
|
, fIsScratch(false) {
|
||||||
++fNumAlive;
|
++fNumAlive;
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResource(GrGpu* gpu, GrGpuResource::LifeCycle lifeCycle)
|
static TestResource* CreateScratch(GrGpu* gpu, SkBudgeted budgeted,
|
||||||
: INHERITED(gpu, lifeCycle)
|
SimulatedProperty property) {
|
||||||
, fToDelete(nullptr)
|
return new TestResource(gpu, budgeted, property, kScratchConstructor);
|
||||||
, fSize(kDefaultSize)
|
|
||||||
, fProperty(kA_SimulatedProperty) {
|
|
||||||
++fNumAlive;
|
|
||||||
this->registerWithCache();
|
|
||||||
}
|
}
|
||||||
|
static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) {
|
||||||
TestResource(GrGpu* gpu)
|
return new TestResource(gpu, size);
|
||||||
: INHERITED(gpu, kCached_LifeCycle)
|
|
||||||
, fToDelete(nullptr)
|
|
||||||
, fSize(kDefaultSize)
|
|
||||||
, fProperty(kA_SimulatedProperty) {
|
|
||||||
++fNumAlive;
|
|
||||||
this->registerWithCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
static TestResource* CreateScratch(GrGpu* gpu, SimulatedProperty property, bool cached = true) {
|
|
||||||
return new TestResource(gpu, property, cached, kScratchConstructor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~TestResource() {
|
~TestResource() {
|
||||||
@ -307,20 +294,34 @@ public:
|
|||||||
static size_t ExpectedScratchKeySize() {
|
static size_t ExpectedScratchKeySize() {
|
||||||
return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt);
|
return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int kScratchKeyFieldCnt = 6;
|
static const int kScratchKeyFieldCnt = 6;
|
||||||
|
|
||||||
TestResource(GrGpu* gpu, SimulatedProperty property, bool cached, ScratchConstructor)
|
TestResource(GrGpu* gpu, SkBudgeted budgeted, SimulatedProperty property, ScratchConstructor)
|
||||||
: INHERITED(gpu, cached ? kCached_LifeCycle : kUncached_LifeCycle)
|
: INHERITED(gpu)
|
||||||
, fToDelete(nullptr)
|
, fToDelete(nullptr)
|
||||||
, fSize(kDefaultSize)
|
, fSize(kDefaultSize)
|
||||||
, fProperty(property) {
|
, fProperty(property)
|
||||||
GrScratchKey scratchKey;
|
, fIsScratch(true) {
|
||||||
ComputeScratchKey(fProperty, &scratchKey);
|
|
||||||
this->setScratchKey(scratchKey);
|
|
||||||
++fNumAlive;
|
++fNumAlive;
|
||||||
this->registerWithCache();
|
this->registerWithCache(budgeted);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor for simulating resources that wrap backend objects.
|
||||||
|
TestResource(GrGpu* gpu, size_t size)
|
||||||
|
: INHERITED(gpu)
|
||||||
|
, fToDelete(nullptr)
|
||||||
|
, fSize(size)
|
||||||
|
, fProperty(kA_SimulatedProperty)
|
||||||
|
, fIsScratch(false) {
|
||||||
|
++fNumAlive;
|
||||||
|
this->registerWithCacheWrapped();
|
||||||
|
}
|
||||||
|
|
||||||
|
void computeScratchKey(GrScratchKey* key) const override {
|
||||||
|
if (fIsScratch) {
|
||||||
|
ComputeScratchKey(fProperty, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t onGpuMemorySize() const override { return fSize; }
|
size_t onGpuMemorySize() const override { return fSize; }
|
||||||
@ -329,6 +330,7 @@ private:
|
|||||||
size_t fSize;
|
size_t fSize;
|
||||||
static int fNumAlive;
|
static int fNumAlive;
|
||||||
SimulatedProperty fProperty;
|
SimulatedProperty fProperty;
|
||||||
|
bool fIsScratch;
|
||||||
typedef GrGpuResource INHERITED;
|
typedef GrGpuResource INHERITED;
|
||||||
};
|
};
|
||||||
int TestResource::fNumAlive = 0;
|
int TestResource::fNumAlive = 0;
|
||||||
@ -418,15 +420,15 @@ static void test_budgeting(skiatest::Reporter* reporter) {
|
|||||||
|
|
||||||
// Create a scratch, a unique, and a wrapped resource
|
// Create a scratch, a unique, and a wrapped resource
|
||||||
TestResource* scratch =
|
TestResource* scratch =
|
||||||
TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty);
|
TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes, TestResource::kB_SimulatedProperty);
|
||||||
scratch->setSize(10);
|
scratch->setSize(10);
|
||||||
TestResource* unique = new TestResource(context->getGpu());
|
TestResource* unique = new TestResource(context->getGpu());
|
||||||
unique->setSize(11);
|
unique->setSize(11);
|
||||||
unique->resourcePriv().setUniqueKey(uniqueKey);
|
unique->resourcePriv().setUniqueKey(uniqueKey);
|
||||||
TestResource* wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeCycle);
|
TestResource* wrapped = TestResource::CreateWrapped(context->getGpu());
|
||||||
wrapped->setSize(12);
|
wrapped->setSize(12);
|
||||||
TestResource* unbudgeted =
|
TestResource* unbudgeted =
|
||||||
new TestResource(context->getGpu(), GrGpuResource::kUncached_LifeCycle);
|
new TestResource(context->getGpu(), SkBudgeted::kNo);
|
||||||
unbudgeted->setSize(13);
|
unbudgeted->setSize(13);
|
||||||
|
|
||||||
// Make sure we can't add a unique key to the wrapped resource
|
// Make sure we can't add a unique key to the wrapped resource
|
||||||
@ -461,7 +463,7 @@ static void test_budgeting(skiatest::Reporter* reporter) {
|
|||||||
unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
unbudgeted->gpuMemorySize() == cache->getResourceBytes());
|
||||||
|
|
||||||
// Now try freeing the budgeted resources first
|
// Now try freeing the budgeted resources first
|
||||||
wrapped = new TestResource(context->getGpu(), GrGpuResource::kBorrowed_LifeCycle);
|
wrapped = TestResource::CreateWrapped(context->getGpu());
|
||||||
scratch->setSize(12);
|
scratch->setSize(12);
|
||||||
unique->unref();
|
unique->unref();
|
||||||
cache->purgeAllUnlocked();
|
cache->purgeAllUnlocked();
|
||||||
@ -506,7 +508,9 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
|
|||||||
TestResource* unbudgeted;
|
TestResource* unbudgeted;
|
||||||
|
|
||||||
// A large uncached or wrapped resource shouldn't evict anything.
|
// A large uncached or wrapped resource shouldn't evict anything.
|
||||||
scratch = TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty);
|
scratch = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
|
TestResource::kB_SimulatedProperty);
|
||||||
|
|
||||||
scratch->setSize(10);
|
scratch->setSize(10);
|
||||||
scratch->unref();
|
scratch->unref();
|
||||||
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
|
||||||
@ -524,7 +528,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
|
|||||||
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
||||||
|
|
||||||
size_t large = 2 * cache->getResourceBytes();
|
size_t large = 2 * cache->getResourceBytes();
|
||||||
unbudgeted = new TestResource(context->getGpu(), large, GrGpuResource::kUncached_LifeCycle);
|
unbudgeted = new TestResource(context->getGpu(), SkBudgeted::kNo, large);
|
||||||
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
||||||
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
||||||
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
||||||
@ -536,7 +540,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
|
|||||||
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
||||||
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes());
|
||||||
|
|
||||||
wrapped = new TestResource(context->getGpu(), large, GrGpuResource::kBorrowed_LifeCycle);
|
wrapped = TestResource::CreateWrapped(context->getGpu(), large);
|
||||||
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
REPORTER_ASSERT(reporter, 3 == cache->getResourceCount());
|
||||||
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes());
|
||||||
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount());
|
||||||
@ -563,7 +567,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter);
|
|||||||
GrResourceCache* cache = mock.cache();
|
GrResourceCache* cache = mock.cache();
|
||||||
|
|
||||||
TestResource* resource =
|
TestResource* resource =
|
||||||
TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty, false);
|
TestResource::CreateScratch(context->getGpu(), SkBudgeted::kNo,
|
||||||
|
TestResource::kA_SimulatedProperty);
|
||||||
GrScratchKey key;
|
GrScratchKey key;
|
||||||
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
|
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
|
||||||
|
|
||||||
@ -623,8 +628,10 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
|
|||||||
|
|
||||||
// Create two resources that have the same scratch key.
|
// Create two resources that have the same scratch key.
|
||||||
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
||||||
|
SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
||||||
|
SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
a->setSize(11);
|
a->setSize(11);
|
||||||
b->setSize(12);
|
b->setSize(12);
|
||||||
@ -667,9 +674,9 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) {
|
|||||||
GrResourceCache* cache = mock.cache();
|
GrResourceCache* cache = mock.cache();
|
||||||
|
|
||||||
// Create two resources that have the same scratch key.
|
// Create two resources that have the same scratch key.
|
||||||
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
a->unref();
|
a->unref();
|
||||||
b->unref();
|
b->unref();
|
||||||
@ -726,9 +733,9 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) {
|
|||||||
GrResourceCache* cache = mock.cache();
|
GrResourceCache* cache = mock.cache();
|
||||||
|
|
||||||
// Create two resources that have the same scratch key.
|
// Create two resources that have the same scratch key.
|
||||||
TestResource* a = TestResource::CreateScratch(context->getGpu(),
|
TestResource* a = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
TestResource* b = TestResource::CreateScratch(context->getGpu(),
|
TestResource* b = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
TestResource::kB_SimulatedProperty);
|
TestResource::kB_SimulatedProperty);
|
||||||
a->unref();
|
a->unref();
|
||||||
b->unref();
|
b->unref();
|
||||||
@ -888,7 +895,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
|
|||||||
// Add three resources to the cache. Only c is usable as scratch.
|
// Add three resources to the cache. Only c is usable as scratch.
|
||||||
TestResource* a = new TestResource(context->getGpu());
|
TestResource* a = new TestResource(context->getGpu());
|
||||||
TestResource* b = new TestResource(context->getGpu());
|
TestResource* b = new TestResource(context->getGpu());
|
||||||
TestResource* c = TestResource::CreateScratch(context->getGpu(),
|
TestResource* c = TestResource::CreateScratch(context->getGpu(), SkBudgeted::kYes,
|
||||||
TestResource::kA_SimulatedProperty);
|
TestResource::kA_SimulatedProperty);
|
||||||
a->resourcePriv().setUniqueKey(key1);
|
a->resourcePriv().setUniqueKey(key1);
|
||||||
b->resourcePriv().setUniqueKey(key2);
|
b->resourcePriv().setUniqueKey(key2);
|
||||||
|
@ -222,10 +222,9 @@ void GrResourceCache::dumpStats(SkString* out) const {
|
|||||||
|
|
||||||
out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
|
out->appendf("Budget: %d items %d bytes\n", fMaxCount, (int)fMaxBytes);
|
||||||
out->appendf("\t\tEntry Count: current %d"
|
out->appendf("\t\tEntry Count: current %d"
|
||||||
" (%d budgeted, %d external(%d borrowed, %d adopted), %d locked, %d scratch %.2g%% full), high %d\n",
|
" (%d budgeted, %d wrapped, %d locked, %d scratch %.2g%% full), high %d\n",
|
||||||
stats.fTotal, fBudgetedCount, stats.fExternal, stats.fBorrowed,
|
stats.fTotal, fBudgetedCount, stats.fWrapped, stats.fNumNonPurgeable,
|
||||||
stats.fAdopted, stats.fNumNonPurgeable, stats.fScratch, countUtilization,
|
stats.fScratch, countUtilization, fHighWaterCount);
|
||||||
fHighWaterCount);
|
|
||||||
out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
|
out->appendf("\t\tEntry Bytes: current %d (budgeted %d, %.2g%% full, %d unbudgeted) high %d\n",
|
||||||
SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
|
SkToInt(fBytes), SkToInt(fBudgetedBytes), byteUtilization,
|
||||||
SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
|
SkToInt(stats.fUnbudgetedSize), SkToInt(fHighWaterBytes));
|
||||||
@ -323,12 +322,12 @@ private:
|
|||||||
|
|
||||||
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
|
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
|
||||||
|
|
||||||
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle lifeCycle,
|
GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) override {
|
const SkTArray<GrMipLevel>& texels) override {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCycle,
|
GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||||
const SkTArray<GrMipLevel>& texels) override {
|
const SkTArray<GrMipLevel>& texels) override {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user