Make GrBackendTexture take Gr*Info refs in ctor, and copy them.
Bug: skia:
Change-Id: Ic05d3384fa07560fc18c52bb8ae03541a72515f7
Reviewed-on: https://skia-review.googlesource.com/14374
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp
index 5b3dc22..c71a51c 100644
--- a/gm/rectangletexture.cpp
+++ b/gm/rectangletexture.cpp
@@ -109,7 +109,7 @@
info.fID = id;
info.fTarget = TARGET;
- GrBackendTexture rectangleTex(width, height, kRGBA_8888_GrPixelConfig, &info);
+ GrBackendTexture rectangleTex(width, height, kRGBA_8888_GrPixelConfig, info);
if (sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(context, rectangleTex,
kTopLeft_GrSurfaceOrigin)) {
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index d9302da..232f220 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -14,18 +14,14 @@
class GrBackendTexture {
public:
- // The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in
- // creation of SkImages or SkSurfaces.
GrBackendTexture(int width,
int height,
- const GrVkImageInfo* vkInfo);
+ const GrVkImageInfo& vkInfo);
- // The passed in GrGLTextureInfo must live until the GrBackendTexture is no longer used in
- // creation of SkImages or SkSurfaces.
GrBackendTexture(int width,
int height,
GrPixelConfig config,
- const GrGLTextureInfo* glInfo);
+ const GrGLTextureInfo& glInfo);
int width() const { return fWidth; }
int height() const { return fHeight; }
@@ -54,9 +50,8 @@
GrBackend fBackend;
union {
- const GrVkImageInfo* fVkInfo;
- const GrGLTextureInfo* fGLInfo;
- GrBackendObject fHandle;
+ GrVkImageInfo fVkInfo;
+ GrGLTextureInfo fGLInfo;
};
};
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 0c205a9..6304475 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -14,12 +14,12 @@
GrBackendTexture::GrBackendTexture(int width,
int height,
- const GrVkImageInfo* vkInfo)
+ const GrVkImageInfo& vkInfo)
: fWidth(width)
, fHeight(height)
, fConfig(
#ifdef SK_VULKAN
- GrVkFormatToPixelConfig(vkInfo->fFormat)
+ GrVkFormatToPixelConfig(vkInfo.fFormat)
#else
kUnknown_GrPixelConfig
#endif
@@ -30,7 +30,7 @@
GrBackendTexture::GrBackendTexture(int width,
int height,
GrPixelConfig config,
- const GrGLTextureInfo* glInfo)
+ const GrGLTextureInfo& glInfo)
: fWidth(width)
, fHeight(height)
, fConfig(config)
@@ -40,26 +40,33 @@
GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend)
: fWidth(desc.fWidth)
, fHeight(desc.fHeight)
- , fConfig(kVulkan_GrBackend == backend
+ , fConfig(desc.fConfig)
+ , fBackend(backend) {
+ if (kOpenGL_GrBackend == backend) {
+ fGLInfo = *reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
+ } else {
+ SkASSERT(kVulkan_GrBackend == backend);
#ifdef SK_VULKAN
- ? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fTextureHandle)->fFormat)
+ const GrVkImageInfo* vkInfo =
+ reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle);
+ fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
+ fVkInfo = *vkInfo;
#else
- ? kUnknown_GrPixelConfig
+ fConfig = kUnknown_GrPixelConfig;
#endif
- : desc.fConfig)
- , fBackend(backend)
- , fHandle(desc.fTextureHandle) {}
+ }
+}
const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
if (kVulkan_GrBackend == fBackend) {
- return fVkInfo;
+ return &fVkInfo;
}
return nullptr;
}
const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
if (kOpenGL_GrBackend == fBackend) {
- return fGLInfo;
+ return &fGLInfo;
}
return nullptr;
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 68127f2..2c7a194 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -315,11 +315,11 @@
if (kOpenGL_GrBackend == backend) {
GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
- return GrBackendTexture(width, height, config, glInfo);
+ return GrBackendTexture(width, height, config, *glInfo);
} else {
SkASSERT(kVulkan_GrBackend == backend);
GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
- return GrBackendTexture(width, height, vkInfo);
+ return GrBackendTexture(width, height, *vkInfo);
}
}
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 1b94a6e..ae66db5 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -130,7 +130,7 @@
externalTexture.fID = glCtx0->eglImageToExternalTexture(image);
// Wrap this texture ID in a GrTexture
- GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, &externalTexture);
+ GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, externalTexture);
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
// fails on the Nexus5. Why?
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index cdcd8d7..9c85ad4 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -119,7 +119,7 @@
rectangleInfo.fID = rectTexID;
rectangleInfo.fTarget = GR_GL_TEXTURE_RECTANGLE;
- GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, &rectangleInfo);
+ GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, rectangleInfo);
GrColor refPixels[kWidth * kHeight];
for (int y = 0; y < kHeight; ++y) {
diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp
index 0ae3402..fc19bb3 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -33,7 +33,7 @@
false);
const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj);
- GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo);
+ GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
@@ -44,7 +44,7 @@
// image is null
GrVkImageInfo backendCopy = *imageInfo;
backendCopy.fImage = VK_NULL_HANDLE;
- backendTex = GrBackendTexture(kW, kH, &backendCopy);
+ backendTex = GrBackendTexture(kW, kH, backendCopy);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kNone_GrBackendTextureFlag,
@@ -125,7 +125,7 @@
true);
const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj);
- GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo);
+ GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo);
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
@@ -136,7 +136,7 @@
// image is null
GrVkImageInfo backendCopy = *imageInfo;
backendCopy.fImage = VK_NULL_HANDLE;
- backendTex = GrBackendTexture(kW, kH, &backendCopy);
+ backendTex = GrBackendTexture(kW, kH, backendCopy);
tex = gpu->wrapBackendTexture(backendTex,
kTopLeft_GrSurfaceOrigin,
kRenderTarget_GrBackendTextureFlag,
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 7fe9a43..f5459b1 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -60,11 +60,11 @@
GrPixelConfig config, GrBackendObject handle) {
if (kOpenGL_GrBackend == backend) {
GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle);
- return GrBackendTexture(width, height, config, glInfo);
+ return GrBackendTexture(width, height, config, *glInfo);
} else {
SkASSERT(kVulkan_GrBackend == backend);
GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle);
- return GrBackendTexture(width, height, vkInfo);
+ return GrBackendTexture(width, height, *vkInfo);
}
}
};
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index f483c27..809c614 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -274,7 +274,7 @@
info.fFormat = format;
info.fLevelCount = 1;
- GrBackendTexture backendTex(fWidth, fHeight, &info);
+ GrBackendTexture backendTex(fWidth, fHeight, info);
fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext, backendTex,
kTopLeft_GrSurfaceOrigin,