Update SkSurface MakeFromBackend* factories to take an SkColorType.
Bug: skia:
Change-Id: Ib1b03b1181ec937843eac2e8d8cb03ebe53e32c1
Reviewed-on: https://skia-review.googlesource.com/86760
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tools/fiddle/draw.cpp b/tools/fiddle/draw.cpp
index 05866e3..bbc463c 100644
--- a/tools/fiddle/draw.cpp
+++ b/tools/fiddle/draw.cpp
@@ -33,6 +33,7 @@
sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context,
backEndTexture,
kTopLeft_GrSurfaceOrigin,
+ kRGBA_8888_SkColorType,
kOpaque_SkAlphaType,
nullptr);
@@ -40,13 +41,14 @@
sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context,
backEndTextureRenderTarget,
kTopLeft_GrSurfaceOrigin,
- 0, nullptr, nullptr);
+ 0, kRGBA_8888_SkColorType,
+ nullptr, nullptr);
// Note: this surface should only be renderable (i.e., not textureable)
sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(context,
backEndRenderTarget,
kTopLeft_GrSurfaceOrigin,
+ kRGBA_8888_SkColorType,
nullptr, nullptr);
}
-
}
diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp
index 4c7a087..b22ec55 100644
--- a/tools/fiddle/fiddle_main.cpp
+++ b/tools/fiddle/fiddle_main.cpp
@@ -129,6 +129,7 @@
backingDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
backingDesc.fWidth = bm.width();
backingDesc.fHeight = bm.height();
+ // This config must match the SkColorType used in draw.cpp in the SkImage and Surface factories
backingDesc.fConfig = kRGBA_8888_GrPixelConfig;
backingDesc.fSampleCnt = 0;
diff --git a/tools/sk_app/GLWindowContext.cpp b/tools/sk_app/GLWindowContext.cpp
index d928a7b..9ef5141 100644
--- a/tools/sk_app/GLWindowContext.cpp
+++ b/tools/sk_app/GLWindowContext.cpp
@@ -39,15 +39,6 @@
this->initializeContext();
return;
}
-
- if (fContext) {
- // We may not have real sRGB support (ANGLE, in particular), so check for
- // that, and fall back to L32:
- fPixelConfig = fContext->caps()->srgbSupport() && fDisplayParams.fColorSpace
- ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
- } else {
- fPixelConfig = kUnknown_GrPixelConfig;
- }
}
void GLWindowContext::destroyContext() {
@@ -72,16 +63,18 @@
GR_GL_CALL(fBackendContext.get(), GetIntegerv(GR_GL_FRAMEBUFFER_BINDING,
&buffer));
fbInfo.fFBOID = buffer;
+ fbInfo.fFormat = fContext->caps()->srgbSupport() && fDisplayParams.fColorSpace
+ ? GR_GL_SRGB8_ALPHA8 : GR_GL_RGBA8;
GrBackendRenderTarget backendRT(fWidth,
fHeight,
fSampleCount,
fStencilBits,
- fPixelConfig,
fbInfo);
fSurface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
kBottomLeft_GrSurfaceOrigin,
+ kRGBA_8888_SkColorType,
fDisplayParams.fColorSpace,
&fSurfaceProps);
}
diff --git a/tools/sk_app/VulkanWindowContext.cpp b/tools/sk_app/VulkanWindowContext.cpp
index 711791d..6237ee0 100644
--- a/tools/sk_app/VulkanWindowContext.cpp
+++ b/tools/sk_app/VulkanWindowContext.cpp
@@ -201,6 +201,20 @@
return false;
}
+ SkColorType colorType;
+ switch (surfaceFormat) {
+ case VK_FORMAT_R8G8B8A8_UNORM: // fall through
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ colorType = kRGBA_8888_SkColorType;
+ break;
+ case VK_FORMAT_B8G8R8A8_UNORM: // fall through
+ case VK_FORMAT_B8G8R8A8_SRGB:
+ colorType = kBGRA_8888_SkColorType;
+ break;
+ default:
+ return false;
+ }
+
// If mailbox mode is available, use it, as it is the lowest-latency non-
// tearing mode. If not, fall back to FIFO which is always available.
VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR;
@@ -254,15 +268,12 @@
fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSwapchain, nullptr);
}
- this->createBuffers(swapchainCreateInfo.imageFormat);
+ this->createBuffers(swapchainCreateInfo.imageFormat, colorType);
return true;
}
-void VulkanWindowContext::createBuffers(VkFormat format) {
- fPixelConfig = GrVkFormatToPixelConfig(format);
- SkASSERT(kUnknown_GrPixelConfig != fPixelConfig);
-
+void VulkanWindowContext::createBuffers(VkFormat format, SkColorType colorType) {
fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, nullptr);
SkASSERT(fImageCount);
fImages = new VkImage[fImageCount];
@@ -287,6 +298,7 @@
fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(), backendTex,
kTopLeft_GrSurfaceOrigin,
fSampleCount,
+ colorType,
fDisplayParams.fColorSpace,
&fSurfaceProps);
}
diff --git a/tools/sk_app/VulkanWindowContext.h b/tools/sk_app/VulkanWindowContext.h
index d02b114..df6ef33 100644
--- a/tools/sk_app/VulkanWindowContext.h
+++ b/tools/sk_app/VulkanWindowContext.h
@@ -64,7 +64,7 @@
BackbufferInfo* getAvailableBackbuffer();
bool createSwapchain(int width, int height, const DisplayParams& params);
- void createBuffers(VkFormat format);
+ void createBuffers(VkFormat format, SkColorType colorType);
void destroyBuffers();
sk_sp<const GrVkBackendContext> fBackendContext;
diff --git a/tools/sk_app/WindowContext.h b/tools/sk_app/WindowContext.h
index cd4c357..5e7d76d 100644
--- a/tools/sk_app/WindowContext.h
+++ b/tools/sk_app/WindowContext.h
@@ -61,7 +61,6 @@
int fWidth;
int fHeight;
DisplayParams fDisplayParams;
- GrPixelConfig fPixelConfig;
SkSurfaceProps fSurfaceProps;
// parameters obtained from the native window