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 23 matching lines...) Expand all Loading... |
34 #include "third_party/khronos/GLES2/gl2.h" | 34 #include "third_party/khronos/GLES2/gl2.h" |
35 #include "third_party/khronos/GLES2/gl2ext.h" | 35 #include "third_party/khronos/GLES2/gl2ext.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "third_party/skia/include/core/SkColor.h" | 37 #include "third_party/skia/include/core/SkColor.h" |
38 #include "third_party/skia/include/gpu/GrContext.h" | 38 #include "third_party/skia/include/gpu/GrContext.h" |
39 #include "third_party/skia/include/gpu/GrTexture.h" | 39 #include "third_party/skia/include/gpu/GrTexture.h" |
40 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 40 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
41 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" | 41 #include "third_party/skia/include/gpu/SkGrTexturePixelRef.h" |
42 #include "ui/gfx/quad_f.h" | 42 #include "ui/gfx/quad_f.h" |
43 #include "ui/gfx/rect_conversions.h" | 43 #include "ui/gfx/rect_conversions.h" |
| 44 #include "ui/gfx/transform_util.h" |
44 | 45 |
45 using WebKit::WebGraphicsContext3D; | 46 using WebKit::WebGraphicsContext3D; |
46 using WebKit::WebGraphicsMemoryAllocation; | 47 using WebKit::WebGraphicsMemoryAllocation; |
47 using WebKit::WebSharedGraphicsContext3D; | 48 using WebKit::WebSharedGraphicsContext3D; |
48 | 49 |
49 namespace cc { | 50 namespace cc { |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
53 bool needsIOSurfaceReadbackWorkaround() | 54 bool needsIOSurfaceReadbackWorkaround() |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 512 } |
512 | 513 |
513 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua
d* quad) | 514 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua
d* quad) |
514 { | 515 { |
515 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass
_id); | 516 CachedResource* contentsTexture = m_renderPassTextures.get(quad->render_pass
_id); |
516 if (!contentsTexture || !contentsTexture->id()) | 517 if (!contentsTexture || !contentsTexture->id()) |
517 return; | 518 return; |
518 | 519 |
519 gfx::Transform quadRectMatrix; | 520 gfx::Transform quadRectMatrix; |
520 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); | 521 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); |
521 gfx::Transform contentsDeviceTransform = MathUtil::to2dTransform(frame.windo
wMatrix * frame.projectionMatrix * quadRectMatrix); | 522 gfx::Transform contentsDeviceTransform = gfx::CreateFlattenedTransform(frame
.windowMatrix * frame.projectionMatrix * quadRectMatrix); |
522 | 523 |
523 // Can only draw surface if device matrix is invertible. | 524 // Can only draw surface if device matrix is invertible. |
524 gfx::Transform contentsDeviceTransformInverse(gfx::Transform::kSkipInitializ
ation); | 525 gfx::Transform contentsDeviceTransformInverse(gfx::Transform::kSkipInitializ
ation); |
525 if (!contentsDeviceTransform.GetInverse(&contentsDeviceTransformInverse)) | 526 if (!contentsDeviceTransform.GetInverse(&contentsDeviceTransformInverse)) |
526 return; | 527 return; |
527 | 528 |
528 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( | 529 scoped_ptr<ScopedResource> backgroundTexture = drawBackgroundFilters( |
529 frame, quad, contentsDeviceTransform, contentsDeviceTransformInverse); | 530 frame, quad, contentsDeviceTransform, contentsDeviceTransformInverse); |
530 | 531 |
531 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. | 532 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 658 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
658 } | 659 } |
659 | 660 |
660 if (shaderEdgeLocation != -1) { | 661 if (shaderEdgeLocation != -1) { |
661 float edge[24]; | 662 float edge[24]; |
662 deviceLayerEdges.toFloatArray(edge); | 663 deviceLayerEdges.toFloatArray(edge); |
663 deviceLayerBounds.toFloatArray(&edge[12]); | 664 deviceLayerBounds.toFloatArray(&edge[12]); |
664 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); | 665 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); |
665 } | 666 } |
666 | 667 |
667 // Map device space quad to surface space. contentsDeviceTransform has no 3d
component since it was generated with to2dTransform() so we don't need to proje
ct. | 668 // Map device space quad to surface space. contentsDeviceTransform has no 3d
component since it was flattened, so we don't need to project. |
668 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d
eviceLayerEdges.ToQuadF(), clipped); | 669 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d
eviceLayerEdges.ToQuadF(), clipped); |
669 DCHECK(!clipped); | 670 DCHECK(!clipped); |
670 | 671 |
671 setShaderOpacity(quad->opacity(), shaderAlphaLocation); | 672 setShaderOpacity(quad->opacity(), shaderAlphaLocation); |
672 setShaderQuadF(surfaceQuad, shaderQuadLocation); | 673 setShaderQuadF(surfaceQuad, shaderQuadLocation); |
673 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat
ion); | 674 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat
ion); |
674 | 675 |
675 // Flush the compositor context before the filter bitmap goes out of | 676 // Flush the compositor context before the filter bitmap goes out of |
676 // scope, so the draw gets processed before the filter texture gets deleted. | 677 // scope, so the draw gets processed before the filter texture gets deleted. |
677 if (filterBitmap.getTexture()) | 678 if (filterBitmap.getTexture()) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 | 763 |
763 // Map to normalized texture coordinates. | 764 // Map to normalized texture coordinates. |
764 const gfx::Size& textureSize = quad->texture_size; | 765 const gfx::Size& textureSize = quad->texture_size; |
765 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); | 766 float fragmentTexTranslateX = clampTexRect.x() / textureSize.width(); |
766 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); | 767 float fragmentTexTranslateY = clampTexRect.y() / textureSize.height(); |
767 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); | 768 float fragmentTexScaleX = clampTexRect.width() / textureSize.width(); |
768 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); | 769 float fragmentTexScaleY = clampTexRect.height() / textureSize.height(); |
769 | 770 |
770 | 771 |
771 gfx::QuadF localQuad; | 772 gfx::QuadF localQuad; |
772 gfx::Transform deviceTransform = MathUtil::to2dTransform(frame.windowMatrix
* frame.projectionMatrix * quad->quadTransform()); | 773 gfx::Transform deviceTransform = gfx::CreateFlattenedTransform(frame.windowM
atrix * frame.projectionMatrix * quad->quadTransform()); |
773 if (!deviceTransform.IsInvertible()) | 774 if (!deviceTransform.IsInvertible()) |
774 return; | 775 return; |
775 | 776 |
776 bool clipped = false; | 777 bool clipped = false; |
777 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q
uad->visibleContentRect()), clipped); | 778 gfx::QuadF deviceLayerQuad = MathUtil::mapQuad(deviceTransform, gfx::QuadF(q
uad->visibleContentRect()), clipped); |
778 DCHECK(!clipped); | 779 DCHECK(!clipped); |
779 | 780 |
780 TileProgramUniforms uniforms; | 781 TileProgramUniforms uniforms; |
781 // For now, we simply skip anti-aliasing with the quad is clipped. This only
happens | 782 // For now, we simply skip anti-aliasing with the quad is clipped. This only
happens |
782 // on perspective transformed layers that go partially behind the camera. | 783 // on perspective transformed layers that go partially behind the camera. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 | 854 |
854 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; | 855 float sign = gfx::QuadF(tileRect).IsCounterClockwise() ? -1 : 1; |
855 bottomEdge.scale(sign); | 856 bottomEdge.scale(sign); |
856 leftEdge.scale(sign); | 857 leftEdge.scale(sign); |
857 topEdge.scale(sign); | 858 topEdge.scale(sign); |
858 rightEdge.scale(sign); | 859 rightEdge.scale(sign); |
859 | 860 |
860 // Create device space quad. | 861 // Create device space quad. |
861 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | 862 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); |
862 | 863 |
863 // Map device space quad to local space. deviceTransform has no 3d compo
nent since it was generated with to2dTransform() so we don't need to project. | 864 // Map device space quad to local space. deviceTransform has no 3d compo
nent since it was flattened, so we don't need to project. |
864 // We should have already checked that the transform was uninvertible ab
ove. | 865 // We should have already checked that the transform was uninvertible ab
ove. |
865 gfx::Transform inverseDeviceTransform(gfx::Transform::kSkipInitializatio
n); | 866 gfx::Transform inverseDeviceTransform(gfx::Transform::kSkipInitializatio
n); |
866 bool didInvert = deviceTransform.GetInverse(&inverseDeviceTransform); | 867 bool didInvert = deviceTransform.GetInverse(&inverseDeviceTransform); |
867 DCHECK(didInvert); | 868 DCHECK(didInvert); |
868 localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.ToQuadF
(), clipped); | 869 localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.ToQuadF
(), clipped); |
869 | 870 |
870 // We should not DCHECK(!clipped) here, because anti-aliasing inflation
may cause deviceQuad to become | 871 // We should not DCHECK(!clipped) here, because anti-aliasing inflation
may cause deviceQuad to become |
871 // clipped. To our knowledge this scenario does not need to be handled d
ifferently than the unclipped case. | 872 // clipped. To our knowledge this scenario does not need to be handled d
ifferently than the unclipped case. |
872 } else { | 873 } else { |
873 // Move fragment shader transform to vertex shader. We can do this while | 874 // Move fragment shader transform to vertex shader. We can do this while |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1795 |
1795 releaseRenderPassTextures(); | 1796 releaseRenderPassTextures(); |
1796 } | 1797 } |
1797 | 1798 |
1798 bool GLRenderer::isContextLost() | 1799 bool GLRenderer::isContextLost() |
1799 { | 1800 { |
1800 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1801 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1801 } | 1802 } |
1802 | 1803 |
1803 } // namespace cc | 1804 } // namespace cc |
OLD | NEW |