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

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

Issue 1037123003: Implement support for KHR_blend_equation_advanced (Closed) Base URL: https://skia.googlesource.com/skia.git@upload_zzz2_barriers
Patch Set: Compiler warning Created 5 years, 7 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/builders/GrGLFragmentShaderBuilder.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 "GrGLStencilAttachment.h" 10 #include "GrGLStencilAttachment.h"
(...skipping 20 matching lines...) Expand all
31 #else 31 #else
32 #define CLEAR_ERROR_BEFORE_ALLOC(iface) 32 #define CLEAR_ERROR_BEFORE_ALLOC(iface)
33 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) 33 #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call)
34 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR 34 #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR
35 #endif 35 #endif
36 36
37 37
38 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
39 39
40 40
41 static const GrGLenum gXfermodeEquation2Blend[] = {
42 // Basic OpenGL blend equations.
43 GR_GL_FUNC_ADD,
44 GR_GL_FUNC_SUBTRACT,
45 GR_GL_FUNC_REVERSE_SUBTRACT,
46
47 // GL_KHR_blend_equation_advanced.
48 GR_GL_SCREEN,
49 GR_GL_OVERLAY,
50 GR_GL_DARKEN,
51 GR_GL_LIGHTEN,
52 GR_GL_COLORDODGE,
53 GR_GL_COLORBURN,
54 GR_GL_HARDLIGHT,
55 GR_GL_SOFTLIGHT,
56 GR_GL_DIFFERENCE,
57 GR_GL_EXCLUSION,
58 GR_GL_MULTIPLY,
59 GR_GL_HSL_HUE,
60 GR_GL_HSL_SATURATION,
61 GR_GL_HSL_COLOR,
62 GR_GL_HSL_LUMINOSITY
63 };
64 GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation);
65 GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation);
66 GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation);
67 GR_STATIC_ASSERT(3 == kScreen_GrBlendEquation);
68 GR_STATIC_ASSERT(4 == kOverlay_GrBlendEquation);
69 GR_STATIC_ASSERT(5 == kDarken_GrBlendEquation);
70 GR_STATIC_ASSERT(6 == kLighten_GrBlendEquation);
71 GR_STATIC_ASSERT(7 == kColorDodge_GrBlendEquation);
72 GR_STATIC_ASSERT(8 == kColorBurn_GrBlendEquation);
73 GR_STATIC_ASSERT(9 == kHardLight_GrBlendEquation);
74 GR_STATIC_ASSERT(10 == kSoftLight_GrBlendEquation);
75 GR_STATIC_ASSERT(11 == kDifference_GrBlendEquation);
76 GR_STATIC_ASSERT(12 == kExclusion_GrBlendEquation);
77 GR_STATIC_ASSERT(13 == kMultiply_GrBlendEquation);
78 GR_STATIC_ASSERT(14 == kHSLHue_GrBlendEquation);
79 GR_STATIC_ASSERT(15 == kHSLSaturation_GrBlendEquation);
80 GR_STATIC_ASSERT(16 == kHSLColor_GrBlendEquation);
81 GR_STATIC_ASSERT(17 == kHSLLuminosity_GrBlendEquation);
82 GR_STATIC_ASSERT(18 == kTotalGrBlendEquationCount);
83
41 static const GrGLenum gXfermodeCoeff2Blend[] = { 84 static const GrGLenum gXfermodeCoeff2Blend[] = {
42 GR_GL_ZERO, 85 GR_GL_ZERO,
43 GR_GL_ONE, 86 GR_GL_ONE,
44 GR_GL_SRC_COLOR, 87 GR_GL_SRC_COLOR,
45 GR_GL_ONE_MINUS_SRC_COLOR, 88 GR_GL_ONE_MINUS_SRC_COLOR,
46 GR_GL_DST_COLOR, 89 GR_GL_DST_COLOR,
47 GR_GL_ONE_MINUS_DST_COLOR, 90 GR_GL_ONE_MINUS_DST_COLOR,
48 GR_GL_SRC_ALPHA, 91 GR_GL_SRC_ALPHA,
49 GR_GL_ONE_MINUS_SRC_ALPHA, 92 GR_GL_ONE_MINUS_SRC_ALPHA,
50 GR_GL_DST_ALPHA, 93 GR_GL_DST_ALPHA,
(...skipping 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 if (kNo_TriState != fMSAAEnabled) { 2110 if (kNo_TriState != fMSAAEnabled) {
2068 GL_CALL(Disable(GR_GL_MULTISAMPLE)); 2111 GL_CALL(Disable(GR_GL_MULTISAMPLE));
2069 fMSAAEnabled = kNo_TriState; 2112 fMSAAEnabled = kNo_TriState;
2070 } 2113 }
2071 } 2114 }
2072 } 2115 }
2073 } 2116 }
2074 2117
2075 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { 2118 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) {
2076 // Any optimization to disable blending should have already been applied and 2119 // Any optimization to disable blending should have already been applied and
2077 // tweaked the coeffs to (1, 0). 2120 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0).
2078 2121
2122 GrBlendEquation equation = blendInfo.fEquation;
2079 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; 2123 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
2080 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; 2124 GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
2081 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff; 2125 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati on == equation) &&
2126 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo eff;
2082 if (blendOff) { 2127 if (blendOff) {
2083 if (kNo_TriState != fHWBlendState.fEnabled) { 2128 if (kNo_TriState != fHWBlendState.fEnabled) {
2084 GL_CALL(Disable(GR_GL_BLEND)); 2129 GL_CALL(Disable(GR_GL_BLEND));
2085 fHWBlendState.fEnabled = kNo_TriState; 2130 fHWBlendState.fEnabled = kNo_TriState;
2086 } 2131 }
2087 } else { 2132 return;
2088 if (kYes_TriState != fHWBlendState.fEnabled) { 2133 }
2089 GL_CALL(Enable(GR_GL_BLEND)); 2134
2090 fHWBlendState.fEnabled = kYes_TriState; 2135 if (kYes_TriState != fHWBlendState.fEnabled) {
2091 } 2136 GL_CALL(Enable(GR_GL_BLEND));
2092 if (fHWBlendState.fSrcCoeff != srcCoeff || 2137 fHWBlendState.fEnabled = kYes_TriState;
2093 fHWBlendState.fDstCoeff != dstCoeff) { 2138 }
2094 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], 2139
2095 gXfermodeCoeff2Blend[dstCoeff])); 2140 if (fHWBlendState.fEquation != equation) {
2096 fHWBlendState.fSrcCoeff = srcCoeff; 2141 GL_CALL(BlendEquation(gXfermodeEquation2Blend[equation]));
2097 fHWBlendState.fDstCoeff = dstCoeff; 2142 fHWBlendState.fEquation = equation;
2098 } 2143 }
2099 GrColor blendConst = blendInfo.fBlendConstant; 2144
2100 if ((BlendCoeffReferencesConstant(srcCoeff) || 2145 if (GrBlendEquationIsAdvanced(equation)) {
2101 BlendCoeffReferencesConstant(dstCoeff)) && 2146 SkASSERT(this->caps()->advancedBlendEquationSupport());
2102 (!fHWBlendState.fConstColorValid || 2147 // Advanced equations have no other blend state.
2103 fHWBlendState.fConstColor != blendConst)) { 2148 return;
2104 GrGLfloat c[4]; 2149 }
2105 GrColorToRGBAFloat(blendConst, c); 2150
2106 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); 2151 if (fHWBlendState.fSrcCoeff != srcCoeff ||
2107 fHWBlendState.fConstColor = blendConst; 2152 fHWBlendState.fDstCoeff != dstCoeff) {
2108 fHWBlendState.fConstColorValid = true; 2153 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
2109 } 2154 gXfermodeCoeff2Blend[dstCoeff]));
2155 fHWBlendState.fSrcCoeff = srcCoeff;
2156 fHWBlendState.fDstCoeff = dstCoeff;
2157 }
2158
2159 GrColor blendConst = blendInfo.fBlendConstant;
2160 if ((BlendCoeffReferencesConstant(srcCoeff) ||
2161 BlendCoeffReferencesConstant(dstCoeff)) &&
2162 (!fHWBlendState.fConstColorValid ||
2163 fHWBlendState.fConstColor != blendConst)) {
2164 GrGLfloat c[4];
2165 GrColorToRGBAFloat(blendConst, c);
2166 GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
2167 fHWBlendState.fConstColor = blendConst;
2168 fHWBlendState.fConstColorValid = true;
2110 } 2169 }
2111 } 2170 }
2112 2171
2113 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { 2172 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
2114 static const GrGLenum gWrapModes[] = { 2173 static const GrGLenum gWrapModes[] = {
2115 GR_GL_CLAMP_TO_EDGE, 2174 GR_GL_CLAMP_TO_EDGE,
2116 GR_GL_REPEAT, 2175 GR_GL_REPEAT,
2117 GR_GL_MIRRORED_REPEAT 2176 GR_GL_MIRRORED_REPEAT
2118 }; 2177 };
2119 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); 2178 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes));
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 } 2785 }
2727 return false; 2786 return false;
2728 } 2787 }
2729 2788
2730 void GrGLGpu::xferBarrier(GrXferBarrierType type) { 2789 void GrGLGpu::xferBarrier(GrXferBarrierType type) {
2731 switch (type) { 2790 switch (type) {
2732 case kTexture_GrXferBarrierType: 2791 case kTexture_GrXferBarrierType:
2733 SkASSERT(this->caps()->textureBarrierSupport()); 2792 SkASSERT(this->caps()->textureBarrierSupport());
2734 GL_CALL(TextureBarrier()); 2793 GL_CALL(TextureBarrier());
2735 return; 2794 return;
2795 case kBlend_GrXferBarrierType:
2796 SkASSERT(GrDrawTargetCaps::kAdvanced_BlendEquationSupport ==
2797 this->caps()->blendEquationSupport());
2798 GL_CALL(BlendBarrier());
2799 return;
2736 } 2800 }
2737 } 2801 }
2738 2802
2739 void GrGLGpu::didAddGpuTraceMarker() { 2803 void GrGLGpu::didAddGpuTraceMarker() {
2740 if (this->caps()->gpuTracingSupport()) { 2804 if (this->caps()->gpuTracingSupport()) {
2741 const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers(); 2805 const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers();
2742 SkString markerString = markerArray.toStringLast(); 2806 SkString markerString = markerArray.toStringLast();
2743 #if GR_FORCE_GPU_TRACE_DEBUGGING 2807 #if GR_FORCE_GPU_TRACE_DEBUGGING
2744 SkDebugf("%s\n", markerString.c_str()); 2808 SkDebugf("%s\n", markerString.c_str());
2745 #else 2809 #else
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 this->setVertexArrayID(gpu, 0); 2848 this->setVertexArrayID(gpu, 0);
2785 } 2849 }
2786 int attrCount = gpu->glCaps().maxVertexAttributes(); 2850 int attrCount = gpu->glCaps().maxVertexAttributes();
2787 if (fDefaultVertexArrayAttribState.count() != attrCount) { 2851 if (fDefaultVertexArrayAttribState.count() != attrCount) {
2788 fDefaultVertexArrayAttribState.resize(attrCount); 2852 fDefaultVertexArrayAttribState.resize(attrCount);
2789 } 2853 }
2790 attribState = &fDefaultVertexArrayAttribState; 2854 attribState = &fDefaultVertexArrayAttribState;
2791 } 2855 }
2792 return attribState; 2856 return attribState;
2793 } 2857 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/builders/GrGLFragmentShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698