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 "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 break; | 285 break; |
286 case DrawQuad::YUVVideoContent: | 286 case DrawQuad::YUVVideoContent: |
287 drawYUVVideoQuad(frame, YUVVideoDrawQuad::materialCast(quad)); | 287 drawYUVVideoQuad(frame, YUVVideoDrawQuad::materialCast(quad)); |
288 break; | 288 break; |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo
ardDrawQuad* quad) | 292 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo
ardDrawQuad* quad) |
293 { | 293 { |
294 const TileCheckerboardProgram* program = tileCheckerboardProgram(); | 294 const TileCheckerboardProgram* program = tileCheckerboardProgram(); |
295 DCHECK(program && program->initialized()); | 295 DCHECK(program && (program->initialized() || isContextLost())); |
296 GLC(context(), context()->useProgram(program->program())); | 296 GLC(context(), context()->useProgram(program->program())); |
297 | 297 |
298 SkColor color = quad->color(); | 298 SkColor color = quad->color(); |
299 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) /
255.0, 1)); | 299 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) /
255.0, 1)); |
300 | 300 |
301 const int checkerboardWidth = 16; | 301 const int checkerboardWidth = 16; |
302 float frequency = 1.0 / checkerboardWidth; | 302 float frequency = 1.0 / checkerboardWidth; |
303 | 303 |
304 gfx::Rect tileRect = quad->quadRect(); | 304 gfx::Rect tileRect = quad->quadRect(); |
305 float texOffsetX = tileRect.x() % checkerboardWidth; | 305 float texOffsetX = tileRect.x() % checkerboardWidth; |
306 float texOffsetY = tileRect.y() % checkerboardWidth; | 306 float texOffsetY = tileRect.y() % checkerboardWidth; |
307 float texScaleX = tileRect.width(); | 307 float texScaleX = tileRect.width(); |
308 float texScaleY = tileRect.height(); | 308 float texScaleY = tileRect.height(); |
309 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo
cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); | 309 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo
cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); |
310 | 310 |
311 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat
ion(), frequency)); | 311 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat
ion(), frequency)); |
312 | 312 |
313 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; | 313 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; |
314 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); | 314 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); |
315 } | 315 } |
316 | 316 |
317 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde
rDrawQuad* quad) | 317 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde
rDrawQuad* quad) |
318 { | 318 { |
319 static float glMatrix[16]; | 319 static float glMatrix[16]; |
320 const SolidColorProgram* program = solidColorProgram(); | 320 const SolidColorProgram* program = solidColorProgram(); |
321 DCHECK(program && program->initialized()); | 321 DCHECK(program && (program->initialized() || isContextLost())); |
322 GLC(context(), context()->useProgram(program->program())); | 322 GLC(context(), context()->useProgram(program->program())); |
323 | 323 |
324 // Use the full quadRect for debug quads to not move the edges based on part
ial swaps. | 324 // Use the full quadRect for debug quads to not move the edges based on part
ial swaps. |
325 const gfx::Rect& layerRect = quad->quadRect(); | 325 const gfx::Rect& layerRect = quad->quadRect(); |
326 WebTransformationMatrix renderMatrix = quad->quadTransform(); | 326 WebTransformationMatrix renderMatrix = quad->quadTransform(); |
327 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR
ect.height() + layerRect.y()); | 327 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR
ect.height() + layerRect.y()); |
328 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height()); | 328 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height()); |
329 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); | 329 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); |
330 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc
ation(), 1, false, &glMatrix[0])); | 330 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc
ation(), 1, false, &glMatrix[0])); |
331 | 331 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 // un-antialiased quad should have and which vertex this is and the float | 848 // un-antialiased quad should have and which vertex this is and the float |
849 // quad passed in via uniform is the actual geometry that gets used to draw | 849 // quad passed in via uniform is the actual geometry that gets used to draw |
850 // it. This is why this centered rect is used and not the original quadRect. | 850 // it. This is why this centered rect is used and not the original quadRect. |
851 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect
.height()), tileRect.size()); | 851 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect
.height()), tileRect.size()); |
852 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); | 852 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); |
853 } | 853 } |
854 | 854 |
855 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ
uad* quad) | 855 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ
uad* quad) |
856 { | 856 { |
857 const VideoYUVProgram* program = videoYUVProgram(); | 857 const VideoYUVProgram* program = videoYUVProgram(); |
858 DCHECK(program && program->initialized()); | 858 DCHECK(program && (program->initialized() || isContextLost())); |
859 | 859 |
860 const VideoLayerImpl::FramePlane& yPlane = quad->yPlane(); | 860 const VideoLayerImpl::FramePlane& yPlane = quad->yPlane(); |
861 const VideoLayerImpl::FramePlane& uPlane = quad->uPlane(); | 861 const VideoLayerImpl::FramePlane& uPlane = quad->uPlane(); |
862 const VideoLayerImpl::FramePlane& vPlane = quad->vPlane(); | 862 const VideoLayerImpl::FramePlane& vPlane = quad->vPlane(); |
863 | 863 |
864 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res
ourceId); | 864 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res
ourceId); |
865 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res
ourceId); | 865 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res
ourceId); |
866 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res
ourceId); | 866 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res
ourceId); |
867 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | 867 GLC(context(), context()->activeTexture(GL_TEXTURE1)); |
868 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId())
); | 868 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId())
); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 921 |
922 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture
Id())); | 922 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture
Id())); |
923 | 923 |
924 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 924 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
925 | 925 |
926 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; | 926 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; |
927 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); | 927 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); |
928 } | 928 } |
929 | 929 |
930 struct TextureProgramBinding { | 930 struct TextureProgramBinding { |
931 template<class Program> void set(Program* program) | 931 template<class Program> void set( |
| 932 Program* program, WebKit::WebGraphicsContext3D* context) |
932 { | 933 { |
933 DCHECK(program && program->initialized()); | 934 DCHECK(program && (program->initialized() || context->isContextLost())); |
934 programId = program->program(); | 935 programId = program->program(); |
935 samplerLocation = program->fragmentShader().samplerLocation(); | 936 samplerLocation = program->fragmentShader().samplerLocation(); |
936 matrixLocation = program->vertexShader().matrixLocation(); | 937 matrixLocation = program->vertexShader().matrixLocation(); |
937 alphaLocation = program->fragmentShader().alphaLocation(); | 938 alphaLocation = program->fragmentShader().alphaLocation(); |
938 } | 939 } |
939 int programId; | 940 int programId; |
940 int samplerLocation; | 941 int samplerLocation; |
941 int matrixLocation; | 942 int matrixLocation; |
942 int alphaLocation; | 943 int alphaLocation; |
943 }; | 944 }; |
944 | 945 |
945 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 946 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
946 template<class Program> void set(Program* program) | 947 template<class Program> void set( |
| 948 Program* program, WebKit::WebGraphicsContext3D* context) |
947 { | 949 { |
948 TextureProgramBinding::set(program); | 950 TextureProgramBinding::set(program, context); |
949 texTransformLocation = program->vertexShader().texTransformLocation(); | 951 texTransformLocation = program->vertexShader().texTransformLocation(); |
950 } | 952 } |
951 int texTransformLocation; | 953 int texTransformLocation; |
952 }; | 954 }; |
953 | 955 |
954 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
d* quad) | 956 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
d* quad) |
955 { | 957 { |
956 TexTransformTextureProgramBinding binding; | 958 TexTransformTextureProgramBinding binding; |
957 if (quad->flipped()) | 959 if (quad->flipped()) |
958 binding.set(textureProgramFlip()); | 960 binding.set(textureProgramFlip(), context()); |
959 else | 961 else |
960 binding.set(textureProgram()); | 962 binding.set(textureProgram(), context()); |
961 GLC(context(), context()->useProgram(binding.programId)); | 963 GLC(context(), context()->useProgram(binding.programId)); |
962 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 964 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
963 const gfx::RectF& uvRect = quad->uvRect(); | 965 const gfx::RectF& uvRect = quad->uvRect(); |
964 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); | 966 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); |
965 | 967 |
966 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); | 968 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); |
967 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); | 969 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur
eId())); |
968 | 970 |
969 if (!quad->premultipliedAlpha()) { | 971 if (!quad->premultipliedAlpha()) { |
970 // As it turns out, the premultiplied alpha blending function (ONE, ONE_
MINUS_SRC_ALPHA) | 972 // As it turns out, the premultiplied alpha blending function (ONE, ONE_
MINUS_SRC_ALPHA) |
(...skipping 10 matching lines...) Expand all Loading... |
981 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 983 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
982 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); | 984 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); |
983 | 985 |
984 if (!quad->premultipliedAlpha()) | 986 if (!quad->premultipliedAlpha()) |
985 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 987 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
986 } | 988 } |
987 | 989 |
988 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
wQuad* quad) | 990 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
wQuad* quad) |
989 { | 991 { |
990 TexTransformTextureProgramBinding binding; | 992 TexTransformTextureProgramBinding binding; |
991 binding.set(textureIOSurfaceProgram()); | 993 binding.set(textureIOSurfaceProgram(), context()); |
992 | 994 |
993 GLC(context(), context()->useProgram(binding.programId)); | 995 GLC(context(), context()->useProgram(binding.programId)); |
994 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 996 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
995 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) | 997 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) |
996 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); | 998 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); |
997 else | 999 else |
998 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); | 1000 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); |
999 | 1001 |
1000 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf
aceTextureId())); | 1002 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurf
aceTextureId())); |
1001 | 1003 |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 | 1590 |
1589 releaseRenderPassTextures(); | 1591 releaseRenderPassTextures(); |
1590 } | 1592 } |
1591 | 1593 |
1592 bool GLRenderer::isContextLost() | 1594 bool GLRenderer::isContextLost() |
1593 { | 1595 { |
1594 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1596 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1595 } | 1597 } |
1596 | 1598 |
1597 } // namespace cc | 1599 } // namespace cc |
OLD | NEW |