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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 | 276 |
277 void GLRenderer::doNoOp() | 277 void GLRenderer::doNoOp() |
278 { | 278 { |
279 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 279 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
280 GLC(m_context, m_context->flush()); | 280 GLC(m_context, m_context->flush()); |
281 } | 281 } |
282 | 282 |
283 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) | 283 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) |
284 { | 284 { |
285 DCHECK(quad->rect.Contains(quad->visible_rect)); | 285 DCHECK(quad->rect.Contains(quad->visible_rect)); |
286 if (quad->material != DrawQuad::TEXTURE_CONTENT) { | |
287 flushTextureQuadCache(); | |
reveman
2013/02/26 01:49:28
I think we should keep this flushTextureQuadCache(
ernstm
2013/02/26 18:10:57
Done.
| |
288 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
289 } | |
290 | 286 |
291 switch (quad->material) { | 287 switch (quad->material) { |
292 case DrawQuad::INVALID: | 288 case DrawQuad::INVALID: |
293 NOTREACHED(); | 289 NOTREACHED(); |
294 break; | 290 break; |
295 case DrawQuad::CHECKERBOARD: | 291 case DrawQuad::CHECKERBOARD: |
296 drawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 292 drawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
297 break; | 293 break; |
298 case DrawQuad::DEBUG_BORDER: | 294 case DrawQuad::DEBUG_BORDER: |
299 drawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 295 drawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
(...skipping 17 matching lines...) Expand all Loading... | |
317 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 313 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); |
318 break; | 314 break; |
319 case DrawQuad::YUV_VIDEO_CONTENT: | 315 case DrawQuad::YUV_VIDEO_CONTENT: |
320 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); | 316 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); |
321 break; | 317 break; |
322 } | 318 } |
323 } | 319 } |
324 | 320 |
325 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) | 321 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) |
326 { | 322 { |
323 flushTextureQuadCache(); | |
324 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
325 | |
327 const TileCheckerboardProgram* program = tileCheckerboardProgram(); | 326 const TileCheckerboardProgram* program = tileCheckerboardProgram(); |
328 DCHECK(program && (program->initialized() || isContextLost())); | 327 DCHECK(program && (program->initialized() || isContextLost())); |
329 setUseProgram(program->program()); | 328 setUseProgram(program->program()); |
330 | 329 |
331 SkColor color = quad->color; | 330 SkColor color = quad->color; |
332 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1)); | 331 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1)); |
333 | 332 |
334 const int checkerboardWidth = 16; | 333 const int checkerboardWidth = 16; |
335 float frequency = 1.0 / checkerboardWidth; | 334 float frequency = 1.0 / checkerboardWidth; |
336 | 335 |
337 gfx::Rect tileRect = quad->rect; | 336 gfx::Rect tileRect = quad->rect; |
338 float texOffsetX = tileRect.x() % checkerboardWidth; | 337 float texOffsetX = tileRect.x() % checkerboardWidth; |
339 float texOffsetY = tileRect.y() % checkerboardWidth; | 338 float texOffsetY = tileRect.y() % checkerboardWidth; |
340 float texScaleX = tileRect.width(); | 339 float texScaleX = tileRect.width(); |
341 float texScaleY = tileRect.height(); | 340 float texScaleY = tileRect.height(); |
342 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); | 341 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); |
343 | 342 |
344 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency)); | 343 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency)); |
345 | 344 |
346 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | 345 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; |
347 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 346 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
348 } | 347 } |
349 | 348 |
350 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad) | 349 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad) |
351 { | 350 { |
351 flushTextureQuadCache(); | |
352 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
353 | |
352 static float glMatrix[16]; | 354 static float glMatrix[16]; |
353 const SolidColorProgram* program = solidColorProgram(); | 355 const SolidColorProgram* program = solidColorProgram(); |
354 DCHECK(program && (program->initialized() || isContextLost())); | 356 DCHECK(program && (program->initialized() || isContextLost())); |
355 setUseProgram(program->program()); | 357 setUseProgram(program->program()); |
356 | 358 |
357 // Use the full quadRect for debug quads to not move the edges based on part ial swaps. | 359 // Use the full quadRect for debug quads to not move the edges based on part ial swaps. |
358 const gfx::Rect& layerRect = quad->rect; | 360 const gfx::Rect& layerRect = quad->rect; |
359 gfx::Transform renderMatrix = quad->quadTransform(); | 361 gfx::Transform renderMatrix = quad->quadTransform(); |
360 renderMatrix.Translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y()); | 362 renderMatrix.Translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y()); |
361 renderMatrix.Scale(layerRect.width(), layerRect.height()); | 363 renderMatrix.Scale(layerRect.width(), layerRect.height()); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 | 547 |
546 useRenderPass(frame, targetRenderPass); | 548 useRenderPass(frame, targetRenderPass); |
547 | 549 |
548 if (!usingBackgroundTexture) | 550 if (!usingBackgroundTexture) |
549 return scoped_ptr<ScopedResource>(); | 551 return scoped_ptr<ScopedResource>(); |
550 return backgroundTexture.Pass(); | 552 return backgroundTexture.Pass(); |
551 } | 553 } |
552 | 554 |
553 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua d* quad) | 555 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua d* quad) |
554 { | 556 { |
557 flushTextureQuadCache(); | |
558 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
559 | |
555 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass _id); | 560 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass _id); |
556 if (!contentsTexture || !contentsTexture->id()) | 561 if (!contentsTexture || !contentsTexture->id()) |
557 return; | 562 return; |
558 | 563 |
559 gfx::Transform quadRectMatrix; | 564 gfx::Transform quadRectMatrix; |
560 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); | 565 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); |
561 gfx::Transform contentsDeviceTransform = frame.windowMatrix * frame.projecti onMatrix * quadRectMatrix; | 566 gfx::Transform contentsDeviceTransform = frame.windowMatrix * frame.projecti onMatrix * quadRectMatrix; |
562 contentsDeviceTransform.FlattenTo2d(); | 567 contentsDeviceTransform.FlattenTo2d(); |
563 | 568 |
564 // Can only draw surface if device matrix is invertible. | 569 // Can only draw surface if device matrix is invertible. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); | 719 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); |
715 | 720 |
716 // Flush the compositor context before the filter bitmap goes out of | 721 // Flush the compositor context before the filter bitmap goes out of |
717 // scope, so the draw gets processed before the filter texture gets deleted. | 722 // scope, so the draw gets processed before the filter texture gets deleted. |
718 if (filterBitmap.getTexture()) | 723 if (filterBitmap.getTexture()) |
719 m_context->flush(); | 724 m_context->flush(); |
720 } | 725 } |
721 | 726 |
722 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) | 727 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) |
723 { | 728 { |
729 flushTextureQuadCache(); | |
730 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
731 | |
724 const SolidColorProgram* program = solidColorProgram(); | 732 const SolidColorProgram* program = solidColorProgram(); |
725 setUseProgram(program->program()); | 733 setUseProgram(program->program()); |
726 | 734 |
727 SkColor color = quad->color; | 735 SkColor color = quad->color; |
728 float opacity = quad->opacity(); | 736 float opacity = quad->opacity(); |
729 float alpha = (SkColorGetA(color) / 255.0) * opacity; | 737 float alpha = (SkColorGetA(color) / 255.0) * opacity; |
730 | 738 |
731 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); | 739 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); |
732 | 740 |
733 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 741 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
(...skipping 19 matching lines...) Expand all Loading... | |
753 uniforms.pointLocation = program->vertexShader().pointLocation(); | 761 uniforms.pointLocation = program->vertexShader().pointLocation(); |
754 | 762 |
755 uniforms.samplerLocation = program->fragmentShader().samplerLocation(); | 763 uniforms.samplerLocation = program->fragmentShader().samplerLocation(); |
756 uniforms.alphaLocation = program->fragmentShader().alphaLocation(); | 764 uniforms.alphaLocation = program->fragmentShader().alphaLocation(); |
757 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe xTransformLocation(); | 765 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe xTransformLocation(); |
758 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); | 766 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); |
759 } | 767 } |
760 | 768 |
761 void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua d) | 769 void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua d) |
762 { | 770 { |
771 flushTextureQuadCache(); | |
772 | |
763 gfx::Rect tileRect = quad->visible_rect; | 773 gfx::Rect tileRect = quad->visible_rect; |
764 | 774 |
765 gfx::RectF texCoordRect = quad->tex_coord_rect; | 775 gfx::RectF texCoordRect = quad->tex_coord_rect; |
766 float texToGeomScaleX = quad->rect.width() / texCoordRect.width(); | 776 float texToGeomScaleX = quad->rect.width() / texCoordRect.width(); |
767 float texToGeomScaleY = quad->rect.height() / texCoordRect.height(); | 777 float texToGeomScaleY = quad->rect.height() / texCoordRect.height(); |
768 | 778 |
769 // texCoordRect corresponds to quadRect, but quadVisibleRect may be | 779 // texCoordRect corresponds to quadRect, but quadVisibleRect may be |
770 // smaller than quadRect due to occlusion or clipping. Adjust | 780 // smaller than quadRect due to occlusion or clipping. Adjust |
771 // texCoordRect to match. | 781 // texCoordRect to match. |
772 gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin(); | 782 gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin(); |
(...skipping 28 matching lines...) Expand all Loading... | |
801 float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); | 811 float vertexTexScaleX = tileRect.width() / clampGeomRect.width(); |
802 float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); | 812 float vertexTexScaleY = tileRect.height() / clampGeomRect.height(); |
803 | 813 |
804 // Map to normalized texture coordinates. | 814 // Map to normalized texture coordinates. |
805 const gfx::Size& textureSize = quad->texture_size; | 815 const gfx::Size& textureSize = quad->texture_size; |
806 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); | 816 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); |
807 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); | 817 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); |
808 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); | 818 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); |
809 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); | 819 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); |
810 | 820 |
811 | |
812 gfx::QuadF localQuad; | 821 gfx::QuadF localQuad; |
813 gfx::Transform deviceTransform = frame.windowMatrix * frame.projectionMatrix * quad->quadTransform(); | 822 gfx::Transform deviceTransform = frame.windowMatrix * frame.projectionMatrix * quad->quadTransform(); |
814 deviceTransform.FlattenTo2d(); | 823 deviceTransform.FlattenTo2d(); |
815 if (!deviceTransform.IsInvertible()) | 824 if (!deviceTransform.IsInvertible()) |
816 return; | 825 return; |
817 | 826 |
818 bool clipped = false; | 827 bool clipped = false; |
819 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped); | 828 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q uad->visibleContentRect()), clipped); |
820 DCHECK(!clipped); | 829 DCHECK(!clipped); |
821 | 830 |
831 // TODO(reveman): Axis-aligned is not enough to avoid anti-aliasing. | |
832 // Bounding rectangle for quad also needs to be expressible as | |
833 // an integer rectangle. crbug.com/169374 | |
834 bool isAxisAlignedInTarget = deviceLayerQuad.IsRectilinear(); | |
835 bool useAA = !clipped && !isAxisAlignedInTarget && quad->IsEdge(); | |
836 | |
822 TileProgramUniforms uniforms; | 837 TileProgramUniforms uniforms; |
823 // For now, we simply skip anti-aliasing with the quad is clipped. This only happens | 838 if (useAA) { |
824 // on perspective transformed layers that go partially behind the camera. | |
825 if (quad->IsAntialiased() && !clipped) { | |
826 if (quad->swizzle_contents) | 839 if (quad->swizzle_contents) |
827 tileUniformLocation(tileProgramSwizzleAA(), uniforms); | 840 tileUniformLocation(tileProgramSwizzleAA(), uniforms); |
828 else | 841 else |
829 tileUniformLocation(tileProgramAA(), uniforms); | 842 tileUniformLocation(tileProgramAA(), uniforms); |
830 } else { | 843 } else { |
831 if (quad->ShouldDrawWithBlending()) { | 844 if (quad->ShouldDrawWithBlending()) { |
832 if (quad->swizzle_contents) | 845 if (quad->swizzle_contents) |
833 tileUniformLocation(tileProgramSwizzle(), uniforms); | 846 tileUniformLocation(tileProgramSwizzle(), uniforms); |
834 else | 847 else |
835 tileUniformLocation(tileProgram(), uniforms); | 848 tileUniformLocation(tileProgram(), uniforms); |
836 } else { | 849 } else { |
837 if (quad->swizzle_contents) | 850 if (quad->swizzle_contents) |
838 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); | 851 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); |
839 else | 852 else |
840 tileUniformLocation(tileProgramOpaque(), uniforms); | 853 tileUniformLocation(tileProgramOpaque(), uniforms); |
841 } | 854 } |
842 } | 855 } |
843 | 856 |
reveman
2013/02/26 01:49:28
nit: remove this whitespace change.
ernstm
2013/02/26 18:10:57
Done.
ernstm
2013/02/26 18:10:57
Done.
| |
844 setUseProgram(uniforms.program); | 857 setUseProgram(uniforms.program); |
845 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); | 858 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); |
846 bool scaled = (texToGeomScaleX != 1 || texToGeomScaleY != 1); | 859 bool scaled = (texToGeomScaleX != 1 || texToGeomScaleY != 1); |
847 GLenum filter = (quad->IsAntialiased() || scaled || !quad->quadTransform().I sIdentityOrIntegerTranslation()) ? GL_LINEAR : GL_NEAREST; | 860 GLenum filter = (useAA || scaled || !quad->quadTransform().IsIdentityOrInteg erTranslation()) ? GL_LINEAR : GL_NEAREST; |
848 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D, filter); | 861 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D, filter); |
849 | 862 |
850 bool useAA = !clipped && quad->IsAntialiased(); | |
851 if (useAA) { | 863 if (useAA) { |
864 // always enable blending when using antialiasing | |
865 setBlendEnabled(true); | |
reveman
2013/02/26 01:49:28
is the setBlendEnabled(quad->ShouldDrawWithBlendin
ernstm
2013/02/26 18:10:57
The line below is enough. This one is a leftover f
| |
866 | |
852 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); | 867 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); |
853 deviceLayerBounds.inflateAntiAliasingDistance(); | 868 deviceLayerBounds.inflateAntiAliasingDistance(); |
854 | 869 |
855 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); | 870 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); |
856 deviceLayerEdges.inflateAntiAliasingDistance(); | 871 deviceLayerEdges.inflateAntiAliasingDistance(); |
857 | 872 |
858 float edge[24]; | 873 float edge[24]; |
859 deviceLayerEdges.toFloatArray(edge); | 874 deviceLayerEdges.toFloatArray(edge); |
860 deviceLayerBounds.toFloatArray(&edge[12]); | 875 deviceLayerBounds.toFloatArray(&edge[12]); |
861 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); | 876 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); |
(...skipping 15 matching lines...) Expand all Loading... | |
877 DCHECK(!clipped); | 892 DCHECK(!clipped); |
878 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); | 893 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); |
879 DCHECK(!clipped); | 894 DCHECK(!clipped); |
880 | 895 |
881 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); | 896 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); |
882 LayerQuad::Edge leftEdge(bottomLeft, topLeft); | 897 LayerQuad::Edge leftEdge(bottomLeft, topLeft); |
883 LayerQuad::Edge topEdge(topLeft, topRight); | 898 LayerQuad::Edge topEdge(topLeft, topRight); |
884 LayerQuad::Edge rightEdge(topRight, bottomRight); | 899 LayerQuad::Edge rightEdge(topRight, bottomRight); |
885 | 900 |
886 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. | 901 // Only apply anti-aliasing to edges not clipped by culling or scissorin g. |
887 if (quad->top_edge_aa && tileRect.y() == quad->rect.y()) | 902 if (quad->IsTopEdge() && tileRect.y() == quad->rect.y()) |
888 topEdge = deviceLayerEdges.top(); | 903 topEdge = deviceLayerEdges.top(); |
889 if (quad->left_edge_aa && tileRect.x() == quad->rect.x()) | 904 if (quad->IsLeftEdge() && tileRect.x() == quad->rect.x()) |
890 leftEdge = deviceLayerEdges.left(); | 905 leftEdge = deviceLayerEdges.left(); |
891 if (quad->right_edge_aa && tileRect.right() == quad->rect.right()) | 906 if (quad->IsRightEdge() && tileRect.right() == quad->rect.right()) |
892 rightEdge = deviceLayerEdges.right(); | 907 rightEdge = deviceLayerEdges.right(); |
893 if (quad->bottom_edge_aa && tileRect.bottom() == quad->rect.bottom()) | 908 if (quad->IsBottomEdge() && tileRect.bottom() == quad->rect.bottom()) |
894 bottomEdge = deviceLayerEdges.bottom(); | 909 bottomEdge = deviceLayerEdges.bottom(); |
895 | 910 |
896 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; | 911 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; |
897 bottomEdge.scale(sign); | 912 bottomEdge.scale(sign); |
898 leftEdge.scale(sign); | 913 leftEdge.scale(sign); |
899 topEdge.scale(sign); | 914 topEdge.scale(sign); |
900 rightEdge.scale(sign); | 915 rightEdge.scale(sign); |
901 | 916 |
902 // Create device space quad. | 917 // Create device space quad. |
903 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | 918 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); |
(...skipping 17 matching lines...) Expand all Loading... | |
921 vertexTexTranslateX *= fragmentTexScaleX; | 936 vertexTexTranslateX *= fragmentTexScaleX; |
922 vertexTexTranslateY *= fragmentTexScaleY; | 937 vertexTexTranslateY *= fragmentTexScaleY; |
923 vertexTexTranslateX += fragmentTexTranslateX; | 938 vertexTexTranslateX += fragmentTexTranslateX; |
924 vertexTexTranslateY += fragmentTexTranslateY; | 939 vertexTexTranslateY += fragmentTexTranslateY; |
925 | 940 |
926 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); | 941 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
927 | 942 |
928 localQuad = gfx::RectF(tileRect); | 943 localQuad = gfx::RectF(tileRect); |
929 } | 944 } |
930 | 945 |
946 // Enable blending when the quad properties require it or if we decided | |
reveman
2013/02/26 01:49:28
nit: remove whitespace at end of line.
ernstm
2013/02/26 18:10:57
Done.
| |
947 // to use antialiasing. | |
948 setBlendEnabled(quad->ShouldDrawWithBlending() || useAA); | |
949 | |
931 // Normalize to tileRect. | 950 // Normalize to tileRect. |
932 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); | 951 localQuad.Scale(1.0f / tileRect.width(), 1.0f / tileRect.height()); |
933 | 952 |
934 setShaderOpacity(quad->opacity(), uniforms.alphaLocation); | 953 setShaderOpacity(quad->opacity(), uniforms.alphaLocation); |
935 setShaderQuadF(localQuad, uniforms.pointLocation); | 954 setShaderQuadF(localQuad, uniforms.pointLocation); |
936 | 955 |
937 // The tile quad shader behaves differently compared to all other shaders. | 956 // The tile quad shader behaves differently compared to all other shaders. |
938 // The transform and vertex data are used to figure out the extents that the | 957 // The transform and vertex data are used to figure out the extents that the |
939 // un-antialiased quad should have and which vertex this is and the float | 958 // un-antialiased quad should have and which vertex this is and the float |
940 // quad passed in via uniform is the actual geometry that gets used to draw | 959 // quad passed in via uniform is the actual geometry that gets used to draw |
941 // it. This is why this centered rect is used and not the original quadRect. | 960 // it. This is why this centered rect is used and not the original quadRect. |
942 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size()); | 961 gfx::RectF centeredRect(gfx::PointF(-0.5 * tileRect.width(), -0.5 * tileRect .height()), tileRect.size()); |
943 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location); | 962 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix Location); |
944 } | 963 } |
945 | 964 |
946 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad) | 965 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad) |
947 { | 966 { |
967 flushTextureQuadCache(); | |
968 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
reveman
2013/02/26 01:49:28
nit: remove whitespace at end of line.
ernstm
2013/02/26 18:10:57
Done.
| |
969 | |
948 const VideoYUVProgram* program = videoYUVProgram(); | 970 const VideoYUVProgram* program = videoYUVProgram(); |
949 DCHECK(program && (program->initialized() || isContextLost())); | 971 DCHECK(program && (program->initialized() || isContextLost())); |
950 | 972 |
951 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane; | 973 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane; |
952 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane; | 974 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane; |
953 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane; | 975 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane; |
954 | 976 |
955 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | 977 GLC(context(), context()->activeTexture(GL_TEXTURE1)); |
956 ResourceProvider::ScopedSamplerGL yPlaneLock(m_resourceProvider, yPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR); | 978 ResourceProvider::ScopedSamplerGL yPlaneLock(m_resourceProvider, yPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR); |
957 GLC(context(), context()->activeTexture(GL_TEXTURE2)); | 979 GLC(context(), context()->activeTexture(GL_TEXTURE2)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 | 1012 |
991 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | 1013 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; |
992 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 1014 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
993 | 1015 |
994 // Reset active texture back to texture 0. | 1016 // Reset active texture back to texture 0. |
995 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 1017 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
996 } | 1018 } |
997 | 1019 |
998 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) | 1020 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) |
999 { | 1021 { |
1022 flushTextureQuadCache(); | |
1023 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
1024 | |
1000 static float glMatrix[16]; | 1025 static float glMatrix[16]; |
1001 | 1026 |
1002 DCHECK(m_capabilities.usingEglImage); | 1027 DCHECK(m_capabilities.usingEglImage); |
1003 | 1028 |
1004 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); | 1029 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); |
1005 setUseProgram(program->program()); | 1030 setUseProgram(program->program()); |
1006 | 1031 |
1007 toGLMatrix(&glMatrix[0], quad->matrix); | 1032 toGLMatrix(&glMatrix[0], quad->matrix); |
1008 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); | 1033 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); |
1009 | 1034 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 } | 1203 } |
1179 | 1204 |
1180 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); | 1205 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); |
1181 | 1206 |
1182 if (!quad->premultiplied_alpha) | 1207 if (!quad->premultiplied_alpha) |
1183 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 1208 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
1184 } | 1209 } |
1185 | 1210 |
1186 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) | 1211 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) |
1187 { | 1212 { |
1213 flushTextureQuadCache(); | |
1214 setBlendEnabled(quad->ShouldDrawWithBlending()); | |
1215 | |
1188 TexTransformTextureProgramBinding binding; | 1216 TexTransformTextureProgramBinding binding; |
1189 binding.set(textureIOSurfaceProgram(), context()); | 1217 binding.set(textureIOSurfaceProgram(), context()); |
1190 | 1218 |
1191 setUseProgram(binding.programId); | 1219 setUseProgram(binding.programId); |
1192 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 1220 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
1193 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) | 1221 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) |
1194 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->io_surface_size.height(), quad->io_surface_size.width(), quad->io_surface_siz e.height() * -1.0)); | 1222 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->io_surface_size.height(), quad->io_surface_size.width(), quad->io_surface_siz e.height() * -1.0)); |
1195 else | 1223 else |
1196 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height())); | 1224 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height())); |
1197 | 1225 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1847 | 1875 |
1848 releaseRenderPassTextures(); | 1876 releaseRenderPassTextures(); |
1849 } | 1877 } |
1850 | 1878 |
1851 bool GLRenderer::isContextLost() | 1879 bool GLRenderer::isContextLost() |
1852 { | 1880 { |
1853 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1881 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1854 } | 1882 } |
1855 | 1883 |
1856 } // namespace cc | 1884 } // namespace cc |
OLD | NEW |