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 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1634 OverlayCandidateList* candidates, | 1634 OverlayCandidateList* candidates, |
1635 std::vector<gfx::Rect>* content_bounds)); | 1635 std::vector<gfx::Rect>* content_bounds)); |
1636 }; | 1636 }; |
1637 | 1637 |
1638 class Validator : public OverlayCandidateValidator { | 1638 class Validator : public OverlayCandidateValidator { |
1639 public: | 1639 public: |
1640 void GetStrategies(OverlayProcessor::StrategyList* strategies) override {} | 1640 void GetStrategies(OverlayProcessor::StrategyList* strategies) override {} |
1641 | 1641 |
1642 // Returns true if draw quads can be represented as CALayers (Mac only). | 1642 // Returns true if draw quads can be represented as CALayers (Mac only). |
1643 MOCK_METHOD0(AllowCALayerOverlays, bool()); | 1643 MOCK_METHOD0(AllowCALayerOverlays, bool()); |
1644 | 1644 MOCK_METHOD0(AllowDCLayerOverlays, bool()); |
1645 bool AllowDCLayerOverlays() override { return false; } | |
1646 | 1645 |
1647 // A list of possible overlay candidates is presented to this function. | 1646 // A list of possible overlay candidates is presented to this function. |
1648 // The expected result is that those candidates that can be in a separate | 1647 // The expected result is that those candidates that can be in a separate |
1649 // plane are marked with |overlay_handled| set to true, otherwise they are | 1648 // plane are marked with |overlay_handled| set to true, otherwise they are |
1650 // to be traditionally composited. Candidates with |overlay_handled| set to | 1649 // to be traditionally composited. Candidates with |overlay_handled| set to |
1651 // true must also have their |display_rect| converted to integer | 1650 // true must also have their |display_rect| converted to integer |
1652 // coordinates if necessary. | 1651 // coordinates if necessary. |
1653 void CheckOverlaySupport(OverlayCandidateList* surfaces) {} | 1652 void CheckOverlaySupport(OverlayCandidateList* surfaces) {} |
1654 }; | 1653 }; |
1655 | 1654 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1726 premultiplied_alpha, gfx::PointF(0, 0), gfx::PointF(1, 1), | 1725 premultiplied_alpha, gfx::PointF(0, 0), gfx::PointF(1, 1), |
1727 SK_ColorTRANSPARENT, vertex_opacity, flipped, nearest_neighbor, false); | 1726 SK_ColorTRANSPARENT, vertex_opacity, flipped, nearest_neighbor, false); |
1728 | 1727 |
1729 // DirectRenderer::DrawFrame calls into OverlayProcessor::ProcessForOverlays. | 1728 // DirectRenderer::DrawFrame calls into OverlayProcessor::ProcessForOverlays. |
1730 // Attempt will be called for each strategy in OverlayProcessor. We have | 1729 // Attempt will be called for each strategy in OverlayProcessor. We have |
1731 // added a fake strategy, so checking for Attempt calls checks if there was | 1730 // added a fake strategy, so checking for Attempt calls checks if there was |
1732 // any attempt to overlay, which there shouldn't be. We can't use the quad | 1731 // any attempt to overlay, which there shouldn't be. We can't use the quad |
1733 // list because the render pass is cleaned up by DrawFrame. | 1732 // list because the render pass is cleaned up by DrawFrame. |
1734 EXPECT_CALL(*processor->strategy_, Attempt(_, _, _, _)).Times(0); | 1733 EXPECT_CALL(*processor->strategy_, Attempt(_, _, _, _)).Times(0); |
1735 EXPECT_CALL(*validator, AllowCALayerOverlays()).Times(0); | 1734 EXPECT_CALL(*validator, AllowCALayerOverlays()).Times(0); |
1735 EXPECT_CALL(*validator, AllowDCLayerOverlays()).Times(0); | |
1736 DrawFrame(&renderer, viewport_size); | 1736 DrawFrame(&renderer, viewport_size); |
1737 Mock::VerifyAndClearExpectations(processor->strategy_); | 1737 Mock::VerifyAndClearExpectations(processor->strategy_); |
1738 Mock::VerifyAndClearExpectations(validator.get()); | 1738 Mock::VerifyAndClearExpectations(validator.get()); |
1739 | 1739 |
1740 // Without a copy request Attempt() should be called once. | 1740 // Without a copy request Attempt() should be called once. |
1741 root_pass = | 1741 root_pass = |
1742 AddRenderPass(&render_passes_in_draw_order_, 1, gfx::Rect(viewport_size), | 1742 AddRenderPass(&render_passes_in_draw_order_, 1, gfx::Rect(viewport_size), |
1743 gfx::Transform(), FilterOperations()); | 1743 gfx::Transform(), FilterOperations()); |
1744 root_pass->has_transparent_background = false; | 1744 root_pass->has_transparent_background = false; |
1745 | 1745 |
1746 overlay_quad = root_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 1746 overlay_quad = root_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
1747 overlay_quad->SetNew( | 1747 overlay_quad->SetNew( |
1748 root_pass->CreateAndAppendSharedQuadState(), gfx::Rect(viewport_size), | 1748 root_pass->CreateAndAppendSharedQuadState(), gfx::Rect(viewport_size), |
1749 gfx::Rect(viewport_size), gfx::Rect(viewport_size), resource_id, | 1749 gfx::Rect(viewport_size), gfx::Rect(viewport_size), resource_id, |
1750 premultiplied_alpha, gfx::PointF(0, 0), gfx::PointF(1, 1), | 1750 premultiplied_alpha, gfx::PointF(0, 0), gfx::PointF(1, 1), |
1751 SK_ColorTRANSPARENT, vertex_opacity, flipped, nearest_neighbor, false); | 1751 SK_ColorTRANSPARENT, vertex_opacity, flipped, nearest_neighbor, false); |
1752 EXPECT_CALL(*validator, AllowCALayerOverlays()) | 1752 EXPECT_CALL(*validator, AllowCALayerOverlays()) |
1753 .Times(1) | 1753 .Times(1) |
1754 .WillOnce(::testing::Return(false)); | 1754 .WillOnce(::testing::Return(false)); |
1755 EXPECT_CALL(*validator, AllowDCLayerOverlays()) | |
1756 .Times(1) | |
1757 .WillOnce(::testing::Return(false)); | |
1755 EXPECT_CALL(*processor->strategy_, Attempt(_, _, _, _)).Times(1); | 1758 EXPECT_CALL(*processor->strategy_, Attempt(_, _, _, _)).Times(1); |
1756 DrawFrame(&renderer, viewport_size); | 1759 DrawFrame(&renderer, viewport_size); |
1757 | 1760 |
1758 // If the CALayerOverlay path is taken, then the ordinary overlay path should | 1761 // If the CALayerOverlay path is taken, then the ordinary overlay path should |
1759 // not be called. | 1762 // not be called. |
1760 root_pass = | 1763 root_pass = |
1761 AddRenderPass(&render_passes_in_draw_order_, 1, gfx::Rect(viewport_size), | 1764 AddRenderPass(&render_passes_in_draw_order_, 1, gfx::Rect(viewport_size), |
1762 gfx::Transform(), FilterOperations()); | 1765 gfx::Transform(), FilterOperations()); |
1763 root_pass->has_transparent_background = false; | 1766 root_pass->has_transparent_background = false; |
1764 | 1767 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1897 overlay_scheduler, | 1900 overlay_scheduler, |
1898 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), | 1901 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, gfx::Rect(viewport_size), |
1899 BoundingRect(uv_top_left, uv_bottom_right))) | 1902 BoundingRect(uv_top_left, uv_bottom_right))) |
1900 .Times(1); | 1903 .Times(1); |
1901 | 1904 |
1902 DrawFrame(&renderer, viewport_size); | 1905 DrawFrame(&renderer, viewport_size); |
1903 } | 1906 } |
1904 | 1907 |
1905 class PartialSwapMockGLES2Interface : public TestGLES2Interface { | 1908 class PartialSwapMockGLES2Interface : public TestGLES2Interface { |
1906 public: | 1909 public: |
1907 explicit PartialSwapMockGLES2Interface(bool support_set_draw_rectangle) | 1910 explicit PartialSwapMockGLES2Interface(bool support_set_draw_rectangle) |
sunnyps
2017/03/20 23:38:57
nit: support_dc_layers?
| |
1908 : support_set_draw_rectangle_(support_set_draw_rectangle) {} | 1911 : support_set_draw_rectangle_(support_set_draw_rectangle) {} |
1909 | 1912 |
1910 void InitializeTestContext(TestWebGraphicsContext3D* context) override { | 1913 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
1911 context->set_have_post_sub_buffer(true); | 1914 context->set_have_post_sub_buffer(true); |
1912 context->set_support_set_draw_rectangle(support_set_draw_rectangle_); | 1915 context->set_enable_dc_layers(support_set_draw_rectangle_); |
1913 } | 1916 } |
1914 | 1917 |
1915 MOCK_METHOD1(Enable, void(GLenum cap)); | 1918 MOCK_METHOD1(Enable, void(GLenum cap)); |
1916 MOCK_METHOD1(Disable, void(GLenum cap)); | 1919 MOCK_METHOD1(Disable, void(GLenum cap)); |
1917 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); | 1920 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
1921 MOCK_METHOD1(SetEnableDCLayersCHROMIUM, void(GLboolean enable)); | |
1918 | 1922 |
1919 private: | 1923 private: |
1920 bool support_set_draw_rectangle_; | 1924 bool support_set_draw_rectangle_; |
1921 }; | 1925 }; |
1922 | 1926 |
1923 class GLRendererPartialSwapTest : public GLRendererTest { | 1927 class GLRendererPartialSwapTest : public GLRendererTest { |
1924 protected: | 1928 protected: |
1925 void RunTest(bool partial_swap, bool set_draw_rectangle) { | 1929 void RunTest(bool partial_swap, bool set_draw_rectangle) { |
1926 auto gl_owned = | 1930 auto gl_owned = |
1927 base::MakeUnique<PartialSwapMockGLES2Interface>(set_draw_rectangle); | 1931 base::MakeUnique<PartialSwapMockGLES2Interface>(set_draw_rectangle); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2009 } | 2013 } |
2010 | 2014 |
2011 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_PartialSwap) { | 2015 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_PartialSwap) { |
2012 RunTest(true, true); | 2016 RunTest(true, true); |
2013 } | 2017 } |
2014 | 2018 |
2015 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_NoPartialSwap) { | 2019 TEST_F(GLRendererPartialSwapTest, SetDrawRectangle_NoPartialSwap) { |
2016 RunTest(false, true); | 2020 RunTest(false, true); |
2017 } | 2021 } |
2018 | 2022 |
2023 class DCLayerValidator : public OverlayCandidateValidator { | |
2024 public: | |
2025 void GetStrategies(OverlayProcessor::StrategyList* strategies) override {} | |
2026 bool AllowCALayerOverlays() override { return false; } | |
2027 bool AllowDCLayerOverlays() override { return true; } | |
2028 void CheckOverlaySupport(OverlayCandidateList* surfaces) override {} | |
2029 }; | |
2030 | |
2031 // Test that SetEnableDCLayersCHROMIUM is properly called when enabling | |
2032 // and disabling DC layers. | |
2033 TEST_F(GLRendererTest, DCLayerOverlaySwitch) { | |
2034 auto gl_owned = base::MakeUnique<PartialSwapMockGLES2Interface>(true); | |
2035 auto* gl = gl_owned.get(); | |
2036 | |
2037 auto provider = TestContextProvider::Create(std::move(gl_owned)); | |
2038 provider->BindToCurrentThread(); | |
2039 | |
2040 FakeOutputSurfaceClient output_surface_client; | |
2041 std::unique_ptr<FakeOutputSurface> output_surface( | |
2042 FakeOutputSurface::Create3d(std::move(provider))); | |
2043 output_surface->BindToClient(&output_surface_client); | |
2044 | |
2045 std::unique_ptr<ResourceProvider> resource_provider = | |
2046 FakeResourceProvider::Create(output_surface->context_provider(), nullptr); | |
2047 | |
2048 RendererSettings settings; | |
2049 settings.partial_swap_enabled = true; | |
2050 FakeRendererGL renderer(&settings, output_surface.get(), | |
2051 resource_provider.get()); | |
2052 renderer.Initialize(); | |
2053 renderer.SetVisible(true); | |
2054 TestOverlayProcessor* processor = | |
2055 new TestOverlayProcessor(output_surface.get()); | |
2056 processor->Initialize(); | |
2057 renderer.SetOverlayProcessor(processor); | |
2058 std::unique_ptr<DCLayerValidator> validator(new DCLayerValidator); | |
2059 output_surface->SetOverlayCandidateValidator(validator.get()); | |
2060 | |
2061 gfx::Size viewport_size(100, 100); | |
2062 | |
2063 TextureMailbox mailbox = | |
2064 TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D, | |
2065 gfx::Size(256, 256), true, false); | |
2066 std::unique_ptr<SingleReleaseCallbackImpl> release_callback = | |
2067 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased)); | |
2068 ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox( | |
2069 mailbox, std::move(release_callback)); | |
2070 | |
2071 for (int i = 0; i < 65; i++) { | |
2072 int root_pass_id = 1; | |
2073 RenderPass* root_pass = AddRenderPass( | |
2074 &render_passes_in_draw_order_, root_pass_id, gfx::Rect(viewport_size), | |
2075 gfx::Transform(), FilterOperations()); | |
2076 if (i == 0) { | |
2077 gfx::Rect rect(0, 0, 100, 100); | |
2078 gfx::RectF tex_coord_rect(0, 0, 1, 1); | |
2079 SharedQuadState* shared_state = | |
2080 root_pass->CreateAndAppendSharedQuadState(); | |
2081 shared_state->SetAll(gfx::Transform(), rect.size(), rect, rect, false, 1, | |
2082 SkBlendMode::kSrcOver, 0); | |
2083 YUVVideoDrawQuad* quad = | |
2084 root_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>(); | |
2085 quad->SetNew(shared_state, rect, rect, rect, tex_coord_rect, | |
2086 tex_coord_rect, rect.size(), rect.size(), resource_id, | |
2087 resource_id, resource_id, resource_id, | |
2088 YUVVideoDrawQuad::REC_601, gfx::ColorSpace(), 0, 1.0, 8); | |
2089 } | |
2090 | |
2091 // A bunch of initialization that happens. | |
2092 EXPECT_CALL(*gl, Disable(_)).Times(AnyNumber()); | |
2093 EXPECT_CALL(*gl, Enable(_)).Times(AnyNumber()); | |
2094 EXPECT_CALL(*gl, Scissor(_, _, _, _)).Times(AnyNumber()); | |
2095 | |
2096 // Partial frame, we should use a scissor to swap only that part when | |
2097 // partial swap is enabled. | |
2098 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); | |
2099 // Frame 0 should be completely damaged because it's the first. | |
2100 // Frame 1 should be because it changed. Frame 60 should be | |
2101 // because it's disabling DC layers. | |
2102 gfx::Rect output_rectangle = (i == 0 || i == 1 || i == 60) | |
2103 ? root_pass->output_rect | |
2104 : root_pass->damage_rect; | |
2105 | |
2106 // Frame 0 should have DC Layers enabled because of the overlay. | |
2107 // After 60 frames of no overlays DC layers should be disabled again. | |
2108 if (i < 60) | |
2109 EXPECT_CALL(*gl, SetEnableDCLayersCHROMIUM(GL_TRUE)); | |
2110 else | |
2111 EXPECT_CALL(*gl, SetEnableDCLayersCHROMIUM(GL_FALSE)); | |
2112 | |
2113 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | |
2114 DrawFrame(&renderer, viewport_size); | |
2115 EXPECT_EQ(output_rectangle, output_surface->last_set_draw_rectangle()); | |
2116 testing::Mock::VerifyAndClearExpectations(gl); | |
2117 } | |
2118 } | |
2119 | |
2019 class GLRendererWithMockContextTest : public ::testing::Test { | 2120 class GLRendererWithMockContextTest : public ::testing::Test { |
2020 protected: | 2121 protected: |
2021 class MockContextSupport : public TestContextSupport { | 2122 class MockContextSupport : public TestContextSupport { |
2022 public: | 2123 public: |
2023 MockContextSupport() {} | 2124 MockContextSupport() {} |
2024 MOCK_METHOD1(SetAggressivelyFreeResources, | 2125 MOCK_METHOD1(SetAggressivelyFreeResources, |
2025 void(bool aggressively_free_resources)); | 2126 void(bool aggressively_free_resources)); |
2026 }; | 2127 }; |
2027 | 2128 |
2028 void SetUp() override { | 2129 void SetUp() override { |
(...skipping 26 matching lines...) Expand all Loading... | |
2055 renderer_->SetVisible(true); | 2156 renderer_->SetVisible(true); |
2056 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2157 Mock::VerifyAndClearExpectations(context_support_ptr_); |
2057 | 2158 |
2058 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); | 2159 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); |
2059 renderer_->SetVisible(false); | 2160 renderer_->SetVisible(false); |
2060 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2161 Mock::VerifyAndClearExpectations(context_support_ptr_); |
2061 } | 2162 } |
2062 | 2163 |
2063 } // namespace | 2164 } // namespace |
2064 } // namespace cc | 2165 } // namespace cc |
OLD | NEW |