diff options
author | Greg Daniel <egdaniel@google.com> | 2017-09-08 14:46:23 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-08 19:58:18 +0000 |
commit | 21918231b25037f6ae98a9a431d9e107e8b29f08 (patch) | |
tree | 72664e6a811a5e3ccabedb44fd207f70a706170b /src/gpu/GrResourceProvider.cpp | |
parent | 1170a553be35920fe45d6a454a27d21167060977 (diff) |
Revert "Remove isMipMapped from GrSurfaceDesc" and follow up find exact scratch CL
This reverts commit 52cb5fe23b8f960bb3248620c8f4e2f2957b6685.
This reverts commit e1fbf170580a4b932d0abcb11593fb1ef0cac60b.
TBR:bsalomon@googole.com
Bug: chromium:763333
Change-Id: Ie94e00c3c7231e32f009b9dc7bb51ebb53baf7b1
Reviewed-on: https://skia-review.googlesource.com/44400
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/GrResourceProvider.cpp')
-rw-r--r-- | src/gpu/GrResourceProvider.cpp | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index cd337b27c2..8dce5497d8 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -87,12 +87,7 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, Sk return nullptr; } - - // TODO: Try finding an exact scratch texture and use that instead of always creating a new - // texture. We need to update GrSurfaceContext writePixels to take an array of texels to be able - // to do this. sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted, texels, mipLevelCount)); - if (tex) { tex->texturePriv().setMipColorMode(mipColorMode); } @@ -101,11 +96,8 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, Sk } sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc, - SkBudgeted budgeted, uint32_t flags, - bool isMipMapped) { - if (isMipMapped) { - flags |= kMipMapped_Flag; - } + 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(); @@ -146,7 +138,7 @@ sk_sp<GrTextureProxy> GrResourceProvider::createTextureProxy(const GrSurfaceDesc SkImageInfo srcInfo; if (make_info(desc.fWidth, desc.fHeight, desc.fConfig, &srcInfo)) { - sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, 0, false); + sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, 0); sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin); if (proxy) { sk_sp<GrSurfaceContext> sContext = @@ -175,7 +167,7 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, Sk return nullptr; } - sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, flags, false); + sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, flags); if (tex) { return tex; } @@ -196,52 +188,51 @@ sk_sp<GrTexture> GrResourceProvider::createApproxTexture(const GrSurfaceDesc& de return nullptr; } - if (auto tex = this->refScratchTexture(desc, flags)) { - return tex; - } - - GrSurfaceDesc copyDesc = desc; - // bin by pow2 with a reasonable min - copyDesc.fWidth = SkTMax(kMinScratchTextureSize, GrNextPow2(desc.fWidth)); - copyDesc.fHeight = SkTMax(kMinScratchTextureSize, GrNextPow2(desc.fHeight)); - - if (auto tex = this->refScratchTexture(copyDesc, flags)) { - return tex; - } - - return fGpu->createTexture(copyDesc, SkBudgeted::kYes); + return this->refScratchTexture(desc, flags); } -sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc, uint32_t flags) { +sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc, + uint32_t flags) { ASSERT_SINGLE_OWNER SkASSERT(!this->isAbandoned()); - SkASSERT(validate_desc(desc, *fCaps)); + SkASSERT(validate_desc(inDesc, *fCaps)); + + SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); // 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(desc.fFlags & kPerformInitialClear_GrSurfaceFlag) && - (fGpu->caps()->reuseScratchTextures() || (desc.fFlags & kRenderTarget_GrSurfaceFlag))) { + 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)); + } GrScratchKey key; - bool isMipMapped = SkToBool(kMipMapped_Flag & flags); - GrTexturePriv::ComputeScratchKey(desc, isMipMapped, &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; } |