Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1530713002: make alpha read back of bgra/rgba work (Closed) Base URL: https://skia.googlesource.com/skia.git@align
Patch Set: cleanup Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDesc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "GrGLGLSL.h" 10 #include "GrGLGLSL.h"
(...skipping 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 return false; 1587 return false;
1588 } 1588 }
1589 1589
1590 GrGLuint programID = program->programID(); 1590 GrGLuint programID = program->programID();
1591 if (fHWProgramID != programID) { 1591 if (fHWProgramID != programID) {
1592 GL_CALL(UseProgram(programID)); 1592 GL_CALL(UseProgram(programID));
1593 fHWProgramID = programID; 1593 fHWProgramID = programID;
1594 } 1594 }
1595 1595
1596 if (blendInfo.fWriteColor) { 1596 if (blendInfo.fWriteColor) {
1597 this->flushBlend(blendInfo); 1597 this->flushBlend(blendInfo, SkToBool(args.fDesc->header().fSwapDstRedAnd Alpha));
1598 } 1598 }
1599 1599
1600 SkSTArray<8, const GrTextureAccess*> textureAccesses; 1600 SkSTArray<8, const GrTextureAccess*> textureAccesses;
1601 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); 1601 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses);
1602 1602
1603 int numTextureAccesses = textureAccesses.count(); 1603 int numTextureAccesses = textureAccesses.count();
1604 for (int i = 0; i < numTextureAccesses; i++) { 1604 for (int i = 0; i < numTextureAccesses; i++) {
1605 this->bindTexture(i, textureAccesses[i]->getParams(), 1605 this->bindTexture(i, textureAccesses[i]->getParams(),
1606 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re())); 1606 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re()));
1607 } 1607 }
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 this->onResolveRenderTarget(tgt); 2066 this->onResolveRenderTarget(tgt);
2067 // we don't track the state of the READ FBO ID. 2067 // we don't track the state of the READ FBO ID.
2068 fStats.incRenderTargetBinds(); 2068 fStats.incRenderTargetBinds();
2069 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, 2069 GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
2070 tgt->textureFBOID())); 2070 tgt->textureFBOID()));
2071 break; 2071 break;
2072 default: 2072 default:
2073 SkFAIL("Unknown resolve type"); 2073 SkFAIL("Unknown resolve type");
2074 } 2074 }
2075 2075
2076 // This must be called after the RT is bound as the FBO above.
2077 if (!this->glCaps().readPixelsSupported(this->glInterface(), format, type, t gt->config())) {
2078 // We fail except the special case of reading back just the alpha channe l of a RGBA/BGRA
2079 // target.
2080 if ((tgt->config() == kRGBA_8888_GrPixelConfig ||
2081 tgt->config() == kBGRA_8888_GrPixelConfig) &&
2082 kAlpha_8_GrPixelConfig == config) {
2083 SkDebugf("");
2084 SkAutoTDeleteArray<uint32_t> temp(new uint32_t[width * height * 4]);
2085 if (this->onReadPixels(surface, left, top, width, height, tgt->confi g(), temp.get(),
2086 width*4)) {
2087 uint8_t* dst = reinterpret_cast<uint8_t*>(buffer);
2088 for (int j = 0; j < height; ++j) {
2089 for (int i = 0; i < width; ++i) {
2090 dst[j*rowBytes + i] = (0xFF000000U & temp[j*width+i]) >> 24;
2091 }
2092 }
2093 SkDebugf("rowBytes: %d\n", rowBytes);
2094 return true;
2095 }
2096 }
2097 return false;
2098 }
2099
2076 const GrGLIRect& glvp = tgt->getViewport(); 2100 const GrGLIRect& glvp = tgt->getViewport();
2077 2101
2078 // the read rect is viewport-relative 2102 // the read rect is viewport-relative
2079 GrGLIRect readRect; 2103 GrGLIRect readRect;
2080 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin()); 2104 readRect.setRelativeTo(glvp, left, top, width, height, tgt->origin());
2081 2105
2082 size_t tightRowBytes = GrBytesPerPixel(config) * width; 2106 size_t tightRowBytes = GrBytesPerPixel(config) * width;
2083 2107
2084 size_t readDstRowBytes = tightRowBytes; 2108 size_t readDstRowBytes = tightRowBytes;
2085 void* readDst = buffer; 2109 void* readDst = buffer;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 } 2439 }
2416 } else { 2440 } else {
2417 if (kNo_TriState != fMSAAEnabled) { 2441 if (kNo_TriState != fMSAAEnabled) {
2418 GL_CALL(Disable(GR_GL_MULTISAMPLE)); 2442 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2419 fMSAAEnabled = kNo_TriState; 2443 fMSAAEnabled = kNo_TriState;
2420 } 2444 }
2421 } 2445 }
2422 } 2446 }
2423 } 2447 }
2424 2448
2425 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { 2449 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, bool swapC onstRedAndAlpha) {
2426 // Any optimization to disable blending should have already been applied and 2450 // Any optimization to disable blending should have already been applied and
2427 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). 2451 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0).
2428 2452
2429 GrBlendEquation equation = blendInfo.fEquation; 2453 GrBlendEquation equation = blendInfo.fEquation;
2430 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 2454 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
2431 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 2455 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
2432 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) && 2456 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) &&
2433 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; 2457 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff;
2434 if (blendOff) { 2458 if (blendOff) {
2435 if (kNo_TriState != fHWBlendState.fEnabled) { 2459 if (kNo_TriState != fHWBlendState.fEnabled) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 2493
2470 if (fHWBlendState.fSrcCoeff != srcCoeff || 2494 if (fHWBlendState.fSrcCoeff != srcCoeff ||
2471 fHWBlendState.fDstCoeff != dstCoeff) { 2495 fHWBlendState.fDstCoeff != dstCoeff) {
2472 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], 2496 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
2473 gXfermodeCoeff2Blend[dstCoeff])); 2497 gXfermodeCoeff2Blend[dstCoeff]));
2474 fHWBlendState.fSrcCoeff = srcCoeff; 2498 fHWBlendState.fSrcCoeff = srcCoeff;
2475 fHWBlendState.fDstCoeff = dstCoeff; 2499 fHWBlendState.fDstCoeff = dstCoeff;
2476 } 2500 }
2477 2501
2478 GrColor blendConst = blendInfo.fBlendConstant; 2502 GrColor blendConst = blendInfo.fBlendConstant;
2479 if ((BlendCoeffReferencesConstant(srcCoeff) || 2503 if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant( dstCoeff))) {
2480 BlendCoeffReferencesConstant(dstCoeff)) && 2504 if (swapConstRedAndAlpha) {
2481 (!fHWBlendState.fConstColorValid || 2505 blendConst = GrColorPackRGBA(GrColorUnpackA(blendConst), GrColorUnpa ckG(blendConst),
2482 fHWBlendState.fConstColor != blendConst)) { 2506 GrColorUnpackB(blendConst), GrColorUnpa ckR(blendConst));
2483 GrGLfloat c[4]; 2507 }
2484 GrColorToRGBAFloat(blendConst, c); 2508 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blen dConst) {
2485 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); 2509 GrGLfloat c[4];
2486 fHWBlendState.fConstColor = blendConst; 2510 GrColorToRGBAFloat(blendConst, c);
2487 fHWBlendState.fConstColorValid = true; 2511 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
2512 fHWBlendState.fConstColor = blendConst;
2513 fHWBlendState.fConstColorValid = true;
2514 }
2488 } 2515 }
2489 } 2516 }
2490 2517
2491 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { 2518 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
2492 static const GrGLenum gWrapModes[] = { 2519 static const GrGLenum gWrapModes[] = {
2493 GR_GL_CLAMP_TO_EDGE, 2520 GR_GL_CLAMP_TO_EDGE,
2494 GR_GL_REPEAT, 2521 GR_GL_REPEAT,
2495 GR_GL_MIRRORED_REPEAT 2522 GR_GL_MIRRORED_REPEAT
2496 }; 2523 };
2497 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); 2524 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes));
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 GrGLAttribArrayState* attribs = 3350 GrGLAttribArrayState* attribs =
3324 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer); 3351 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer);
3325 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo f(GrGLfloat), 0); 3352 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo f(GrGLfloat), 0);
3326 attribs->disableUnusedArrays(this, 0x1); 3353 attribs->disableUnusedArrays(this, 0x1);
3327 3354
3328 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); 3355 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges));
3329 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); 3356 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels));
3330 3357
3331 GrXferProcessor::BlendInfo blendInfo; 3358 GrXferProcessor::BlendInfo blendInfo;
3332 blendInfo.reset(); 3359 blendInfo.reset();
3333 this->flushBlend(blendInfo); 3360 this->flushBlend(blendInfo, false);
3334 this->flushColorWrite(true); 3361 this->flushColorWrite(true);
3335 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 3362 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
3336 this->flushHWAAState(glRT, false); 3363 this->flushHWAAState(glRT, false);
3337 this->disableScissor(); 3364 this->disableScissor();
3338 GrStencilSettings stencil; 3365 GrStencilSettings stencil;
3339 stencil.setDisabled(); 3366 stencil.setDisabled();
3340 this->flushStencil(stencil); 3367 this->flushStencil(stencil);
3341 3368
3342 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); 3369 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4));
3343 } 3370 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 sy1 = 1.f - sy1; 3421 sy1 = 1.f - sy1;
3395 } 3422 }
3396 3423
3397 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); 3424 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0));
3398 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, 3425 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform,
3399 sx1 - sx0, sy1 - sy0, sx0, sy0)); 3426 sx1 - sx0, sy1 - sy0, sx0, sy0));
3400 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); 3427 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0));
3401 3428
3402 GrXferProcessor::BlendInfo blendInfo; 3429 GrXferProcessor::BlendInfo blendInfo;
3403 blendInfo.reset(); 3430 blendInfo.reset();
3404 this->flushBlend(blendInfo); 3431 this->flushBlend(blendInfo, false);
3405 this->flushColorWrite(true); 3432 this->flushColorWrite(true);
3406 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 3433 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
3407 this->flushHWAAState(dstRT, false); 3434 this->flushHWAAState(dstRT, false);
3408 this->disableScissor(); 3435 this->disableScissor();
3409 GrStencilSettings stencil; 3436 GrStencilSettings stencil;
3410 stencil.setDisabled(); 3437 stencil.setDisabled();
3411 this->flushStencil(stencil); 3438 this->flushStencil(stencil);
3412 3439
3413 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); 3440 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
3414 } 3441 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 this->setVertexArrayID(gpu, 0); 3676 this->setVertexArrayID(gpu, 0);
3650 } 3677 }
3651 int attrCount = gpu->glCaps().maxVertexAttributes(); 3678 int attrCount = gpu->glCaps().maxVertexAttributes();
3652 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3679 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3653 fDefaultVertexArrayAttribState.resize(attrCount); 3680 fDefaultVertexArrayAttribState.resize(attrCount);
3654 } 3681 }
3655 attribState = &fDefaultVertexArrayAttribState; 3682 attribState = &fDefaultVertexArrayAttribState;
3656 } 3683 }
3657 return attribState; 3684 return attribState;
3658 } 3685 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDesc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698