| 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 "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); | 151 GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 152 GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); | 152 GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 153 GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); | 153 GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 154 GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); | 154 GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
| 155 | 155 |
| 156 // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope | 156 // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
| 157 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); | 157 GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Sample locations that are colocated at pixel center. |
| 161 static const GrGLfloat gCenteredSampleLocations[2*16] = { 0.5f, 0.5f, 0.5f, 0.5f
, 0.5f, 0.5f, 0.5f, 0.5f, |
| 162 0.5f, 0.5f, 0.5f, 0.5f
, 0.5f, 0.5f, 0.5f, 0.5f, |
| 163 0.5f, 0.5f, 0.5f, 0.5f
, 0.5f, 0.5f, 0.5f, 0.5f, |
| 164 0.5f, 0.5f, 0.5f, 0.5f
, 0.5f, 0.5f, 0.5f, 0.5f }; |
| 165 |
| 166 // Default sample pattern. |
| 167 static GrGLfloat defaultSampleLocations2x[] = { 0.75f, 0.75f, 0.25f, 0.25f }; |
| 168 static GrGLfloat defaultSampleLocations4x[] = { 0.375f, 0.125f, 0.875f, 0.375f,
0.125f, 0.625f, 0.625f, 0.875f }; |
| 169 static GrGLfloat defaultSampleLocations8x[] = { 0.5625f, 0.3125f, 0.4375f, 0.68
75f, 0.8125f, 0.5625f, 0.3125f, 0.1875f, |
| 170 0.1875f, 0.8125f, 0.0625f, 0.43
75f, 0.6875f, 0.9375f, 0.9375f, 0.0625f }; |
| 171 static GrGLfloat defaultSampleLocations16x[] = { 0.5625f, 0.5625f, 0.4375f, 0.31
25f, 0.3125f, 0.625f, 0.75f, 0.4375f, |
| 172 0.1875f, 0.375f, 0.625f, 0.8125
f, 0.8125f, 0.6875f, 0.6875f, 0.1875f, |
| 173 0.375f, 0.875f, 0.5f, 0.0625f,
0.25f, 0.125f, 0.125f, 0.75f, |
| 174 0.375f, 0.875f, 0.5f, 0.0625f,
0.25f, 0.125f, 0.125f, 0.75f, |
| 175 0.0f, 0.5f, 0.9375f, 0.25f, 0.8
75f, 0.9375f, 0.0625f, 0.0f }; |
| 176 // Lookup table for sample locations array for sample count 0..16. |
| 177 static GrGLfloat* gDefaultSampleLocations[17] = { 0, |
| 178 0, defaultSampleLocations2x, 0
, defaultSampleLocations4x, |
| 179 0, 0, 0, defaultSampleLocation
s8x, |
| 180 0, 0, 0, 0, |
| 181 0, 0, 0, defaultSampleLocation
s16x }; |
| 182 |
| 160 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
| 161 | 184 |
| 162 // Used in the map of pixel configs to stencil format indices. This value is use
d to | 185 // Used in the map of pixel configs to stencil format indices. This value is use
d to |
| 163 // indicate that a stencil format has not yet been set for the given config. | 186 // indicate that a stencil format has not yet been set for the given config. |
| 164 static const int kUnknownStencilIndex = -1; | 187 static const int kUnknownStencilIndex = -1; |
| 165 // This value is used as the stencil index when no stencil configs are supported
with the | 188 // This value is used as the stencil index when no stencil configs are supported
with the |
| 166 // given pixel config. | 189 // given pixel config. |
| 167 static const int kUnsupportedStencilIndex = -2; | 190 static const int kUnsupportedStencilIndex = -2; |
| 168 | 191 |
| 169 /////////////////////////////////////////////////////////////////////////////// | 192 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 | 1493 |
| 1471 int numTextureAccesses = textureAccesses.count(); | 1494 int numTextureAccesses = textureAccesses.count(); |
| 1472 for (int i = 0; i < numTextureAccesses; i++) { | 1495 for (int i = 0; i < numTextureAccesses; i++) { |
| 1473 this->bindTexture(i, textureAccesses[i]->getParams(), | 1496 this->bindTexture(i, textureAccesses[i]->getParams(), |
| 1474 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); | 1497 static_cast<GrGLTexture*>(textureAccesses[i]->getTextu
re())); |
| 1475 } | 1498 } |
| 1476 | 1499 |
| 1477 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); | 1500 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTa
rget()); |
| 1478 this->flushStencil(pipeline.getStencil()); | 1501 this->flushStencil(pipeline.getStencil()); |
| 1479 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); | 1502 this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->or
igin()); |
| 1480 this->flushHWAAState(glRT, pipeline.isHWAntialiasState()); | 1503 this->flushHWAAState(glRT, pipeline.isHWAntialiasState(), !pipeline.getStenc
il().isDisabled()); |
| 1481 | 1504 |
| 1482 // This must come after textures are flushed because a texture may need | 1505 // This must come after textures are flushed because a texture may need |
| 1483 // to be msaa-resolved (which will modify bound FBO state). | 1506 // to be msaa-resolved (which will modify bound FBO state). |
| 1484 this->flushRenderTarget(glRT, nullptr); | 1507 this->flushRenderTarget(glRT, nullptr); |
| 1485 | 1508 |
| 1486 return true; | 1509 return true; |
| 1487 } | 1510 } |
| 1488 | 1511 |
| 1489 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, | 1512 void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
| 1490 const GrNonInstancedVertices& vertices, | 1513 const GrNonInstancedVertices& vertices, |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 if (!flipY) { | 1916 if (!flipY) { |
| 1894 dst += rowBytes; | 1917 dst += rowBytes; |
| 1895 } else { | 1918 } else { |
| 1896 dst -= rowBytes; | 1919 dst -= rowBytes; |
| 1897 } | 1920 } |
| 1898 } | 1921 } |
| 1899 } | 1922 } |
| 1900 return true; | 1923 return true; |
| 1901 } | 1924 } |
| 1902 | 1925 |
| 1926 void GrGLGpu::setCenteredSampleLocations(GrRenderTarget* rt, bool useCenteredSam
pleLocations) { |
| 1927 GrGLRenderTarget* target = static_cast<GrGLRenderTarget*>(rt->asRenderTarget
()); |
| 1928 SkASSERT(0 != target->renderFBOID()); |
| 1929 |
| 1930 if (0 == rt->numRasterSamples() || |
| 1931 useCenteredSampleLocations == rt->renderTargetPriv().usesCenteredSampleL
ocations()) { |
| 1932 return; |
| 1933 } |
| 1934 |
| 1935 if (!rt->renderTargetPriv().programmableSampleLocationsEnabled()) { |
| 1936 GL_CALL(NamedFramebufferParameteri(target->renderFBOID(), |
| 1937 GR_GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE
_LOCATIONS, true)); |
| 1938 rt->renderTargetPriv().setProgrammableSampleLocationsEnabled(true); |
| 1939 } |
| 1940 |
| 1941 SkASSERT(rt->numRasterSamples() == 2 || |
| 1942 rt->numRasterSamples() == 4 || |
| 1943 rt->numRasterSamples() == 8 || |
| 1944 rt->numRasterSamples() == 16); |
| 1945 |
| 1946 const GrGLfloat *sampleLocations = |
| 1947 useCenteredSampleLocations ? gCenteredSampleLocations |
| 1948 : gDefaultSampleLocations[rt->numRasterSample
s()]; |
| 1949 GL_CALL(NamedFramebufferSampleLocationsfv(target->renderFBOID(), 0, rt->numR
asterSamples(), sampleLocations)); |
| 1950 rt->renderTargetPriv().flagAsUsingCenteredSampleLocations(useCenteredSampleL
ocations); |
| 1951 } |
| 1952 |
| 1903 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ | 1953 void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound)
{ |
| 1904 | 1954 |
| 1905 SkASSERT(target); | 1955 SkASSERT(target); |
| 1906 | 1956 |
| 1907 uint32_t rtID = target->getUniqueID(); | 1957 uint32_t rtID = target->getUniqueID(); |
| 1908 if (fHWBoundRenderTargetUniqueID != rtID) { | 1958 if (fHWBoundRenderTargetUniqueID != rtID) { |
| 1909 fStats.incRenderTargetBinds(); | 1959 fStats.incRenderTargetBinds(); |
| 1910 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); | 1960 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); |
| 1911 #ifdef SK_DEBUG | 1961 #ifdef SK_DEBUG |
| 1912 // don't do this check in Chromium -- this is causing | 1962 // don't do this check in Chromium -- this is causing |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2140 set_gl_stencil(this->glInterface(), | 2190 set_gl_stencil(this->glInterface(), |
| 2141 stencilSettings, | 2191 stencilSettings, |
| 2142 GR_GL_FRONT_AND_BACK, | 2192 GR_GL_FRONT_AND_BACK, |
| 2143 GrStencilSettings::kFront_Face); | 2193 GrStencilSettings::kFront_Face); |
| 2144 } | 2194 } |
| 2145 } | 2195 } |
| 2146 fHWStencilSettings = stencilSettings; | 2196 fHWStencilSettings = stencilSettings; |
| 2147 } | 2197 } |
| 2148 } | 2198 } |
| 2149 | 2199 |
| 2150 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA) { | 2200 void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabl
ed) { |
| 2151 SkASSERT(!useHWAA || rt->isStencilBufferMultisampled()); | 2201 SkASSERT(!useHWAA || rt->isStencilBufferMultisampled()); |
| 2152 | 2202 |
| 2203 if (rt->hasMixedSamples() && stencilEnabled && |
| 2204 this->glCaps().glslCaps()->programmableSampleLocationsSupport()) { |
| 2205 if (useHWAA) { |
| 2206 setCenteredSampleLocations(rt, false); |
| 2207 } else { |
| 2208 setCenteredSampleLocations(rt, true); |
| 2209 } |
| 2210 useHWAA = true; |
| 2211 } |
| 2212 |
| 2153 if (this->glCaps().multisampleDisableSupport()) { | 2213 if (this->glCaps().multisampleDisableSupport()) { |
| 2154 if (useHWAA) { | 2214 if (useHWAA) { |
| 2155 if (kYes_TriState != fMSAAEnabled) { | 2215 if (kYes_TriState != fMSAAEnabled) { |
| 2156 GL_CALL(Enable(GR_GL_MULTISAMPLE)); | 2216 GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 2157 fMSAAEnabled = kYes_TriState; | 2217 fMSAAEnabled = kYes_TriState; |
| 2158 } | 2218 } |
| 2159 } else { | 2219 } else { |
| 2160 if (kNo_TriState != fMSAAEnabled) { | 2220 if (kNo_TriState != fMSAAEnabled) { |
| 2161 GL_CALL(Disable(GR_GL_MULTISAMPLE)); | 2221 GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2162 fMSAAEnabled = kNo_TriState; | 2222 fMSAAEnabled = kNo_TriState; |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2925 GL_CALL(Uniform4f(fCopyProgram.fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0,
dy0)); | 2985 GL_CALL(Uniform4f(fCopyProgram.fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0,
dy0)); |
| 2926 GL_CALL(Uniform4f(fCopyProgram.fTexCoordXformUniform, sx1 - sx0, sy1 - sy0,
sx0, sy0)); | 2986 GL_CALL(Uniform4f(fCopyProgram.fTexCoordXformUniform, sx1 - sx0, sy1 - sy0,
sx0, sy0)); |
| 2927 GL_CALL(Uniform1i(fCopyProgram.fTextureUniform, 0)); | 2987 GL_CALL(Uniform1i(fCopyProgram.fTextureUniform, 0)); |
| 2928 | 2988 |
| 2929 GrXferProcessor::BlendInfo blendInfo; | 2989 GrXferProcessor::BlendInfo blendInfo; |
| 2930 blendInfo.reset(); | 2990 blendInfo.reset(); |
| 2931 this->flushBlend(blendInfo); | 2991 this->flushBlend(blendInfo); |
| 2932 this->flushColorWrite(true); | 2992 this->flushColorWrite(true); |
| 2933 this->flushDither(false); | 2993 this->flushDither(false); |
| 2934 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); | 2994 this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
| 2935 this->flushHWAAState(dstRT, false); | 2995 this->flushHWAAState(dstRT, false, false); |
| 2936 this->disableScissor(); | 2996 this->disableScissor(); |
| 2937 GrStencilSettings stencil; | 2997 GrStencilSettings stencil; |
| 2938 stencil.setDisabled(); | 2998 stencil.setDisabled(); |
| 2939 this->flushStencil(stencil); | 2999 this->flushStencil(stencil); |
| 2940 | 3000 |
| 2941 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | 3001 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
| 2942 } | 3002 } |
| 2943 | 3003 |
| 2944 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, | 3004 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, |
| 2945 GrSurface* src, | 3005 GrSurface* src, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 this->setVertexArrayID(gpu, 0); | 3220 this->setVertexArrayID(gpu, 0); |
| 3161 } | 3221 } |
| 3162 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3222 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3163 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3223 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3164 fDefaultVertexArrayAttribState.resize(attrCount); | 3224 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3165 } | 3225 } |
| 3166 attribState = &fDefaultVertexArrayAttribState; | 3226 attribState = &fDefaultVertexArrayAttribState; |
| 3167 } | 3227 } |
| 3168 return attribState; | 3228 return attribState; |
| 3169 } | 3229 } |
| OLD | NEW |