| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 | 1525 |
| 1526 MOCK_METHOD0(EnsureBackbuffer, void()); | 1526 MOCK_METHOD0(EnsureBackbuffer, void()); |
| 1527 MOCK_METHOD0(DiscardBackbuffer, void()); | 1527 MOCK_METHOD0(DiscardBackbuffer, void()); |
| 1528 MOCK_METHOD5(Reshape, | 1528 MOCK_METHOD5(Reshape, |
| 1529 void(const gfx::Size& size, | 1529 void(const gfx::Size& size, |
| 1530 float scale_factor, | 1530 float scale_factor, |
| 1531 const gfx::ColorSpace& color_space, | 1531 const gfx::ColorSpace& color_space, |
| 1532 bool has_alpha, | 1532 bool has_alpha, |
| 1533 bool use_stencil)); | 1533 bool use_stencil)); |
| 1534 MOCK_METHOD0(BindFramebuffer, void()); | 1534 MOCK_METHOD0(BindFramebuffer, void()); |
| 1535 MOCK_METHOD1(SetDrawRectangle, void(const gfx::Rect&)); |
| 1535 MOCK_METHOD0(GetFramebufferCopyTextureFormat, GLenum()); | 1536 MOCK_METHOD0(GetFramebufferCopyTextureFormat, GLenum()); |
| 1536 MOCK_METHOD1(SwapBuffers_, void(OutputSurfaceFrame& frame)); // NOLINT | 1537 MOCK_METHOD1(SwapBuffers_, void(OutputSurfaceFrame& frame)); // NOLINT |
| 1537 void SwapBuffers(OutputSurfaceFrame frame) override { SwapBuffers_(frame); } | 1538 void SwapBuffers(OutputSurfaceFrame frame) override { SwapBuffers_(frame); } |
| 1538 MOCK_CONST_METHOD0(GetOverlayCandidateValidator, | 1539 MOCK_CONST_METHOD0(GetOverlayCandidateValidator, |
| 1539 OverlayCandidateValidator*()); | 1540 OverlayCandidateValidator*()); |
| 1540 MOCK_CONST_METHOD0(IsDisplayedAsOverlayPlane, bool()); | 1541 MOCK_CONST_METHOD0(IsDisplayedAsOverlayPlane, bool()); |
| 1541 MOCK_CONST_METHOD0(GetOverlayTextureId, unsigned()); | 1542 MOCK_CONST_METHOD0(GetOverlayTextureId, unsigned()); |
| 1542 MOCK_CONST_METHOD0(SurfaceIsSuspendForRecycle, bool()); | 1543 MOCK_CONST_METHOD0(SurfaceIsSuspendForRecycle, bool()); |
| 1543 MOCK_CONST_METHOD0(HasExternalStencilTest, bool()); | 1544 MOCK_CONST_METHOD0(HasExternalStencilTest, bool()); |
| 1544 MOCK_METHOD0(ApplyExternalStencil, void()); | 1545 MOCK_METHOD0(ApplyExternalStencil, void()); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 overlay_scheduler, | 1893 overlay_scheduler, |
| 1893 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), | 1894 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), |
| 1894 BoundingRect(uv_top_left, uv_bottom_right))) | 1895 BoundingRect(uv_top_left, uv_bottom_right))) |
| 1895 .Times(1); | 1896 .Times(1); |
| 1896 | 1897 |
| 1897 DrawFrame(&renderer, viewport_size); | 1898 DrawFrame(&renderer, viewport_size); |
| 1898 } | 1899 } |
| 1899 | 1900 |
| 1900 class PartialSwapMockGLES2Interface : public TestGLES2Interface { | 1901 class PartialSwapMockGLES2Interface : public TestGLES2Interface { |
| 1901 public: | 1902 public: |
| 1903 explicit PartialSwapMockGLES2Interface(bool support_set_draw_rectangle) |
| 1904 : support_set_draw_rectangle_(support_set_draw_rectangle) {} |
| 1905 |
| 1902 void InitializeTestContext(TestWebGraphicsContext3D* context) override { | 1906 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
| 1903 context->set_have_post_sub_buffer(true); | 1907 context->set_have_post_sub_buffer(true); |
| 1908 context->set_support_set_draw_rectangle(support_set_draw_rectangle_); |
| 1904 } | 1909 } |
| 1905 | 1910 |
| 1906 MOCK_METHOD1(Enable, void(GLenum cap)); | 1911 MOCK_METHOD1(Enable, void(GLenum cap)); |
| 1907 MOCK_METHOD1(Disable, void(GLenum cap)); | 1912 MOCK_METHOD1(Disable, void(GLenum cap)); |
| 1908 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); | 1913 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
| 1914 |
| 1915 private: |
| 1916 bool support_set_draw_rectangle_; |
| 1909 }; | 1917 }; |
| 1910 | 1918 |
| 1911 class GLRendererPartialSwapTest : public GLRendererTest { | 1919 class GLRendererPartialSwapTest : public GLRendererTest { |
| 1912 protected: | 1920 protected: |
| 1913 void RunTest(bool partial_swap) { | 1921 void RunTest(bool partial_swap, bool set_draw_rectangle) { |
| 1914 auto gl_owned = base::MakeUnique<PartialSwapMockGLES2Interface>(); | 1922 auto gl_owned = |
| 1923 base::MakeUnique<PartialSwapMockGLES2Interface>(set_draw_rectangle); |
| 1915 auto* gl = gl_owned.get(); | 1924 auto* gl = gl_owned.get(); |
| 1916 | 1925 |
| 1917 auto provider = TestContextProvider::Create(std::move(gl_owned)); | 1926 auto provider = TestContextProvider::Create(std::move(gl_owned)); |
| 1918 provider->BindToCurrentThread(); | 1927 provider->BindToCurrentThread(); |
| 1919 | 1928 |
| 1920 FakeOutputSurfaceClient output_surface_client; | 1929 FakeOutputSurfaceClient output_surface_client; |
| 1921 std::unique_ptr<FakeOutputSurface> output_surface( | 1930 std::unique_ptr<FakeOutputSurface> output_surface( |
| 1922 FakeOutputSurface::Create3d(std::move(provider))); | 1931 FakeOutputSurface::Create3d(std::move(provider))); |
| 1923 output_surface->BindToClient(&output_surface_client); | 1932 output_surface->BindToClient(&output_surface_client); |
| 1924 | 1933 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1948 EXPECT_CALL(*gl, Disable(GL_DEPTH_TEST)).InSequence(seq); | 1957 EXPECT_CALL(*gl, Disable(GL_DEPTH_TEST)).InSequence(seq); |
| 1949 EXPECT_CALL(*gl, Disable(GL_CULL_FACE)).InSequence(seq); | 1958 EXPECT_CALL(*gl, Disable(GL_CULL_FACE)).InSequence(seq); |
| 1950 EXPECT_CALL(*gl, Disable(GL_STENCIL_TEST)).InSequence(seq); | 1959 EXPECT_CALL(*gl, Disable(GL_STENCIL_TEST)).InSequence(seq); |
| 1951 EXPECT_CALL(*gl, Enable(GL_BLEND)).InSequence(seq); | 1960 EXPECT_CALL(*gl, Enable(GL_BLEND)).InSequence(seq); |
| 1952 EXPECT_CALL(*gl, Disable(GL_SCISSOR_TEST)).InSequence(seq); | 1961 EXPECT_CALL(*gl, Disable(GL_SCISSOR_TEST)).InSequence(seq); |
| 1953 EXPECT_CALL(*gl, Scissor(0, 0, 0, 0)).InSequence(seq); | 1962 EXPECT_CALL(*gl, Scissor(0, 0, 0, 0)).InSequence(seq); |
| 1954 | 1963 |
| 1955 // Partial frame, we should use a scissor to swap only that part when | 1964 // Partial frame, we should use a scissor to swap only that part when |
| 1956 // partial swap is enabled. | 1965 // partial swap is enabled. |
| 1957 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); | 1966 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
| 1967 gfx::Rect output_rectangle = |
| 1968 partial_swap ? root_pass->damage_rect : gfx::Rect(viewport_size); |
| 1958 | 1969 |
| 1959 if (partial_swap) { | 1970 if (partial_swap || set_draw_rectangle) { |
| 1960 EXPECT_CALL(*gl, Enable(GL_SCISSOR_TEST)).InSequence(seq); | 1971 EXPECT_CALL(*gl, Enable(GL_SCISSOR_TEST)).InSequence(seq); |
| 1961 // The scissor is flipped, so subtract the y coord and height from the | 1972 // The scissor is flipped, so subtract the y coord and height from the |
| 1962 // bottom of the GL viewport. | 1973 // bottom of the GL viewport. |
| 1963 EXPECT_CALL(*gl, Scissor(2, viewport_size.height() - 3 - 2, 3, 3)) | 1974 EXPECT_CALL( |
| 1975 *gl, |
| 1976 Scissor(output_rectangle.x(), |
| 1977 viewport_size.height() - output_rectangle.y() - |
| 1978 output_rectangle.height(), |
| 1979 output_rectangle.width(), output_rectangle.height())) |
| 1964 .InSequence(seq); | 1980 .InSequence(seq); |
| 1965 } | 1981 } |
| 1966 | 1982 |
| 1967 // The quad doesn't need blending. | 1983 // The quad doesn't need blending. |
| 1968 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); | 1984 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 1969 | 1985 |
| 1970 // Blending is disabled at the end of the frame. | 1986 // Blending is disabled at the end of the frame. |
| 1971 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); | 1987 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 1972 | 1988 |
| 1973 renderer.DecideRenderPassAllocationsForFrame( | 1989 renderer.DecideRenderPassAllocationsForFrame( |
| 1974 render_passes_in_draw_order_); | 1990 render_passes_in_draw_order_); |
| 1975 DrawFrame(&renderer, viewport_size); | 1991 DrawFrame(&renderer, viewport_size); |
| 1992 if (set_draw_rectangle) { |
| 1993 EXPECT_EQ(output_rectangle, output_surface->last_set_draw_rectangle()); |
| 1994 } |
| 1976 } | 1995 } |
| 1977 } | 1996 } |
| 1978 }; | 1997 }; |
| 1979 | 1998 |
| 1980 TEST_F(GLRendererPartialSwapTest, PartialSwap) { | 1999 TEST_F(GLRendererPartialSwapTest, PartialSwap) { |
| 1981 RunTest(true); | 2000 RunTest(true, false); |
| 1982 } | 2001 } |
| 1983 | 2002 |
| 1984 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { | 2003 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { |
| 1985 RunTest(false); | 2004 RunTest(false, false); |
| 2005 } |
| 2006 |
| 2007 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_PartialSwap) { |
| 2008 RunTest(true, true); |
| 2009 } |
| 2010 |
| 2011 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_NoPartialSwap) { |
| 2012 RunTest(false, true); |
| 1986 } | 2013 } |
| 1987 | 2014 |
| 1988 class GLRendererWithMockContextTest : public ::testing::Test { | 2015 class GLRendererWithMockContextTest : public ::testing::Test { |
| 1989 protected: | 2016 protected: |
| 1990 class MockContextSupport : public TestContextSupport { | 2017 class MockContextSupport : public TestContextSupport { |
| 1991 public: | 2018 public: |
| 1992 MockContextSupport() {} | 2019 MockContextSupport() {} |
| 1993 MOCK_METHOD1(SetAggressivelyFreeResources, | 2020 MOCK_METHOD1(SetAggressivelyFreeResources, |
| 1994 void(bool aggressively_free_resources)); | 2021 void(bool aggressively_free_resources)); |
| 1995 }; | 2022 }; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2024 renderer_->SetVisible(true); | 2051 renderer_->SetVisible(true); |
| 2025 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2052 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 2026 | 2053 |
| 2027 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); | 2054 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); |
| 2028 renderer_->SetVisible(false); | 2055 renderer_->SetVisible(false); |
| 2029 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2056 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 2030 } | 2057 } |
| 2031 | 2058 |
| 2032 } // namespace | 2059 } // namespace |
| 2033 } // namespace cc | 2060 } // namespace cc |
| OLD | NEW |