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
This commit is contained in:
commit-bot@chromium.org 2013-05-24 18:52:52 +00:00
parent 912e68ec46
commit 5d1d79a1f9
4 changed files with 33 additions and 15 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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 {

View File

@ -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,