When GL_RGBA readPixels are slow do swizzle using a draw then readPixels with GL_BGRA
Review URL: http://codereview.appspot.com/5339051/
git-svn-id: http://skia.googlecode.com/svn/trunk@2631 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 8c06c21..8dbd411 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1673,19 +1673,30 @@
this->flush();
GrTexture* src = target->asTexture();
+ bool swapRAndB = NULL != src &&
+ fGpu->preferredReadPixelsConfig(config) ==
+ GrPixelConfigSwapRAndB(config);
bool flipY = NULL != src &&
fGpu->readPixelsWillPayForYFlip(target, left, top,
width, height, config,
rowBytes);
+ bool alphaConversion = (!GrPixelConfigIsUnpremultiplied(target->config()) &&
+ GrPixelConfigIsUnpremultiplied(config));
- if (flipY || (!GrPixelConfigIsUnpremultiplied(target->config()) &&
- GrPixelConfigIsUnpremultiplied(config))) {
- if (!src) {
- // we should fallback to cpu conversion here. This could happen when
- // we were given an external render target by the client that is not
- // also a texture (e.g. FBO 0 in GL)
- return false;
+ if (NULL == src && alphaConversion) {
+ // we should fallback to cpu conversion here. This could happen when
+ // we were given an external render target by the client that is not
+ // also a texture (e.g. FBO 0 in GL)
+ return false;
+ }
+
+ // we draw to a scratch texture if any of these conversion are applied
+ if (flipY || swapRAndB || alphaConversion) {
+ GrAssert(NULL != src);
+ if (swapRAndB) {
+ config = GrPixelConfigSwapRAndB(config);
+ GrAssert(kUnknown_GrPixelConfig != config);
}
// Make the scratch a render target because we don't have a robust
// readTexturePixels as of yet (it calls this function).
@@ -1715,6 +1726,7 @@
GrSamplerState sampler;
sampler.setClampNoFilter();
+ sampler.setRAndBSwap(swapRAndB);
GrMatrix matrix;
if (flipY) {
matrix.setTranslate(SK_Scalar1 * left,