Remove unneeded kExact and kNoCreate Flags from GrResouceProvider
This is change 1 of 3 to reland, https://skia-review.googlesource.com/c/skia/+/42083
Bug: skia:
Change-Id: Ia0369fc67807e369c2e90220f5824da7164a230a
Reviewed-on: https://skia-review.googlesource.com/44461
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 933f732..bf048a0 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -97,7 +97,6 @@
sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc,
SkBudgeted budgeted, uint32_t flags) {
- flags |= kExact_Flag | kNoCreate_Flag;
sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
if (tex && SkBudgeted::kNo == budgeted) {
tex->resourcePriv().makeUnbudgeted();
@@ -188,51 +187,53 @@
return nullptr;
}
- return this->refScratchTexture(desc, flags);
+ SkTCopyOnFirstWrite<GrSurfaceDesc> copyDesc(desc);
+
+ // bin by pow2 with a reasonable min
+ if (!SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag) &&
+ (fGpu->caps()->reuseScratchTextures() || (desc.fFlags & kRenderTarget_GrSurfaceFlag))) {
+ GrSurfaceDesc* wdesc = copyDesc.writable();
+ wdesc->fWidth = SkTMax(kMinScratchTextureSize, GrNextPow2(desc.fWidth));
+ wdesc->fHeight = SkTMax(kMinScratchTextureSize, GrNextPow2(desc.fHeight));
+ }
+
+ if (auto tex = this->refScratchTexture(*copyDesc, flags)) {
+ return tex;
+ }
+
+ return fGpu->createTexture(*copyDesc, SkBudgeted::kYes);
}
-sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
+sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc,
uint32_t flags) {
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
- SkASSERT(validate_desc(inDesc, *fCaps));
-
- SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
+ SkASSERT(validate_desc(desc, *fCaps));
// We could make initial clears work with scratch textures but it is a rare case so we just opt
// to fall back to making a new texture.
- if (!SkToBool(inDesc.fFlags & kPerformInitialClear_GrSurfaceFlag) &&
- (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag))) {
- if (!(kExact_Flag & flags)) {
- // bin by pow2 with a reasonable min
- GrSurfaceDesc* wdesc = desc.writable();
- wdesc->fWidth = SkTMax(kMinScratchTextureSize, GrNextPow2(desc->fWidth));
- wdesc->fHeight = SkTMax(kMinScratchTextureSize, GrNextPow2(desc->fHeight));
- }
+ if (!SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag) &&
+ (fGpu->caps()->reuseScratchTextures() || (desc.fFlags & kRenderTarget_GrSurfaceFlag))) {
GrScratchKey key;
- GrTexturePriv::ComputeScratchKey(*desc, &key);
+ GrTexturePriv::ComputeScratchKey(desc, &key);
uint32_t scratchFlags = 0;
if (kNoPendingIO_Flag & flags) {
scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
- } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
+ } else if (!(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
// If it is not a render target then it will most likely be populated by
// writePixels() which will trigger a flush if the texture has pending IO.
scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
}
GrGpuResource* resource = fCache->findAndRefScratchResource(key,
- GrSurface::WorstCaseSize(*desc),
- scratchFlags);
+ GrSurface::WorstCaseSize(desc),
+ scratchFlags);
if (resource) {
GrSurface* surface = static_cast<GrSurface*>(resource);
return sk_sp<GrTexture>(surface->asTexture());
}
}
- if (!(kNoCreate_Flag & flags)) {
- return fGpu->createTexture(*desc, SkBudgeted::kYes);
- }
-
return nullptr;
}
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index be06c8d..b906013 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -165,22 +165,18 @@
/** These flags govern which scratch resources we are allowed to return */
enum Flags {
- kExact_Flag = 0x1,
-
/** If the caller intends to do direct reads/writes to/from the CPU then this flag must be
* set when accessing resources during a GrOpList flush. This includes the execution of
* GrOp objects. The reason is that these memory operations are done immediately and
* will occur out of order WRT the operations being flushed.
* Make this automatic: https://bug.skia.org/4156
*/
- kNoPendingIO_Flag = 0x2,
-
- kNoCreate_Flag = 0x4,
+ kNoPendingIO_Flag = 0x1,
/** Normally the caps may indicate a preference for client-side buffers. Set this flag when
* creating a buffer to guarantee it resides in GPU memory.
*/
- kRequireGpuMemory_Flag = 0x8,
+ kRequireGpuMemory_Flag = 0x2,
};
/**
@@ -258,6 +254,8 @@
GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture);
+ // Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that
+ // it returns null. If non-null, the resulting texture is always budgeted.
sk_sp<GrTexture> refScratchTexture(const GrSurfaceDesc&, uint32_t scratchTextureFlags);
/*