aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-03-09 17:02:09 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-09 22:32:14 +0000
commit0c51eeada6a91b03a91a17e94d0afea6331709d9 (patch)
tree280d2016faa326b1ef150f81a6e16a739cebfbbe
parent8c4cbf4cfb6d9236dfd69273bff7e8384744c29a (diff)
Add GrMockRenderTarget and mock backend render targets
Change-Id: I59673dd7d0015471b7a81aa0c237c67043892454 Reviewed-on: https://skia-review.googlesource.com/113427 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
-rw-r--r--include/gpu/GrBackendSurface.h15
-rw-r--r--include/gpu/mock/GrMockTypes.h7
-rw-r--r--src/gpu/GrBackendSurface.cpp27
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp6
-rw-r--r--src/gpu/mock/GrMockGpu.cpp103
-rw-r--r--src/gpu/mock/GrMockGpu.h14
-rw-r--r--src/gpu/mock/GrMockTexture.h82
-rw-r--r--src/gpu/vk/GrVkRenderTarget.cpp6
-rw-r--r--src/image/SkImage_Gpu.cpp2
-rw-r--r--tools/gpu/GrTest.cpp2
10 files changed, 214 insertions, 50 deletions
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index 94ab39aca2..0145dc44c0 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -113,12 +113,6 @@ public:
GrBackendTexture(int width,
int height,
- GrPixelConfig config,
- const GrMockTextureInfo& mockInfo);
-
- GrBackendTexture(int width,
- int height,
- GrPixelConfig config,
GrMipMapped,
const GrMockTextureInfo& mockInfo);
@@ -203,6 +197,12 @@ public:
GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo);
#endif
+ GrBackendRenderTarget(int width,
+ int height,
+ int sampleCnt,
+ int stencilBits,
+ const GrMockRenderTargetInfo& mockInfo);
+
int width() const { return fWidth; }
int height() const { return fHeight; }
int sampleCnt() const { return fSampleCnt; }
@@ -219,6 +219,8 @@ public:
const GrVkImageInfo* getVkImageInfo() const;
#endif
+ const GrMockRenderTargetInfo* getMockRenderTargetInfo() const;
+
// Returns true if the backend texture has been initialized.
bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
@@ -249,6 +251,7 @@ private:
#ifdef SK_VULKAN
GrVkImageInfo fVkInfo;
#endif
+ GrMockRenderTargetInfo fMockInfo;
};
};
diff --git a/include/gpu/mock/GrMockTypes.h b/include/gpu/mock/GrMockTypes.h
index 49601cb55e..6e38175838 100644
--- a/include/gpu/mock/GrMockTypes.h
+++ b/include/gpu/mock/GrMockTypes.h
@@ -13,7 +13,12 @@
struct GrMockTextureInfo {
GrPixelConfig fConfig;
- int fID;
+ int fID;
+};
+
+struct GrMockRenderTargetInfo {
+ GrPixelConfig fConfig;
+ int fID;
};
/**
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 6db618f717..fa2582a18e 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -106,18 +106,11 @@ GrBackendTexture::GrBackendTexture(int width,
GrBackendTexture::GrBackendTexture(int width,
int height,
- GrPixelConfig config,
- const GrMockTextureInfo& mockInfo)
- : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {}
-
-GrBackendTexture::GrBackendTexture(int width,
- int height,
- GrPixelConfig config,
GrMipMapped mipMapped,
const GrMockTextureInfo& mockInfo)
: fWidth(width)
, fHeight(height)
- , fConfig(config)
+ , fConfig(mockInfo.fConfig)
, fMipMapped(mipMapped)
, fBackend(kMock_GrBackend)
, fMockInfo(mockInfo) {}
@@ -198,6 +191,18 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
, fBackend(kOpenGL_GrBackend)
, fGLInfo(glInfo) {}
+GrBackendRenderTarget::GrBackendRenderTarget(int width,
+ int height,
+ int sampleCnt,
+ int stencilBits,
+ const GrMockRenderTargetInfo& mockInfo)
+ : fWidth(width)
+ , fHeight(height)
+ , fSampleCnt(SkTMax(1, sampleCnt))
+ , fStencilBits(stencilBits)
+ , fConfig(mockInfo.fConfig)
+ , fMockInfo(mockInfo) {}
+
#ifdef SK_VULKAN
const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
@@ -214,3 +219,9 @@ const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
return nullptr;
}
+const GrMockRenderTargetInfo* GrBackendRenderTarget::getMockRenderTargetInfo() const {
+ if (kMock_GrBackend == fBackend) {
+ return &fMockInfo;
+ }
+ return nullptr;
+}
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 6f3714c504..de7399bd92 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -86,9 +86,13 @@ GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const {
GrGLFramebufferInfo fbi;
fbi.fFBOID = fRTFBOID;
fbi.fFormat = this->getGLGpu()->glCaps().configSizedInternalFormat(this->config());
+ int numStencilBits = 0;
+ if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) {
+ numStencilBits = stencil->bits();
+ }
return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(),
- this->numStencilSamples(), fbi);
+ numStencilBits, fbi);
}
size_t GrGLRenderTarget::onGpuMemorySize() const {
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index ad9dc882ce..b1c3e7dd7d 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -24,6 +24,20 @@ int GrMockGpu::NextExternalTextureID() {
return sk_atomic_dec(&gID) - 1;
}
+int GrMockGpu::NextInternalRenderTargetID() {
+ // We start off with large numbers to differentiate from texture IDs, even though their
+ // technically in a different space.
+ static int gID = SK_MaxS32;
+ return sk_atomic_dec(&gID);
+}
+
+int GrMockGpu::NextExternalRenderTargetID() {
+ // We use large negative ints for the "testing only external render targets" so they can easily
+ // be identified when debugging.
+ static int gID = SK_MinS32;
+ return sk_atomic_inc(&gID);
+}
+
sk_sp<GrGpu> GrMockGpu::Make(GrBackendContext backendContext,
const GrContextOptions& contextOptions, GrContext* context) {
return Make(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
@@ -68,14 +82,17 @@ sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgete
const GrMipLevel texels[], int mipLevelCount) {
GrMipMapsStatus mipMapsStatus = mipLevelCount > 1 ? GrMipMapsStatus::kValid
: GrMipMapsStatus::kNotAllocated;
- GrMockTextureInfo info;
- info.fConfig = desc.fConfig;
- info.fID = NextInternalTextureID();
+ GrMockTextureInfo texInfo;
+ texInfo.fConfig = desc.fConfig;
+ texInfo.fID = NextInternalTextureID();
if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
- return sk_sp<GrTexture>(
- new GrMockTextureRenderTarget(this, budgeted, desc, mipMapsStatus, info));
+ GrMockRenderTargetInfo rtInfo;
+ rtInfo.fConfig = desc.fConfig;
+ rtInfo.fID = NextInternalRenderTargetID();
+ return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, budgeted, desc, mipMapsStatus,
+ texInfo, rtInfo));
}
- return sk_sp<GrTexture>(new GrMockTexture(this, budgeted, desc, mipMapsStatus, info));
+ return sk_sp<GrTexture>(new GrMockTexture(this, budgeted, desc, mipMapsStatus, texInfo));
}
sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,
@@ -94,6 +111,62 @@ sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,
info));
}
+sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
+ int sampleCnt,
+ GrWrapOwnership ownership) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = tex.width();
+ desc.fHeight = tex.height();
+ SkASSERT(tex.getMockTextureInfo());
+ GrMockTextureInfo texInfo = *tex.getMockTextureInfo();
+ desc.fConfig = texInfo.fConfig;
+
+ GrMipMapsStatus mipMapsStatus =
+ tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated;
+
+ GrMockRenderTargetInfo rtInfo;
+ rtInfo.fConfig = texInfo.fConfig;
+ // The client gave us the texture ID but we supply the render target ID.
+ rtInfo.fID = NextInternalRenderTargetID();
+
+ return sk_sp<GrTexture>(
+ new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo));
+}
+
+sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = rt.width();
+ desc.fHeight = rt.height();
+ SkASSERT(rt.getMockRenderTargetInfo());
+ const GrMockRenderTargetInfo info = *rt.getMockRenderTargetInfo();
+ desc.fConfig = info.fConfig;
+
+ return sk_sp<GrRenderTarget>(
+ new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, info));
+}
+
+sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
+ int sampleCnt) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = tex.width();
+ desc.fHeight = tex.height();
+ SkASSERT(tex.getMockTextureInfo());
+ const GrMockTextureInfo texInfo = *tex.getMockTextureInfo();
+ desc.fConfig = texInfo.fConfig;
+ desc.fSampleCnt = sampleCnt;
+
+ GrMockRenderTargetInfo rtInfo;
+ rtInfo.fConfig = texInfo.fConfig;
+ // The client gave us the texture ID but we supply the render target ID.
+ rtInfo.fID = NextInternalRenderTargetID();
+
+ return sk_sp<GrRenderTarget>(
+ new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, rtInfo));
+}
+
GrBuffer* GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrBufferType type,
GrAccessPattern accessPattern, const void*) {
return new GrMockBuffer(this, sizeInBytes, type, accessPattern);
@@ -110,12 +183,12 @@ GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrR
#if GR_TEST_UTILS
GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
GrPixelConfig config, bool isRT,
- GrMipMapped) {
+ GrMipMapped mipMapped) {
GrMockTextureInfo info;
info.fConfig = config;
info.fID = NextExternalTextureID();
fOutstandingTestingOnlyTextureIDs.add(info.fID);
- return GrBackendTexture(w, h, config, info);
+ return GrBackendTexture(w, h, mipMapped, info);
}
bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
@@ -138,9 +211,17 @@ void GrMockGpu::deleteTestingOnlyBackendTexture(const GrBackendTexture& tex) {
}
}
-GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType,
- GrSRGBEncoded) {
- return {};
+GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h,
+ GrColorType colorType,
+ GrSRGBEncoded srgbEncoded) {
+ auto config = GrColorTypeToPixelConfig(colorType, srgbEncoded);
+ if (kUnknown_GrPixelConfig == config) {
+ return {};
+ }
+ GrMockRenderTargetInfo info = {config, NextExternalRenderTargetID()};
+ static constexpr int kSampleCnt = 1;
+ static constexpr int kStencilBits = 8;
+ return {w, h, kSampleCnt, kStencilBits, info};
}
void GrMockGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {}
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 8bc72510ee..f0d7c07deb 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -62,18 +62,12 @@ private:
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
- GrWrapOwnership) override {
- return nullptr;
- }
+ GrWrapOwnership) override;
- sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override {
- return nullptr;
- }
+ sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
- int sampleCnt) override {
- return nullptr;
- }
+ int sampleCnt) override;
GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
const void*) override;
@@ -134,6 +128,8 @@ private:
static int NextInternalTextureID();
static int NextExternalTextureID();
+ static int NextInternalRenderTargetID();
+ static int NextExternalRenderTargetID();
SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index 5ed785e052..55dc6f3946 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -9,6 +9,7 @@
#include "GrMockGpu.h"
#include "GrRenderTarget.h"
+#include "GrRenderTargetPriv.h"
#include "GrTexture.h"
#include "GrTexturePriv.h"
#include "mock/GrMockTypes.h"
@@ -34,8 +35,8 @@ public:
return reinterpret_cast<GrBackendObject>(&fInfo);
}
GrBackendTexture getBackendTexture() const override {
- return GrBackendTexture(this->width(), this->height(), this->config(),
- this->texturePriv().mipMapped(), fInfo);
+ return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(),
+ fInfo);
}
void textureParamsModified() override {}
@@ -80,24 +81,83 @@ private:
typedef GrTexture INHERITED;
};
-class GrMockTextureRenderTarget : public GrMockTexture, public GrRenderTarget {
+class GrMockRenderTarget : public GrRenderTarget {
public:
+ GrMockRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
+ const GrMockRenderTargetInfo& info)
+ : GrSurface(gpu, desc), INHERITED(gpu, desc), fInfo(info) {
+ this->registerWithCache(budgeted);
+ }
+
+ enum Wrapped { kWrapped };
+ GrMockRenderTarget(GrMockGpu* gpu, Wrapped, const GrSurfaceDesc& desc,
+ const GrMockRenderTargetInfo& info)
+ : GrSurface(gpu, desc), INHERITED(gpu, desc), fInfo(info) {
+ this->registerWithCacheWrapped();
+ }
+
+ ResolveType getResolveType() const override { return kCanResolve_ResolveType; }
+ bool canAttemptStencilAttachment() const override { return true; }
+ bool completeStencilAttachment() override { return true; }
+
+ size_t onGpuMemorySize() const override {
+ int numColorSamples = this->numColorSamples();
+ if (numColorSamples > 1) {
+ // Add one to account for the resolve buffer.
+ ++numColorSamples;
+ }
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
+ numColorSamples, GrMipMapped::kNo);
+ }
+
+ GrBackendRenderTarget getBackendRenderTarget() const override {
+ int numStencilBits = 0;
+ if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) {
+ numStencilBits = stencil->bits();
+ }
+ return {this->width(), this->height(), this->numColorSamples(), numStencilBits, fInfo};
+ }
+
+ GrBackendObject getRenderTargetHandle() const override {
+ return reinterpret_cast<GrBackendObject>(&fInfo);
+ }
+
+protected:
+ // constructor for subclasses
+ GrMockRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc,
+ const GrMockRenderTargetInfo& info)
+ : GrSurface(gpu, desc), INHERITED(gpu, desc), fInfo(info) {}
+
+private:
+ GrMockRenderTargetInfo fInfo;
+
+ typedef GrRenderTarget INHERITED;
+};
+
+class GrMockTextureRenderTarget : public GrMockTexture, public GrMockRenderTarget {
+public:
+ // Internally created.
GrMockTextureRenderTarget(GrMockGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
- GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& texInfo)
+ GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& texInfo,
+ const GrMockRenderTargetInfo& rtInfo)
: GrSurface(gpu, desc)
, GrMockTexture(gpu, desc, mipMapsStatus, texInfo)
- , GrRenderTarget(gpu, desc) {
+ , GrMockRenderTarget(gpu, desc, rtInfo) {
this->registerWithCache(budgeted);
}
- ResolveType getResolveType() const override { return kCanResolve_ResolveType; }
- GrBackendObject getRenderTargetHandle() const override { return 0; }
- GrBackendRenderTarget getBackendRenderTarget() const override {
- return GrBackendRenderTarget(); // invalid
+ // Renderable wrapped backend texture.
+ GrMockTextureRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc,
+ GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& texInfo,
+ const GrMockRenderTargetInfo& rtInfo)
+ : GrSurface(gpu, desc)
+ , GrMockTexture(gpu, desc, mipMapsStatus, texInfo)
+ , GrMockRenderTarget(gpu, desc, rtInfo) {
+ this->registerWithCacheWrapped();
}
- bool canAttemptStencilAttachment() const override { return true; }
- bool completeStencilAttachment() override { return true; }
+ GrBackendObject getRenderTargetHandle() const override { return 0; }
+
GrTexture* asTexture() override { return this; }
GrRenderTarget* asRenderTarget() override { return this; }
const GrTexture* asTexture() const override { return this; }
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index 2a745ed51c..99b6b7632c 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -348,8 +348,12 @@ GrBackendObject GrVkRenderTarget::getRenderTargetHandle() const {
}
GrBackendRenderTarget GrVkRenderTarget::getBackendRenderTarget() const {
+ int numStencilBits = 0;
+ if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) {
+ numStencilBits = stencil->bits();
+ }
return GrBackendRenderTarget(this->width(), this->height(), this->numColorSamples(),
- this->numStencilSamples(), fInfo);
+ numStencilBits, fInfo);
}
const GrVkResource* GrVkRenderTarget::stencilImageResource() const {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index d49835ea90..7c842f69c0 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -391,7 +391,7 @@ static GrBackendTexture make_backend_texture_from_handle(GrBackend backend,
#endif
case kMock_GrBackend: {
const GrMockTextureInfo* mockInfo = (const GrMockTextureInfo*)(handle);
- return GrBackendTexture(width, height, config, *mockInfo);
+ return GrBackendTexture(width, height, GrMipMapped::kNo, *mockInfo);
}
default:
return GrBackendTexture();
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index ae86aaed82..e33e2dd5c7 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -71,7 +71,7 @@ GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
}
case kMock_GrBackend: {
GrMockTextureInfo* mockInfo = (GrMockTextureInfo*)(handle);
- return GrBackendTexture(width, height, config, mipMapped, *mockInfo);
+ return GrBackendTexture(width, height, mipMapped, *mockInfo);
}
default:
return GrBackendTexture();