Prepare sRGB encoding conversion for the removal of GrPixelConfig
Standardizes that GrGpu subclass's onRead/WritePixels never do sRGB<->linear conversion. This means that they can eventually take a color type rather than config. It also means direct callers of GrGpu::read/writePixels can never expect conversion (which in practice is no change).
Consolidate logic about whether to do sRGB<->linear encoding conversions in GrContext::read/writeSurfacePixels helpers. No change in when conversions are done (yet). This prepares this logic to operate on SkColorSpace and color type rather than config WRT the CPU data.
Bug: skia:6718
Change-Id: I346d669624861578f1bb9ea465a7ab4b549117fa
Reviewed-on: https://skia-review.googlesource.com/105286
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 35c2fcc..daa4057 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -340,6 +340,14 @@
int width, int height,
GrPixelConfig srcConfig, DrawPreference* drawPreference,
WritePixelTempDrawInfo* tempDrawInfo) {
+ if (*drawPreference != kNoDraw_DrawPreference) {
+ // We assume the base class has only inserted a draw for sRGB reasons. So the temp surface
+ // has the config of the original src data. There is no swizzling nor src config spoofing.
+ SkASSERT(tempDrawInfo->fWriteConfig == srcConfig);
+ SkASSERT(tempDrawInfo->fTempSurfaceDesc.fConfig == srcConfig);
+ SkASSERT(tempDrawInfo->fSwizzle == GrSwizzle::RGBA());
+ }
+
GrRenderTarget* renderTarget = dstSurface->asRenderTarget();
if (dstSurface->config() == srcConfig) {
@@ -381,11 +389,6 @@
return false;
}
- // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and writing pixels.
- if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) {
- return false;
- }
-
bool success = false;
bool linearTiling = vkTex->isLinearTiled();
if (linearTiling) {
@@ -435,11 +438,6 @@
return false;
}
- // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and writing pixels.
- if (GrPixelConfigIsSRGB(texture->config()) != GrPixelConfigIsSRGB(config)) {
- return false;
- }
-
SkDEBUGCODE(
SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height);
SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height());
@@ -1859,29 +1857,35 @@
*effectiveSampleCnt = rt->numStencilSamples();
}
-bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrigin,
- int width, int height, size_t rowBytes,
- GrPixelConfig readConfig, DrawPreference* drawPreference,
+bool GrVkGpu::onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrigin, int width,
+ int height, size_t rowBytes, GrPixelConfig dstConfig,
+ DrawPreference* drawPreference,
ReadPixelTempDrawInfo* tempDrawInfo) {
- if (srcSurface->config() == readConfig) {
+ if (*drawPreference != kNoDraw_DrawPreference) {
+ // We assume the base class has only inserted a draw for sRGB reasons. So the
+ // the temp surface has the config of the dst data. There is no swizzling nor dst config.
+ // spoofing.
+ SkASSERT(tempDrawInfo->fReadConfig == dstConfig);
+ SkASSERT(tempDrawInfo->fTempSurfaceDesc.fConfig == dstConfig);
+ SkASSERT(tempDrawInfo->fSwizzle == GrSwizzle::RGBA());
+ }
+
+ if (srcSurface->config() == dstConfig) {
return true;
}
// Any config change requires a draw
ElevateDrawPreference(drawPreference, kRequireDraw_DrawPreference);
- tempDrawInfo->fTempSurfaceDesc.fConfig = readConfig;
- tempDrawInfo->fReadConfig = readConfig;
+ tempDrawInfo->fTempSurfaceDesc.fConfig = dstConfig;
+ tempDrawInfo->fReadConfig = dstConfig;
return true;
}
-bool GrVkGpu::onReadPixels(GrSurface* surface, GrSurfaceOrigin origin,
- int left, int top, int width, int height,
- GrPixelConfig config,
- void* buffer,
- size_t rowBytes) {
+bool GrVkGpu::onReadPixels(GrSurface* surface, GrSurfaceOrigin origin, int left, int top, int width,
+ int height, GrPixelConfig dstConfig, void* buffer, size_t rowBytes) {
VkFormat pixelFormat;
- if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
+ if (!GrPixelConfigToVkFormat(dstConfig, &pixelFormat)) {
return false;
}
@@ -1916,7 +1920,7 @@
VK_PIPELINE_STAGE_TRANSFER_BIT,
false);
- size_t bpp = GrBytesPerPixel(config);
+ size_t bpp = GrBytesPerPixel(dstConfig);
size_t tightRowBytes = bpp * width;
bool flipY = kBottomLeft_GrSurfaceOrigin == origin;