Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv (take 3)
This is in service of: https://skia-review.googlesource.com/c/11125/ (Add parallel proxyID to StencilOps & RenderTargetOpList) where I want a better choke point for texture creation to improve discard handling.
This is a re-reland of: https://skia-review.googlesource.com/c/11200/ (Rm readPixels from GrSurface & move read/writeSurfacePixels to GrContextPriv)
Change-Id: Icfb9dd223418dd460405efd2bfd9d1c356beed1a
Reviewed-on: https://skia-review.googlesource.com/11412
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 42f5e29..5c4ab9c 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -10,6 +10,7 @@
#include "GrBuffer.h"
#include "GrCaps.h"
#include "GrContext.h"
+#include "GrContextPriv.h"
#include "GrGpu.h"
#include "GrPathRendering.h"
#include "GrRenderTarget.h"
@@ -47,9 +48,13 @@
return proxy->priv().isExact() || (SkIsPow2(proxy->width()) && SkIsPow2(proxy->height()));
}
-GrTexture* GrResourceProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
- SkBudgeted budgeted, const GrMipLevel* texels,
- int mipLevelCount, uint32_t flags,
+// MDB TODO: this should probably be a factory on GrSurfaceProxy
+sk_sp<GrTextureProxy> GrResourceProvider::createMipMappedTexture(
+ const GrSurfaceDesc& desc,
+ SkBudgeted budgeted,
+ const GrMipLevel* texels,
+ int mipLevelCount,
+ uint32_t flags,
SkDestinationSurfaceColorMode mipColorMode) {
ASSERT_SINGLE_OWNER
@@ -74,17 +79,19 @@
if (!GrPixelConfigIsCompressed(desc.fConfig)) {
if (mipLevelCount < 2) {
flags |= kExact_Flag | kNoCreate_Flag;
- if (GrTexture* texture = this->refScratchTexture(desc, flags)) {
+ sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
+ if (tex) {
+ sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(tex);
if (!mipLevelCount ||
- texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- texels[0].fPixels, texels[0].fRowBytes)) {
+ fGpu->getContext()->contextPriv().writeSurfacePixels(
+ proxy.get(), nullptr, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ nullptr, texels[0].fPixels, texels[0].fRowBytes)) {
if (SkBudgeted::kNo == budgeted) {
- texture->resourcePriv().makeUnbudgeted();
+ tex->resourcePriv().makeUnbudgeted();
}
- texture->texturePriv().setMipColorMode(mipColorMode);
- return texture;
+ tex->texturePriv().setMipColorMode(mipColorMode);
+ return proxy;
}
- texture->unref();
}
}
}
@@ -93,25 +100,40 @@
for (int i = 0; i < mipLevelCount; ++i) {
texelsShallowCopy.push_back(texels[i]);
}
- GrTexture* texture = fGpu->createTexture(desc, budgeted, texelsShallowCopy);
- if (texture) {
- texture->texturePriv().setMipColorMode(mipColorMode);
+ sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted, texelsShallowCopy));
+ if (tex) {
+ tex->texturePriv().setMipColorMode(mipColorMode);
}
- return texture;
+
+ return GrSurfaceProxy::MakeWrapped(std::move(tex));
}
-GrTexture* GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
- const void* srcData, size_t rowBytes, uint32_t flags) {
- GrMipLevel tempTexels;
- GrMipLevel* texels = nullptr;
- int levelCount = 0;
- if (srcData) {
- tempTexels.fPixels = srcData;
- tempTexels.fRowBytes = rowBytes;
- texels = &tempTexels;
- levelCount = 1;
+sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+ uint32_t flags) {
+ ASSERT_SINGLE_OWNER
+
+ if (this->isAbandoned()) {
+ return nullptr;
}
- return this->createMipMappedTexture(desc, budgeted, texels, levelCount, flags);
+
+ if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
+ !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ return nullptr;
+ }
+
+ if (!GrPixelConfigIsCompressed(desc.fConfig)) {
+ flags |= kExact_Flag | kNoCreate_Flag;
+ sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
+ if (tex) {
+ if (SkBudgeted::kNo == budgeted) {
+ tex->resourcePriv().makeUnbudgeted();
+ }
+ return tex;
+ }
+ }
+
+ sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted));
+ return tex;
}
GrTexture* GrResourceProvider::createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) {