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>
This commit is contained in:
Greg Daniel 2017-04-26 13:29:21 -04:00 committed by Skia Commit-Bot
parent f6782442ba
commit 207282eb5a
9 changed files with 34 additions and 32 deletions

View File

@ -109,7 +109,7 @@ protected:
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)) {

View File

@ -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 @@ private:
GrBackend fBackend;
union {
const GrVkImageInfo* fVkInfo;
const GrGLTextureInfo* fGLInfo;
GrBackendObject fHandle;
GrVkImageInfo fVkInfo;
GrGLTextureInfo fGLInfo;
};
};

View File

@ -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,
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(int width,
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;
}

View File

@ -315,11 +315,11 @@ static GrBackendTexture make_backend_texture_from_handle(GrBackend backend,
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);
}
}

View File

@ -130,7 +130,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
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?

View File

@ -119,7 +119,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
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) {

View File

@ -33,7 +33,7 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
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 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
// 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 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
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 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
// 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,

View File

@ -60,11 +60,11 @@ GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height,
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);
}
}
};

View File

@ -274,7 +274,7 @@ void VulkanWindowContext::createBuffers(VkFormat format) {
info.fFormat = format;
info.fLevelCount = 1;
GrBackendTexture backendTex(fWidth, fHeight, &info);
GrBackendTexture backendTex(fWidth, fHeight, info);
fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext, backendTex,
kTopLeft_GrSurfaceOrigin,