OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/gl_renderer.h" | 7 #include "cc/gl_renderer.h" |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 makeContextCurrent(); | 235 makeContextCurrent(); |
236 // Bind the common vertex attributes used for drawing all the layers. | 236 // Bind the common vertex attributes used for drawing all the layers. |
237 m_sharedGeometry->prepareForDraw(); | 237 m_sharedGeometry->prepareForDraw(); |
238 | 238 |
239 GLC(m_context, m_context->disable(GL_DEPTH_TEST)); | 239 GLC(m_context, m_context->disable(GL_DEPTH_TEST)); |
240 GLC(m_context, m_context->disable(GL_CULL_FACE)); | 240 GLC(m_context, m_context->disable(GL_CULL_FACE)); |
241 GLC(m_context, m_context->enable(GL_SCISSOR_TEST)); | 241 GLC(m_context, m_context->enable(GL_SCISSOR_TEST)); |
242 GLC(m_context, m_context->colorMask(true, true, true, true)); | 242 GLC(m_context, m_context->colorMask(true, true, true, true)); |
243 GLC(m_context, m_context->enable(GL_BLEND)); | 243 GLC(m_context, m_context->enable(GL_BLEND)); |
244 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 244 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
| 245 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
245 } | 246 } |
246 | 247 |
247 void GLRenderer::doNoOp() | 248 void GLRenderer::doNoOp() |
248 { | 249 { |
249 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 250 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
250 GLC(m_context, m_context->flush()); | 251 GLC(m_context, m_context->flush()); |
251 } | 252 } |
252 | 253 |
253 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) | 254 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) |
254 { | 255 { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 567 |
567 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; | 568 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; |
568 unsigned maskTextureId = 0; | 569 unsigned maskTextureId = 0; |
569 if (quad->maskResourceId()) { | 570 if (quad->maskResourceId()) { |
570 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource
Provider, quad->maskResourceId())); | 571 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource
Provider, quad->maskResourceId())); |
571 maskTextureId = maskResourceLock->textureId(); | 572 maskTextureId = maskResourceLock->textureId(); |
572 } | 573 } |
573 | 574 |
574 // FIXME: use the backgroundTexture and blend the background in with this dr
aw instead of having a separate copy of the background texture. | 575 // FIXME: use the backgroundTexture and blend the background in with this dr
aw instead of having a separate copy of the background texture. |
575 | 576 |
576 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
577 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId); | 577 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId); |
578 | 578 |
579 int shaderQuadLocation = -1; | 579 int shaderQuadLocation = -1; |
580 int shaderEdgeLocation = -1; | 580 int shaderEdgeLocation = -1; |
581 int shaderMaskSamplerLocation = -1; | 581 int shaderMaskSamplerLocation = -1; |
582 int shaderMaskTexCoordScaleLocation = -1; | 582 int shaderMaskTexCoordScaleLocation = -1; |
583 int shaderMaskTexCoordOffsetLocation = -1; | 583 int shaderMaskTexCoordOffsetLocation = -1; |
584 int shaderMatrixLocation = -1; | 584 int shaderMatrixLocation = -1; |
585 int shaderAlphaLocation = -1; | 585 int shaderAlphaLocation = -1; |
586 if (useAA && maskTextureId) { | 586 if (useAA && maskTextureId) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } else { | 747 } else { |
748 if (quad->swizzleContents()) | 748 if (quad->swizzleContents()) |
749 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); | 749 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); |
750 else | 750 else |
751 tileUniformLocation(tileProgramOpaque(), uniforms); | 751 tileUniformLocation(tileProgramOpaque(), uniforms); |
752 } | 752 } |
753 } | 753 } |
754 | 754 |
755 GLC(context(), context()->useProgram(uniforms.program)); | 755 GLC(context(), context()->useProgram(uniforms.program)); |
756 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); | 756 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); |
757 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
758 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); | 757 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); |
759 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); | 758 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); |
760 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, quad->textureFilter())); | 759 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, quad->textureFilter())); |
761 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, quad->textureFilter())); | 760 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, quad->textureFilter())); |
762 | 761 |
763 bool useAA = !clipped && quad->isAntialiased(); | 762 bool useAA = !clipped && quad->isAntialiased(); |
764 if (useAA) { | 763 if (useAA) { |
765 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound
ingBox())); | 764 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound
ingBox())); |
766 deviceLayerBounds.inflateAntiAliasingDistance(); | 765 deviceLayerBounds.inflateAntiAliasingDistance(); |
767 | 766 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 static float glMatrix[16]; | 917 static float glMatrix[16]; |
919 | 918 |
920 DCHECK(m_capabilities.usingEglImage); | 919 DCHECK(m_capabilities.usingEglImage); |
921 | 920 |
922 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); | 921 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); |
923 GLC(context(), context()->useProgram(program->program())); | 922 GLC(context(), context()->useProgram(program->program())); |
924 | 923 |
925 toGLMatrix(&glMatrix[0], quad->matrix()); | 924 toGLMatrix(&glMatrix[0], quad->matrix()); |
926 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix
Location(), 1, false, glMatrix)); | 925 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix
Location(), 1, false, glMatrix)); |
927 | 926 |
928 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
929 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture
Id())); | 927 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture
Id())); |
930 | 928 |
931 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 929 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
932 | 930 |
933 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; | 931 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; |
934 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); | 932 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); |
935 } | 933 } |
936 | 934 |
937 struct TextureProgramBinding { | 935 struct TextureProgramBinding { |
938 template<class Program> void set(Program* program) | 936 template<class Program> void set(Program* program) |
(...skipping 24 matching lines...) Expand all Loading... |
963 TexTransformTextureProgramBinding binding; | 961 TexTransformTextureProgramBinding binding; |
964 if (quad->flipped()) | 962 if (quad->flipped()) |
965 binding.set(textureProgramFlip()); | 963 binding.set(textureProgramFlip()); |
966 else | 964 else |
967 binding.set(textureProgram()); | 965 binding.set(textureProgram()); |
968 GLC(context(), context()->useProgram(binding.programId)); | 966 GLC(context(), context()->useProgram(binding.programId)); |
969 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 967 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
970 const gfx::RectF& uvRect = quad->uvRect(); | 968 const gfx::RectF& uvRect = quad->uvRect(); |
971 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); | 969 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); |
972 | 970 |
973 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
974 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); | 971 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); |
975 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); | 972 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); |
976 | 973 |
977 // FIXME: setting the texture parameters every time is redundant. Move this
code somewhere | 974 // FIXME: setting the texture parameters every time is redundant. Move this
code somewhere |
978 // where it will only happen once per texture. | 975 // where it will only happen once per texture. |
979 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 976 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
980 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 977 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
981 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 978 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
982 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 979 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
983 | 980 |
(...skipping 21 matching lines...) Expand all Loading... |
1005 TexTransformTextureProgramBinding binding; | 1002 TexTransformTextureProgramBinding binding; |
1006 binding.set(textureIOSurfaceProgram()); | 1003 binding.set(textureIOSurfaceProgram()); |
1007 | 1004 |
1008 GLC(context(), context()->useProgram(binding.programId)); | 1005 GLC(context(), context()->useProgram(binding.programId)); |
1009 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 1006 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
1010 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) | 1007 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) |
1011 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); | 1008 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); |
1012 else | 1009 else |
1013 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); | 1010 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); |
1014 | 1011 |
1015 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
1016 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf
aceTextureId())); | 1012 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf
aceTextureId())); |
1017 | 1013 |
1018 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 1014 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
1019 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); | 1015 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); |
1020 | 1016 |
1021 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 1017 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
1022 } | 1018 } |
1023 | 1019 |
1024 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) | 1020 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) |
1025 { | 1021 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); | 1081 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); |
1086 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr
ix[0])); | 1082 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr
ix[0])); |
1087 | 1083 |
1088 GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0
)); | 1084 GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0
)); |
1089 } | 1085 } |
1090 | 1086 |
1091 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture
Id, const gfx::Rect& rect, const WebTransformationMatrix& drawMatrix) | 1087 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture
Id, const gfx::Rect& rect, const WebTransformationMatrix& drawMatrix) |
1092 { | 1088 { |
1093 const RenderPassProgram* program = renderPassProgram(); | 1089 const RenderPassProgram* program = renderPassProgram(); |
1094 | 1090 |
1095 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
1096 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); | 1091 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); |
1097 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 1092 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
1098 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 1093 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
1099 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 1094 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
1100 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 1095 GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
1101 | 1096 |
1102 GLC(context(), context()->useProgram(program->program())); | 1097 GLC(context(), context()->useProgram(program->program())); |
1103 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 1098 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
1104 setShaderOpacity(1, program->fragmentShader().alphaLocation()); | 1099 setShaderOpacity(1, program->fragmentShader().alphaLocation()); |
1105 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); | 1100 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 | 1604 |
1610 releaseRenderPassTextures(); | 1605 releaseRenderPassTextures(); |
1611 } | 1606 } |
1612 | 1607 |
1613 bool GLRenderer::isContextLost() | 1608 bool GLRenderer::isContextLost() |
1614 { | 1609 { |
1615 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1610 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1616 } | 1611 } |
1617 | 1612 |
1618 } // namespace cc | 1613 } // namespace cc |
OLD | NEW |