| OLD | NEW |
| 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 Loading... |
| 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 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 if (kNo_TriState != fMSAAEnabled) { | 2151 if (kNo_TriState != fMSAAEnabled) { |
| 2109 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 2152 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2110 fMSAAEnabled = kNo_TriState; | 2153 fMSAAEnabled = kNo_TriState; |
| 2111 } | 2154 } |
| 2112 } | 2155 } |
| 2113 } | 2156 } |
| 2114 } | 2157 } |
| 2115 | 2158 |
| 2116 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { | 2159 void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { |
| 2117 // Any optimization to disable blending should have already been applied and | 2160 // Any optimization to disable blending should have already been applied and |
| 2118 // tweaked the coeffs to (1, 0). | 2161 // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
| 2119 | 2162 |
| 2163 GrBlendEquation equation = blendInfo.fEquation; |
| 2120 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; | 2164 GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 2121 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; | 2165 GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
| 2122 bool blendOff = kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; | 2166 bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquati
on == equation) && |
| 2167 kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCo
eff; |
| 2123 if (blendOff) { | 2168 if (blendOff) { |
| 2124 if (kNo_TriState != fHWBlendState.fEnabled) { | 2169 if (kNo_TriState != fHWBlendState.fEnabled) { |
| 2125 GL_CALL(Disable(GR_GL_BLEND)); | 2170 GL_CALL(Disable(GR_GL_BLEND)); |
| 2126 fHWBlendState.fEnabled = kNo_TriState; | 2171 fHWBlendState.fEnabled = kNo_TriState; |
| 2127 } | 2172 } |
| 2128 } else { | 2173 return; |
| 2129 if (kYes_TriState != fHWBlendState.fEnabled) { | 2174 } |
| 2130 GL_CALL(Enable(GR_GL_BLEND)); | 2175 |
| 2131 fHWBlendState.fEnabled = kYes_TriState; | 2176 if (kYes_TriState != fHWBlendState.fEnabled) { |
| 2132 } | 2177 GL_CALL(Enable(GR_GL_BLEND)); |
| 2133 if (fHWBlendState.fSrcCoeff != srcCoeff || | 2178 fHWBlendState.fEnabled = kYes_TriState; |
| 2134 fHWBlendState.fDstCoeff != dstCoeff) { | 2179 } |
| 2135 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], | 2180 |
| 2136 gXfermodeCoeff2Blend[dstCoeff])); | 2181 if (fHWBlendState.fEquation != equation) { |
| 2137 fHWBlendState.fSrcCoeff = srcCoeff; | 2182 GL_CALL(BlendEquation(gXfermodeEquation2Blend[equation])); |
| 2138 fHWBlendState.fDstCoeff = dstCoeff; | 2183 fHWBlendState.fEquation = equation; |
| 2139 } | 2184 } |
| 2140 GrColor blendConst = blendInfo.fBlendConstant; | 2185 |
| 2141 if ((BlendCoeffReferencesConstant(srcCoeff) || | 2186 if (GrBlendEquationIsAdvanced(equation)) { |
| 2142 BlendCoeffReferencesConstant(dstCoeff)) && | 2187 SkASSERT(this->caps()->advancedBlendEquationSupport()); |
| 2143 (!fHWBlendState.fConstColorValid || | 2188 // Advanced equations have no other blend state. |
| 2144 fHWBlendState.fConstColor != blendConst)) { | 2189 return; |
| 2145 GrGLfloat c[4]; | 2190 } |
| 2146 GrColorToRGBAFloat(blendConst, c); | 2191 |
| 2147 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); | 2192 if (fHWBlendState.fSrcCoeff != srcCoeff || |
| 2148 fHWBlendState.fConstColor = blendConst; | 2193 fHWBlendState.fDstCoeff != dstCoeff) { |
| 2149 fHWBlendState.fConstColorValid = true; | 2194 GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 2150 } | 2195 gXfermodeCoeff2Blend[dstCoeff])); |
| 2196 fHWBlendState.fSrcCoeff = srcCoeff; |
| 2197 fHWBlendState.fDstCoeff = dstCoeff; |
| 2198 } |
| 2199 |
| 2200 GrColor blendConst = blendInfo.fBlendConstant; |
| 2201 if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 2202 BlendCoeffReferencesConstant(dstCoeff)) && |
| 2203 (!fHWBlendState.fConstColorValid || |
| 2204 fHWBlendState.fConstColor != blendConst)) { |
| 2205 GrGLfloat c[4]; |
| 2206 GrColorToRGBAFloat(blendConst, c); |
| 2207 GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
| 2208 fHWBlendState.fConstColor = blendConst; |
| 2209 fHWBlendState.fConstColorValid = true; |
| 2151 } | 2210 } |
| 2152 } | 2211 } |
| 2153 | 2212 |
| 2154 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { | 2213 static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
| 2155 static const GrGLenum gWrapModes[] = { | 2214 static const GrGLenum gWrapModes[] = { |
| 2156 GR_GL_CLAMP_TO_EDGE, | 2215 GR_GL_CLAMP_TO_EDGE, |
| 2157 GR_GL_REPEAT, | 2216 GR_GL_REPEAT, |
| 2158 GR_GL_MIRRORED_REPEAT | 2217 GR_GL_MIRRORED_REPEAT |
| 2159 }; | 2218 }; |
| 2160 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); | 2219 GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2761 if(!SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { | 2820 if(!SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { |
| 2762 return true; | 2821 return true; |
| 2763 } | 2822 } |
| 2764 } else { | 2823 } else { |
| 2765 return true; | 2824 return true; |
| 2766 } | 2825 } |
| 2767 } | 2826 } |
| 2768 return false; | 2827 return false; |
| 2769 } | 2828 } |
| 2770 | 2829 |
| 2830 void GrGLGpu::setXferBarrier(GrXferBarrierType type) { |
| 2831 switch (type) { |
| 2832 case kTexture_GrXferBarrierType: |
| 2833 SkASSERT(this->caps()->textureBarrierSupport()); |
| 2834 GL_CALL(TextureBarrier()); |
| 2835 return; |
| 2836 case kBlend_GrXferBarrierType: |
| 2837 SkASSERT(GrDrawTargetCaps::kAdvanced_BlendEquationSupport == this->c
aps()->blendEquationSupport()); |
| 2838 GL_CALL(BlendBarrier()); |
| 2839 return; |
| 2840 } |
| 2841 } |
| 2842 |
| 2771 void GrGLGpu::didAddGpuTraceMarker() { | 2843 void GrGLGpu::didAddGpuTraceMarker() { |
| 2772 if (this->caps()->gpuTracingSupport()) { | 2844 if (this->caps()->gpuTracingSupport()) { |
| 2773 const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers(); | 2845 const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers(); |
| 2774 SkString markerString = markerArray.toStringLast(); | 2846 SkString markerString = markerArray.toStringLast(); |
| 2775 #if GR_FORCE_GPU_TRACE_DEBUGGING | 2847 #if GR_FORCE_GPU_TRACE_DEBUGGING |
| 2776 SkDebugf("%s\n", markerString.c_str()); | 2848 SkDebugf("%s\n", markerString.c_str()); |
| 2777 #else | 2849 #else |
| 2778 GL_CALL(PushGroupMarker(0, markerString.c_str())); | 2850 GL_CALL(PushGroupMarker(0, markerString.c_str())); |
| 2779 #endif | 2851 #endif |
| 2780 } | 2852 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2816 this->setVertexArrayID(gpu, 0); | 2888 this->setVertexArrayID(gpu, 0); |
| 2817 } | 2889 } |
| 2818 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2890 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2819 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2891 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2820 fDefaultVertexArrayAttribState.resize(attrCount); | 2892 fDefaultVertexArrayAttribState.resize(attrCount); |
| 2821 } | 2893 } |
| 2822 attribState = &fDefaultVertexArrayAttribState; | 2894 attribState = &fDefaultVertexArrayAttribState; |
| 2823 } | 2895 } |
| 2824 return attribState; | 2896 return attribState; |
| 2825 } | 2897 } |
| OLD | NEW |