From 5d1d79a1f9d351e6f2390d844e6a7361d7d607ca Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 24 May 2013 18:52:52 +0000 Subject: [PATCH] fix slowness of getImageData() for CanvasRenderingContext2D in linux due to un-optimized format for glReadPixels This is a continuation of https://codereview.chromium.org/15331003/ BUG=242093 R=robertphillips@google.com, jun.a.jiang@intel.com, bsalomon@google.com Author: bsalomon@google.com Review URL: https://chromiumcodereview.appspot.com/15746007 git-svn-id: http://skia.googlecode.com/svn/trunk@9280 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrContext.cpp | 6 ++++-- src/gpu/GrGpu.h | 15 +++++++++++---- src/gpu/gl/GrGpuGL.cpp | 21 ++++++++++++++------- src/gpu/gl/GrGpuGL.h | 6 ++++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index d25709f0ea..751d869cfa 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1280,7 +1280,8 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target, // dstConfig. GrPixelConfig readConfig = dstConfig; bool swapRAndB = false; - if (GrPixelConfigSwapRAndB(dstConfig) == fGpu->preferredReadPixelsConfig(dstConfig)) { + if (GrPixelConfigSwapRAndB(dstConfig) == + fGpu->preferredReadPixelsConfig(dstConfig, target->config())) { readConfig = GrPixelConfigSwapRAndB(readConfig); swapRAndB = true; } @@ -1478,7 +1479,8 @@ bool GrContext::writeRenderTargetPixels(GrRenderTarget* target, // when drawing the scratch to the dst using a conversion effect. bool swapRAndB = false; GrPixelConfig writeConfig = srcConfig; - if (fGpu->preferredWritePixelsConfig(srcConfig) == GrPixelConfigSwapRAndB(srcConfig)) { + if (GrPixelConfigSwapRAndB(srcConfig) == + fGpu->preferredWritePixelsConfig(srcConfig, target->config())) { writeConfig = GrPixelConfigSwapRAndB(srcConfig); swapRAndB = true; } diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ade64312b8..5b556c5b25 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -152,11 +152,18 @@ public: void forceRenderTargetFlush(); /** - * Gets a preferred 8888 config to use for writing / reading pixel data. The returned config - * must have at least as many bits per channel as the config param. + * Gets a preferred 8888 config to use for writing/reading pixel data to/from a surface with + * config surfaceConfig. The returned config must have at least as many bits per channel as the + * readConfig or writeConfig param. */ - virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) const { return config; } - virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) const { return config; } + virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, + GrPixelConfig surfaceConfig) const { + return readConfig; + } + virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, + GrPixelConfig surfaceConfig) const { + return writeConfig; + } /** * Called before uploading writing pixels to a GrTexture when the src pixel config doesn't diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 035ef3bb1b..0c47060e4f 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -266,21 +266,28 @@ void GrGpuGL::fillInConfigRenderableTable() { } namespace { -GrPixelConfig preferred_pixel_ops_config(GrPixelConfig config) { - if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == config) { +GrPixelConfig preferred_pixel_ops_config(GrPixelConfig cpuConfig, GrPixelConfig surfaceConfig) { + if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == cpuConfig) { return kBGRA_8888_GrPixelConfig; + } else if (GrBytesPerPixel(cpuConfig) == 4 && + GrPixelConfigSwapRAndB(cpuConfig) == surfaceConfig) { + // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surface and vice-versa. + // Perhaps this should be guarded by some compiletime or runtime check. + return surfaceConfig; } else { - return config; + return cpuConfig; } } } -GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig config) const { - return preferred_pixel_ops_config(config); +GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig, + GrPixelConfig surfaceConfig) const { + return preferred_pixel_ops_config(readConfig, surfaceConfig); } -GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig config) const { - return preferred_pixel_ops_config(config); +GrPixelConfig GrGpuGL::preferredWritePixelsConfig(GrPixelConfig writeConfig, + GrPixelConfig surfaceConfig) const { + return preferred_pixel_ops_config(writeConfig, surfaceConfig); } bool GrGpuGL::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const { diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 8f80a72cbc..094fca1f1b 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -44,8 +44,10 @@ public: bool programUnitTest(int maxStages); // GrGpu overrides - virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) const SK_OVERRIDE; - virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) const SK_OVERRIDE; + virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, + GrPixelConfig surfaceConfig) const SK_OVERRIDE; + virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, + GrPixelConfig surfaceConfig) const SK_OVERRIDE; virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE; virtual bool readPixelsWillPayForYFlip( GrRenderTarget* renderTarget,