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

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

Issue 1584473002: Swizzle shader output and blend when using GL_RED to implement kAlpha_8_GrPixelConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@hideformats
Patch Set: Address comments Created 4 years, 11 months 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.h » ('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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 return false; 1563 return false;
1564 } 1564 }
1565 1565
1566 GrGLuint programID = program->programID(); 1566 GrGLuint programID = program->programID();
1567 if (fHWProgramID != programID) { 1567 if (fHWProgramID != programID) {
1568 GL_CALL(UseProgram(programID)); 1568 GL_CALL(UseProgram(programID));
1569 fHWProgramID = programID; 1569 fHWProgramID = programID;
1570 } 1570 }
1571 1571
1572 if (blendInfo.fWriteColor) { 1572 if (blendInfo.fWriteColor) {
1573 this->flushBlend(blendInfo); 1573 // Swizzle the blend to match what the shader will output.
1574 const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzl e(
1575 args.fPipeline->getRenderTarget()->config());
1576 this->flushBlend(blendInfo, swizzle);
1574 } 1577 }
1575 1578
1576 SkSTArray<8, const GrTextureAccess*> textureAccesses; 1579 SkSTArray<8, const GrTextureAccess*> textureAccesses;
1577 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses); 1580 program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses);
1578 1581
1579 int numTextureAccesses = textureAccesses.count(); 1582 int numTextureAccesses = textureAccesses.count();
1580 for (int i = 0; i < numTextureAccesses; i++) { 1583 for (int i = 0; i < numTextureAccesses; i++) {
1581 this->bindTexture(i, textureAccesses[i]->getParams(), 1584 this->bindTexture(i, textureAccesses[i]->getParams(),
1582 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re())); 1585 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu re()));
1583 } 1586 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset)); 1646 reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + o ffset));
1644 offset += attrib.fOffset; 1647 offset += attrib.fOffset;
1645 } 1648 }
1646 attribState->disableUnusedArrays(this, usedAttribArraysMask); 1649 attribState->disableUnusedArrays(this, usedAttribArraysMask);
1647 } 1650 }
1648 } 1651 }
1649 1652
1650 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc, 1653 void GrGLGpu::buildProgramDesc(GrProgramDesc* desc,
1651 const GrPrimitiveProcessor& primProc, 1654 const GrPrimitiveProcessor& primProc,
1652 const GrPipeline& pipeline) const { 1655 const GrPipeline& pipeline) const {
1653 if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, this)) { 1656 if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, *this->glCaps() .glslCaps())) {
1654 SkDEBUGFAIL("Failed to generate GL program descriptor"); 1657 SkDEBUGFAIL("Failed to generate GL program descriptor");
1655 } 1658 }
1656 } 1659 }
1657 1660
1658 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) { 1661 void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) {
1659 this->handleDirtyContext(); 1662 this->handleDirtyContext();
1660 if (GR_GL_ARRAY_BUFFER == type) { 1663 if (GR_GL_ARRAY_BUFFER == type) {
1661 this->bindVertexBuffer(id); 1664 this->bindVertexBuffer(id);
1662 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) { 1665 } else if (GR_GL_ELEMENT_ARRAY_BUFFER == type) {
1663 this->bindIndexBufferAndDefaultVertexArray(id); 1666 this->bindIndexBufferAndDefaultVertexArray(id);
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 } 2391 }
2389 } else { 2392 } else {
2390 if (kNo_TriState != fMSAAEnabled) { 2393 if (kNo_TriState != fMSAAEnabled) {
2391 GL_CALL(Disable(GR_GL_MULTISAMPLE)); 2394 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2392 fMSAAEnabled = kNo_TriState; 2395 fMSAAEnabled = kNo_TriState;
2393 } 2396 }
2394 } 2397 }
2395 } 2398 }
2396 } 2399 }
2397 2400
2398 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { 2401 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSw izzle& swizzle) {
2399 // Any optimization to disable blending should have already been applied and 2402 // Any optimization to disable blending should have already been applied and
2400 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). 2403 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0).
2401 2404
2402 GrBlendEquation equation = blendInfo.fEquation; 2405 GrBlendEquation equation = blendInfo.fEquation;
2403 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 2406 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
2404 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 2407 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
2405 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) && 2408 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) &&
2406 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; 2409 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff;
2407 if (blendOff) { 2410 if (blendOff) {
2408 if (kNo_TriState != fHWBlendState.fEnabled) { 2411 if (kNo_TriState != fHWBlendState.fEnabled) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 } 2444 }
2442 2445
2443 if (fHWBlendState.fSrcCoeff != srcCoeff || 2446 if (fHWBlendState.fSrcCoeff != srcCoeff ||
2444 fHWBlendState.fDstCoeff != dstCoeff) { 2447 fHWBlendState.fDstCoeff != dstCoeff) {
2445 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], 2448 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
2446 gXfermodeCoeff2Blend[dstCoeff])); 2449 gXfermodeCoeff2Blend[dstCoeff]));
2447 fHWBlendState.fSrcCoeff = srcCoeff; 2450 fHWBlendState.fSrcCoeff = srcCoeff;
2448 fHWBlendState.fDstCoeff = dstCoeff; 2451 fHWBlendState.fDstCoeff = dstCoeff;
2449 } 2452 }
2450 2453
2451 GrColor blendConst = blendInfo.fBlendConstant; 2454 if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant( dstCoeff))) {
2452 if ((BlendCoeffReferencesConstant(srcCoeff) || 2455 GrColor blendConst = blendInfo.fBlendConstant;
2453 BlendCoeffReferencesConstant(dstCoeff)) && 2456 blendConst = swizzle.applyTo(blendConst);
2454 (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendCo nst)) { 2457 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blen dConst) {
2455 GrGLfloat c[4]; 2458 GrGLfloat c[4];
2456 GrColorToRGBAFloat(blendConst, c); 2459 GrColorToRGBAFloat(blendConst, c);
2457 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); 2460 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
2458 fHWBlendState.fConstColor = blendConst; 2461 fHWBlendState.fConstColor = blendConst;
2459 fHWBlendState.fConstColorValid = true; 2462 fHWBlendState.fConstColorValid = true;
2463 }
2460 } 2464 }
2461 } 2465 }
2462 2466
2463 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { 2467 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
2464 static const GrGLenum gWrapModes[] = { 2468 static const GrGLenum gWrapModes[] = {
2465 GR_GL_CLAMP_TO_EDGE, 2469 GR_GL_CLAMP_TO_EDGE,
2466 GR_GL_REPEAT, 2470 GR_GL_REPEAT,
2467 GR_GL_MIRRORED_REPEAT 2471 GR_GL_MIRRORED_REPEAT
2468 }; 2472 };
2469 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); 2473 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes));
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 desc->fConfig = src->config(); 2837 desc->fConfig = src->config();
2834 desc->fOrigin = src->origin(); 2838 desc->fOrigin = src->origin();
2835 desc->fFlags = kNone_GrSurfaceFlags; 2839 desc->fFlags = kNone_GrSurfaceFlags;
2836 return true; 2840 return true;
2837 } 2841 }
2838 2842
2839 bool GrGLGpu::onCopySurface(GrSurface* dst, 2843 bool GrGLGpu::onCopySurface(GrSurface* dst,
2840 GrSurface* src, 2844 GrSurface* src,
2841 const SkIRect& srcRect, 2845 const SkIRect& srcRect,
2842 const SkIPoint& dstPoint) { 2846 const SkIPoint& dstPoint) {
2847 // None of our copy methods can handle a swizzle. TODO: Make copySurfaceAsDr aw handle the
2848 // swizzle.
2849 if (this->glCaps().glslCaps()->configOutputSwizzle(src->config()) !=
2850 this->glCaps().glslCaps()->configOutputSwizzle(dst->config())) {
2851 return false;
2852 }
2843 if (src->asTexture() && dst->asRenderTarget()) { 2853 if (src->asTexture() && dst->asRenderTarget()) {
2844 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint); 2854 this->copySurfaceAsDraw(dst, src, srcRect, dstPoint);
2845 return true; 2855 return true;
2846 } 2856 }
2847 2857
2848 if (can_copy_texsubimage(dst, src, this)) { 2858 if (can_copy_texsubimage(dst, src, this)) {
2849 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint); 2859 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint);
2850 return true; 2860 return true;
2851 } 2861 }
2852 2862
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3057 1, 0, 3067 1, 0,
3058 }; 3068 };
3059 GL_ALLOC_CALL(this->glInterface(), 3069 GL_ALLOC_CALL(this->glInterface(),
3060 BufferData(GR_GL_ARRAY_BUFFER, 3070 BufferData(GR_GL_ARRAY_BUFFER,
3061 (GrGLsizeiptr) sizeof(vdata), 3071 (GrGLsizeiptr) sizeof(vdata),
3062 vdata, // data ptr 3072 vdata, // data ptr
3063 GR_GL_STATIC_DRAW)); 3073 GR_GL_STATIC_DRAW));
3064 } 3074 }
3065 3075
3066 void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor color) { 3076 void GrGLGpu::drawDebugWireRect(GrRenderTarget* rt, const SkIRect& rect, GrColor color) {
3077 // TODO: This should swizzle the output to match dst's config, though it is a debugging
3078 // visualization.
3079
3067 this->handleDirtyContext(); 3080 this->handleDirtyContext();
3068 if (!fWireRectProgram.fProgram) { 3081 if (!fWireRectProgram.fProgram) {
3069 this->createWireRectProgram(); 3082 this->createWireRectProgram();
3070 } 3083 }
3071 3084
3072 int w = rt->width(); 3085 int w = rt->width();
3073 int h = rt->height(); 3086 int h = rt->height();
3074 3087
3075 // Compute the edges of the rectangle (top,left,right,bottom) in NDC space. Must consider 3088 // Compute the edges of the rectangle (top,left,right,bottom) in NDC space. Must consider
3076 // whether the render target is flipped or not. 3089 // whether the render target is flipped or not.
(...skipping 30 matching lines...) Expand all
3107 GrGLAttribArrayState* attribs = 3120 GrGLAttribArrayState* attribs =
3108 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer); 3121 fHWGeometryState.bindArrayAndBufferToDraw(this, fWireRectArrayBuffer);
3109 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo f(GrGLfloat), 0); 3122 attribs->set(this, 0, fWireRectArrayBuffer, 2, GR_GL_FLOAT, false, 2 * sizeo f(GrGLfloat), 0);
3110 attribs->disableUnusedArrays(this, 0x1); 3123 attribs->disableUnusedArrays(this, 0x1);
3111 3124
3112 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges)); 3125 GL_CALL(Uniform4fv(fWireRectProgram.fRectUniform, 1, edges));
3113 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels)); 3126 GL_CALL(Uniform4fv(fWireRectProgram.fColorUniform, 1, channels));
3114 3127
3115 GrXferProcessor::BlendInfo blendInfo; 3128 GrXferProcessor::BlendInfo blendInfo;
3116 blendInfo.reset(); 3129 blendInfo.reset();
3117 this->flushBlend(blendInfo); 3130 this->flushBlend(blendInfo, GrSwizzle::RGBA());
3118 this->flushColorWrite(true); 3131 this->flushColorWrite(true);
3119 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 3132 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
3120 this->flushHWAAState(glRT, false); 3133 this->flushHWAAState(glRT, false);
3121 this->disableScissor(); 3134 this->disableScissor();
3122 GrStencilSettings stencil; 3135 GrStencilSettings stencil;
3123 stencil.setDisabled(); 3136 stencil.setDisabled();
3124 this->flushStencil(stencil); 3137 this->flushStencil(stencil);
3125 3138
3126 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4)); 3139 GL_CALL(DrawArrays(GR_GL_LINE_LOOP, 0, 4));
3127 } 3140 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3178 sy1 = 1.f - sy1; 3191 sy1 = 1.f - sy1;
3179 } 3192 }
3180 3193
3181 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); 3194 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0));
3182 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, 3195 GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform,
3183 sx1 - sx0, sy1 - sy0, sx0, sy0)); 3196 sx1 - sx0, sy1 - sy0, sx0, sy0));
3184 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); 3197 GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0));
3185 3198
3186 GrXferProcessor::BlendInfo blendInfo; 3199 GrXferProcessor::BlendInfo blendInfo;
3187 blendInfo.reset(); 3200 blendInfo.reset();
3188 this->flushBlend(blendInfo); 3201 this->flushBlend(blendInfo, GrSwizzle::RGBA());
3189 this->flushColorWrite(true); 3202 this->flushColorWrite(true);
3190 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); 3203 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace);
3191 this->flushHWAAState(dstRT, false); 3204 this->flushHWAAState(dstRT, false);
3192 this->disableScissor(); 3205 this->disableScissor();
3193 GrStencilSettings stencil; 3206 GrStencilSettings stencil;
3194 stencil.setDisabled(); 3207 stencil.setDisabled();
3195 this->flushStencil(stencil); 3208 this->flushStencil(stencil);
3196 3209
3197 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); 3210 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
3198 } 3211 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 this->setVertexArrayID(gpu, 0); 3457 this->setVertexArrayID(gpu, 0);
3445 } 3458 }
3446 int attrCount = gpu->glCaps().maxVertexAttributes(); 3459 int attrCount = gpu->glCaps().maxVertexAttributes();
3447 if (fDefaultVertexArrayAttribState.count() != attrCount) { 3460 if (fDefaultVertexArrayAttribState.count() != attrCount) {
3448 fDefaultVertexArrayAttribState.resize(attrCount); 3461 fDefaultVertexArrayAttribState.resize(attrCount);
3449 } 3462 }
3450 attribState = &fDefaultVertexArrayAttribState; 3463 attribState = &fDefaultVertexArrayAttribState;
3451 } 3464 }
3452 return attribState; 3465 return attribState;
3453 } 3466 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698