Chromium Code Reviews| 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 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 | 1488 |
| 1489 MOCK_METHOD0(EnsureBackbuffer, void()); | 1489 MOCK_METHOD0(EnsureBackbuffer, void()); |
| 1490 MOCK_METHOD0(DiscardBackbuffer, void()); | 1490 MOCK_METHOD0(DiscardBackbuffer, void()); |
| 1491 MOCK_METHOD5(Reshape, | 1491 MOCK_METHOD5(Reshape, |
| 1492 void(const gfx::Size& size, | 1492 void(const gfx::Size& size, |
| 1493 float scale_factor, | 1493 float scale_factor, |
| 1494 const gfx::ColorSpace& color_space, | 1494 const gfx::ColorSpace& color_space, |
| 1495 bool has_alpha, | 1495 bool has_alpha, |
| 1496 bool use_stencil)); | 1496 bool use_stencil)); |
| 1497 MOCK_METHOD0(BindFramebuffer, void()); | 1497 MOCK_METHOD0(BindFramebuffer, void()); |
| 1498 MOCK_METHOD1(SetDrawRectangle, void(const gfx::Rect&)); | |
| 1498 MOCK_METHOD0(GetFramebufferCopyTextureFormat, GLenum()); | 1499 MOCK_METHOD0(GetFramebufferCopyTextureFormat, GLenum()); |
| 1499 MOCK_METHOD1(SwapBuffers_, void(OutputSurfaceFrame& frame)); // NOLINT | 1500 MOCK_METHOD1(SwapBuffers_, void(OutputSurfaceFrame& frame)); // NOLINT |
| 1500 void SwapBuffers(OutputSurfaceFrame frame) override { SwapBuffers_(frame); } | 1501 void SwapBuffers(OutputSurfaceFrame frame) override { SwapBuffers_(frame); } |
| 1501 MOCK_CONST_METHOD0(GetOverlayCandidateValidator, | 1502 MOCK_CONST_METHOD0(GetOverlayCandidateValidator, |
| 1502 OverlayCandidateValidator*()); | 1503 OverlayCandidateValidator*()); |
| 1503 MOCK_CONST_METHOD0(IsDisplayedAsOverlayPlane, bool()); | 1504 MOCK_CONST_METHOD0(IsDisplayedAsOverlayPlane, bool()); |
| 1504 MOCK_CONST_METHOD0(GetOverlayTextureId, unsigned()); | 1505 MOCK_CONST_METHOD0(GetOverlayTextureId, unsigned()); |
| 1505 MOCK_CONST_METHOD0(SurfaceIsSuspendForRecycle, bool()); | 1506 MOCK_CONST_METHOD0(SurfaceIsSuspendForRecycle, bool()); |
| 1506 MOCK_CONST_METHOD0(HasExternalStencilTest, bool()); | 1507 MOCK_CONST_METHOD0(HasExternalStencilTest, bool()); |
| 1507 MOCK_METHOD0(ApplyExternalStencil, void()); | 1508 MOCK_METHOD0(ApplyExternalStencil, void()); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), | 1856 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), |
| 1856 BoundingRect(uv_top_left, uv_bottom_right))) | 1857 BoundingRect(uv_top_left, uv_bottom_right))) |
| 1857 .Times(1); | 1858 .Times(1); |
| 1858 | 1859 |
| 1859 DrawFrame(&renderer, viewport_size); | 1860 DrawFrame(&renderer, viewport_size); |
| 1860 } | 1861 } |
| 1861 | 1862 |
| 1862 class PartialSwapMockGLES2Interface : public TestGLES2Interface { | 1863 class PartialSwapMockGLES2Interface : public TestGLES2Interface { |
| 1863 public: | 1864 public: |
| 1864 void InitializeTestContext(TestWebGraphicsContext3D* context) override { | 1865 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
| 1865 context->set_have_post_sub_buffer(true); | 1866 context->set_have_post_sub_buffer(true); |
|
danakj
2017/02/23 23:38:51
can you set_support_set_draw_rectangle here instea
| |
| 1866 } | 1867 } |
| 1867 | 1868 |
| 1868 MOCK_METHOD1(Enable, void(GLenum cap)); | 1869 MOCK_METHOD1(Enable, void(GLenum cap)); |
| 1869 MOCK_METHOD1(Disable, void(GLenum cap)); | 1870 MOCK_METHOD1(Disable, void(GLenum cap)); |
| 1870 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); | 1871 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
| 1871 }; | 1872 }; |
| 1872 | 1873 |
| 1873 class GLRendererPartialSwapTest : public GLRendererTest { | 1874 class GLRendererPartialSwapTest : public GLRendererTest { |
| 1874 protected: | 1875 protected: |
| 1875 void RunTest(bool partial_swap) { | 1876 void RunTest(bool partial_swap, bool set_draw_rectangle) { |
| 1876 auto gl_owned = base::MakeUnique<PartialSwapMockGLES2Interface>(); | 1877 auto gl_owned = base::MakeUnique<PartialSwapMockGLES2Interface>(); |
| 1877 auto* gl = gl_owned.get(); | 1878 auto* gl = gl_owned.get(); |
| 1878 | 1879 |
| 1879 auto provider = TestContextProvider::Create(std::move(gl_owned)); | 1880 auto provider = TestContextProvider::Create(std::move(gl_owned)); |
| 1880 provider->BindToCurrentThread(); | 1881 provider->BindToCurrentThread(); |
| 1882 provider->TestContext3d()->set_support_set_draw_rectangle( | |
| 1883 set_draw_rectangle); | |
| 1881 | 1884 |
| 1882 FakeOutputSurfaceClient output_surface_client; | 1885 FakeOutputSurfaceClient output_surface_client; |
| 1883 std::unique_ptr<FakeOutputSurface> output_surface( | 1886 std::unique_ptr<FakeOutputSurface> output_surface( |
| 1884 FakeOutputSurface::Create3d(std::move(provider))); | 1887 FakeOutputSurface::Create3d(std::move(provider))); |
| 1885 output_surface->BindToClient(&output_surface_client); | 1888 output_surface->BindToClient(&output_surface_client); |
| 1886 | 1889 |
| 1887 std::unique_ptr<ResourceProvider> resource_provider = | 1890 std::unique_ptr<ResourceProvider> resource_provider = |
| 1888 FakeResourceProvider::Create(output_surface->context_provider(), | 1891 FakeResourceProvider::Create(output_surface->context_provider(), |
| 1889 nullptr); | 1892 nullptr); |
| 1890 | 1893 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1910 EXPECT_CALL(*gl, Disable(GL_DEPTH_TEST)).InSequence(seq); | 1913 EXPECT_CALL(*gl, Disable(GL_DEPTH_TEST)).InSequence(seq); |
| 1911 EXPECT_CALL(*gl, Disable(GL_CULL_FACE)).InSequence(seq); | 1914 EXPECT_CALL(*gl, Disable(GL_CULL_FACE)).InSequence(seq); |
| 1912 EXPECT_CALL(*gl, Disable(GL_STENCIL_TEST)).InSequence(seq); | 1915 EXPECT_CALL(*gl, Disable(GL_STENCIL_TEST)).InSequence(seq); |
| 1913 EXPECT_CALL(*gl, Enable(GL_BLEND)).InSequence(seq); | 1916 EXPECT_CALL(*gl, Enable(GL_BLEND)).InSequence(seq); |
| 1914 EXPECT_CALL(*gl, Disable(GL_SCISSOR_TEST)).InSequence(seq); | 1917 EXPECT_CALL(*gl, Disable(GL_SCISSOR_TEST)).InSequence(seq); |
| 1915 EXPECT_CALL(*gl, Scissor(0, 0, 0, 0)).InSequence(seq); | 1918 EXPECT_CALL(*gl, Scissor(0, 0, 0, 0)).InSequence(seq); |
| 1916 | 1919 |
| 1917 // Partial frame, we should use a scissor to swap only that part when | 1920 // Partial frame, we should use a scissor to swap only that part when |
| 1918 // partial swap is enabled. | 1921 // partial swap is enabled. |
| 1919 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); | 1922 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
| 1923 gfx::Rect output_rectangle = | |
| 1924 partial_swap ? root_pass->damage_rect : gfx::Rect(viewport_size); | |
| 1920 | 1925 |
| 1921 if (partial_swap) { | 1926 if (partial_swap || set_draw_rectangle) { |
| 1922 EXPECT_CALL(*gl, Enable(GL_SCISSOR_TEST)).InSequence(seq); | 1927 EXPECT_CALL(*gl, Enable(GL_SCISSOR_TEST)).InSequence(seq); |
| 1923 // The scissor is flipped, so subtract the y coord and height from the | 1928 // The scissor is flipped, so subtract the y coord and height from the |
| 1924 // bottom of the GL viewport. | 1929 // bottom of the GL viewport. |
| 1925 EXPECT_CALL(*gl, Scissor(2, viewport_size.height() - 3 - 2, 3, 3)) | 1930 EXPECT_CALL( |
| 1931 *gl, Scissor(output_rectangle.x(), | |
| 1932 viewport_size.height() - output_rectangle.y() - | |
| 1933 output_rectangle.height(), | |
| 1934 output_rectangle.width(), output_rectangle.height())) | |
| 1926 .InSequence(seq); | 1935 .InSequence(seq); |
| 1927 } | 1936 } |
| 1928 | 1937 |
| 1929 // The quad doesn't need blending. | 1938 // The quad doesn't need blending. |
| 1930 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); | 1939 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 1931 | 1940 |
| 1932 // Blending is disabled at the end of the frame. | 1941 // Blending is disabled at the end of the frame. |
| 1933 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); | 1942 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 1934 | 1943 |
| 1935 renderer.DecideRenderPassAllocationsForFrame( | 1944 renderer.DecideRenderPassAllocationsForFrame( |
| 1936 render_passes_in_draw_order_); | 1945 render_passes_in_draw_order_); |
| 1937 DrawFrame(&renderer, viewport_size); | 1946 DrawFrame(&renderer, viewport_size); |
| 1947 if (set_draw_rectangle) { | |
| 1948 EXPECT_EQ(output_rectangle, output_surface->last_set_draw_rectangle()); | |
|
danakj
2017/02/23 23:38:51
FWIW you could mock and EXPECT the method instead
| |
| 1949 } | |
| 1938 } | 1950 } |
| 1939 } | 1951 } |
| 1940 }; | 1952 }; |
| 1941 | 1953 |
| 1942 TEST_F(GLRendererPartialSwapTest, PartialSwap) { | 1954 TEST_F(GLRendererPartialSwapTest, PartialSwap) { |
| 1943 RunTest(true); | 1955 RunTest(true, false); |
| 1944 } | 1956 } |
| 1945 | 1957 |
| 1946 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { | 1958 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { |
| 1947 RunTest(false); | 1959 RunTest(false, false); |
| 1960 } | |
| 1961 | |
| 1962 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle) { | |
|
danakj
2017/02/23 23:38:51
nit: maybe name the two test variants a bit more e
| |
| 1963 RunTest(true, true); | |
| 1964 } | |
| 1965 | |
| 1966 TEST_F(GLRendererPartialSwapTest, SetDrawRectangleNoPartialSwap) { | |
| 1967 RunTest(false, true); | |
| 1948 } | 1968 } |
| 1949 | 1969 |
| 1950 class GLRendererWithMockContextTest : public ::testing::Test { | 1970 class GLRendererWithMockContextTest : public ::testing::Test { |
| 1951 protected: | 1971 protected: |
| 1952 class MockContextSupport : public TestContextSupport { | 1972 class MockContextSupport : public TestContextSupport { |
| 1953 public: | 1973 public: |
| 1954 MockContextSupport() {} | 1974 MockContextSupport() {} |
| 1955 MOCK_METHOD1(SetAggressivelyFreeResources, | 1975 MOCK_METHOD1(SetAggressivelyFreeResources, |
| 1956 void(bool aggressively_free_resources)); | 1976 void(bool aggressively_free_resources)); |
| 1957 }; | 1977 }; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1986 renderer_->SetVisible(true); | 2006 renderer_->SetVisible(true); |
| 1987 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2007 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 1988 | 2008 |
| 1989 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); | 2009 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); |
| 1990 renderer_->SetVisible(false); | 2010 renderer_->SetVisible(false); |
| 1991 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2011 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 1992 } | 2012 } |
| 1993 | 2013 |
| 1994 } // namespace | 2014 } // namespace |
| 1995 } // namespace cc | 2015 } // namespace cc |
| OLD | NEW |