aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrBackendSurface.cpp
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-04-10 09:34:07 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-10 14:20:22 +0000
commit52e16d984898f18c84de773507da875a7954b922 (patch)
tree61dc6aaa14903f6b8c2e7e55d5d40c136e653354 /src/gpu/GrBackendSurface.cpp
parent58627cb8eb559670b86f06225eb87e6c1c5e8504 (diff)
Update getBackendInfo calls on GrBackendTexture to support VkImageLayout better.
The big api level change here is that the getBackendInfo calls now return by value instead of a pointer. These changes are being made in support of Vulkan so that the client can update the VkImageLayout on the GrBackendTexture and have that update get reflected in our internal tracking of the image. This is done by storing a ref counted GrVkImageLayout object on the GrBackendTexture and the GrVkImage. Bug: skia: Change-Id: I8c6158fd3a66eb61fef97ebf09ea5364bca3f1ae Reviewed-on: https://skia-review.googlesource.com/119101 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/GrBackendSurface.cpp')
-rw-r--r--src/gpu/GrBackendSurface.cpp116
1 files changed, 98 insertions, 18 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 5832fa6e0a..36c26e9cdb 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -10,6 +10,7 @@
#include "gl/GrGLUtil.h"
#ifdef SK_VULKAN
+#include "vk/GrVkImageLayout.h"
#include "vk/GrVkTypes.h"
#include "vk/GrVkUtil.h"
#endif
@@ -67,13 +68,21 @@ const GrPixelConfig* GrBackendFormat::getMockFormat() const {
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo)
+ : GrBackendTexture(width, height, vkInfo,
+ sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {}
+
+GrBackendTexture::GrBackendTexture(int width,
+ int height,
+ const GrVkImageInfo& vkInfo,
+ sk_sp<GrVkImageLayout> layout)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
, fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
, fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
, fBackend(kVulkan_GrBackend)
- , fVkInfo(vkInfo) {}
+ , fVkInfo(vkInfo, layout.release()) {
+}
#endif
#if GR_TEST_UTILS
@@ -122,47 +131,118 @@ GrBackendTexture::GrBackendTexture(int width,
, fBackend(kMock_GrBackend)
, fMockInfo(mockInfo) {}
+GrBackendTexture::~GrBackendTexture() {
+ this->cleanup();
+}
+
+void GrBackendTexture::cleanup() {
#ifdef SK_VULKAN
-const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
if (this->isValid() && kVulkan_GrBackend == fBackend) {
- return &fVkInfo;
+ fVkInfo.cleanup();
+ }
+#endif
+}
+
+GrBackendTexture::GrBackendTexture(const GrBackendTexture& that) : fIsValid(false) {
+ *this = that;
+}
+
+GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) {
+ if (!that.isValid()) {
+ this->cleanup();
+ fIsValid = false;
+ return *this;
+ }
+ fWidth = that.fWidth;
+ fHeight = that.fHeight;
+ fConfig = that.fConfig;
+ fMipMapped = that.fMipMapped;
+ fBackend = that.fBackend;
+
+ switch (that.fBackend) {
+ case kOpenGL_GrBackend:
+ fGLInfo = that.fGLInfo;
+ break;
+#ifdef SK_VULKAN
+ case kVulkan_GrBackend:
+ fVkInfo.assign(that.fVkInfo, this->isValid());
+ break;
+#endif
+#ifdef SK_METAL
+ case kMetal_GrBackend:
+ break;
+#endif
+ case kMock_GrBackend:
+ fMockInfo = that.fMockInfo;
+ break;
+ default:
+ SK_ABORT("Unknown GrBackend");
+ }
+ fIsValid = that.fIsValid;
+ return *this;
+}
+
+#ifdef SK_VULKAN
+bool GrBackendTexture::getVkImageInfo(GrVkImageInfo* outInfo) const {
+ if (this->isValid() && kVulkan_GrBackend == fBackend) {
+ *outInfo = fVkInfo.snapImageInfo();
+ return true;
+ }
+ return false;
+}
+
+void GrBackendTexture::setVkImageLayout(VkImageLayout layout) {
+ if (this->isValid() && kVulkan_GrBackend == fBackend) {
+ fVkInfo.setImageLayout(layout);
+ }
+}
+
+sk_sp<GrVkImageLayout> GrBackendTexture::getGrVkImageLayout() const {
+ if (this->isValid() && kVulkan_GrBackend == fBackend) {
+ return fVkInfo.getGrVkImageLayout();
}
return nullptr;
}
#endif
-const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
+bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const {
if (this->isValid() && kOpenGL_GrBackend == fBackend) {
- return &fGLInfo;
+ *outInfo = fGLInfo;
+ return true;
}
- return nullptr;
+ return false;
}
-const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
+bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const {
if (this->isValid() && kMock_GrBackend == fBackend) {
- return &fMockInfo;
+ *outInfo = fMockInfo;
+ return true;
}
- return nullptr;
+ return false;
}
GrBackendFormat GrBackendTexture::format() const {
+ if (!this->isValid()) {
+ return GrBackendFormat();
+ }
+
switch (this->backend()) {
#ifdef SK_VULKAN
case kVulkan_GrBackend: {
- const GrVkImageInfo* vkInfo = this->getVkImageInfo();
- SkASSERT(vkInfo);
- return GrBackendFormat::MakeVk(vkInfo->fFormat);
+ GrVkImageInfo vkInfo;
+ SkAssertResult(this->getVkImageInfo(&vkInfo));
+ return GrBackendFormat::MakeVk(vkInfo.fFormat);
}
#endif
case kOpenGL_GrBackend: {
- const GrGLTextureInfo* glInfo = this->getGLTextureInfo();
- SkASSERT(glInfo);
- return GrBackendFormat::MakeGL(glInfo->fFormat, glInfo->fTarget);
+ GrGLTextureInfo glInfo;
+ SkAssertResult(this->getGLTextureInfo(&glInfo));
+ return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
}
case kMock_GrBackend: {
- const GrMockTextureInfo* mockInfo = this->getMockTextureInfo();
- SkASSERT(mockInfo);
- return GrBackendFormat::MakeMock(mockInfo->fConfig);
+ GrMockTextureInfo mockInfo;
+ SkAssertResult(this->getMockTextureInfo(&mockInfo));
+ return GrBackendFormat::MakeMock(mockInfo.fConfig);
}
default:
return GrBackendFormat();