Index: src/gpu/gl/GrGLGpu.cpp |
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp |
index fdf7eece7efb6f38b4d28e00a9cd4958bc00c887..d07203e376baba7dd0da29dddf0247ca0c1d5add 100644 |
--- a/src/gpu/gl/GrGLGpu.cpp |
+++ b/src/gpu/gl/GrGLGpu.cpp |
@@ -1594,7 +1594,7 @@ bool GrGLGpu::flushGLState(const DrawArgs& args) { |
} |
if (blendInfo.fWriteColor) { |
- this->flushBlend(blendInfo); |
+ this->flushBlend(blendInfo, SkToBool(args.fDesc->header().fSwapDstRedAndAlpha)); |
} |
SkSTArray<8, const GrTextureAccess*> textureAccesses; |
@@ -2073,6 +2073,30 @@ bool GrGLGpu::onReadPixels(GrSurface* surface, |
SkFAIL("Unknown resolve type"); |
} |
+ // This must be called after the RT is bound as the FBO above. |
+ if (!this->glCaps().readPixelsSupported(this->glInterface(), format, type, tgt->config())) { |
+ // We fail except the special case of reading back just the alpha channel of a RGBA/BGRA |
+ // target. |
+ if ((tgt->config() == kRGBA_8888_GrPixelConfig || |
+ tgt->config() == kBGRA_8888_GrPixelConfig) && |
+ kAlpha_8_GrPixelConfig == config) { |
+ SkDebugf(""); |
+ SkAutoTDeleteArray<uint32_t> temp(new uint32_t[width * height * 4]); |
+ if (this->onReadPixels(surface, left, top, width, height, tgt->config(), temp.get(), |
+ width*4)) { |
+ uint8_t* dst = reinterpret_cast<uint8_t*>(buffer); |
+ for (int j = 0; j < height; ++j) { |
+ for (int i = 0; i < width; ++i) { |
+ dst[j*rowBytes + i] = (0xFF000000U & temp[j*width+i]) >> 24; |
+ } |
+ } |
+ SkDebugf("rowBytes: %d\n", rowBytes); |
+ return true; |
+ } |
+ } |
+ return false; |
+ } |
+ |
const GrGLIRect& glvp = tgt->getViewport(); |
// the read rect is viewport-relative |
@@ -2422,7 +2446,7 @@ void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA) { |
} |
} |
-void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { |
+void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, bool swapConstRedAndAlpha) { |
// Any optimization to disable blending should have already been applied and |
// tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
@@ -2476,15 +2500,18 @@ void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { |
} |
GrColor blendConst = blendInfo.fBlendConstant; |
- if ((BlendCoeffReferencesConstant(srcCoeff) || |
- BlendCoeffReferencesConstant(dstCoeff)) && |
- (!fHWBlendState.fConstColorValid || |
- fHWBlendState.fConstColor != blendConst)) { |
- GrGLfloat c[4]; |
- GrColorToRGBAFloat(blendConst, c); |
- GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
- fHWBlendState.fConstColor = blendConst; |
- fHWBlendState.fConstColorValid = true; |
+ if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff))) { |
+ if (swapConstRedAndAlpha) { |
+ blendConst = GrColorPackRGBA(GrColorUnpackA(blendConst), GrColorUnpackG(blendConst), |
+ GrColorUnpackB(blendConst), GrColorUnpackR(blendConst)); |
+ } |
+ if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendConst) { |
+ GrGLfloat c[4]; |
+ GrColorToRGBAFloat(blendConst, c); |
+ GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
+ fHWBlendState.fConstColor = blendConst; |
+ fHWBlendState.fConstColorValid = true; |
+ } |
} |
} |
@@ -3330,7 +3357,7 @@ void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor |
GrXferProcessor::BlendInfo blendInfo; |
blendInfo.reset(); |
- this->flushBlend(blendInfo); |
+ this->flushBlend(blendInfo, false); |
this->flushColorWrite(true); |
this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
this->flushHWAAState(glRT, false); |
@@ -3401,7 +3428,7 @@ void GrGLGpu::copySurfaceAsDraw(GrSurface* dst, |
GrXferProcessor::BlendInfo blendInfo; |
blendInfo.reset(); |
- this->flushBlend(blendInfo); |
+ this->flushBlend(blendInfo, false); |
this->flushColorWrite(true); |
this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
this->flushHWAAState(dstRT, false); |