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 <set> | 7 #include <set> |
8 | 8 |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/output/compositor_frame_metadata.h" | 10 #include "cc/output/compositor_frame_metadata.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 output_surface_(FakeOutputSurface::Create3d( | 257 output_surface_(FakeOutputSurface::Create3d( |
258 scoped_ptr<WebKit::WebGraphicsContext3D>( | 258 scoped_ptr<WebKit::WebGraphicsContext3D>( |
259 new FrameCountingMemoryAllocationSettingContext()))), | 259 new FrameCountingMemoryAllocationSettingContext()))), |
260 resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)), | 260 resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)), |
261 renderer_(&mock_client_, | 261 renderer_(&mock_client_, |
262 output_surface_.get(), | 262 output_surface_.get(), |
263 resource_provider_.get()) {} | 263 resource_provider_.get()) {} |
264 | 264 |
265 virtual void SetUp() { renderer_.Initialize(); } | 265 virtual void SetUp() { renderer_.Initialize(); } |
266 | 266 |
267 void SwapBuffers() { renderer_.SwapBuffers(ui::LatencyInfo()); } | 267 void SwapBuffers() { renderer_.SwapBuffers(); } |
268 | 268 |
269 FrameCountingMemoryAllocationSettingContext* Context() { | 269 FrameCountingMemoryAllocationSettingContext* Context() { |
270 return static_cast<FrameCountingMemoryAllocationSettingContext*>( | 270 return static_cast<FrameCountingMemoryAllocationSettingContext*>( |
271 output_surface_->context3d()); | 271 output_surface_->context3d()); |
272 } | 272 } |
273 | 273 |
274 WebGraphicsMemoryAllocation suggest_have_backbuffer_yes_; | 274 WebGraphicsMemoryAllocation suggest_have_backbuffer_yes_; |
275 WebGraphicsMemoryAllocation suggest_have_backbuffer_no_; | 275 WebGraphicsMemoryAllocation suggest_have_backbuffer_no_; |
276 | 276 |
277 scoped_ptr<OutputSurface> output_surface_; | 277 scoped_ptr<OutputSurface> output_surface_; |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 | 1545 |
1546 class MockOutputSurface : public OutputSurface { | 1546 class MockOutputSurface : public OutputSurface { |
1547 public: | 1547 public: |
1548 MockOutputSurface() | 1548 MockOutputSurface() |
1549 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1549 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>( |
1550 new StrictMock<OutputSurfaceMockContext>)) { | 1550 new StrictMock<OutputSurfaceMockContext>)) { |
1551 surface_size_ = gfx::Size(100, 100); | 1551 surface_size_ = gfx::Size(100, 100); |
1552 } | 1552 } |
1553 virtual ~MockOutputSurface() {} | 1553 virtual ~MockOutputSurface() {} |
1554 | 1554 |
1555 MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame)); | |
1556 MOCK_METHOD0(EnsureBackbuffer, void()); | 1555 MOCK_METHOD0(EnsureBackbuffer, void()); |
1557 MOCK_METHOD0(DiscardBackbuffer, void()); | 1556 MOCK_METHOD0(DiscardBackbuffer, void()); |
1558 MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor)); | 1557 MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor)); |
1559 MOCK_METHOD0(BindFramebuffer, void()); | 1558 MOCK_METHOD0(BindFramebuffer, void()); |
1560 MOCK_METHOD2(PostSubBuffer, void(gfx::Rect rect, const ui::LatencyInfo&)); | 1559 MOCK_METHOD1(SwapBuffers, void(CompositorFrame* frame)); |
1561 MOCK_METHOD1(SwapBuffers, void(const ui::LatencyInfo&)); | |
1562 }; | 1560 }; |
1563 | 1561 |
1564 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient { | 1562 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient { |
1565 protected: | 1563 protected: |
1566 MockOutputSurfaceTest() | 1564 MockOutputSurfaceTest() |
1567 : resource_provider_(ResourceProvider::Create(&output_surface_, 0)), | 1565 : resource_provider_(ResourceProvider::Create(&output_surface_, 0)), |
1568 renderer_(this, &output_surface_, resource_provider_.get()) {} | 1566 renderer_(this, &output_surface_, resource_provider_.get()) {} |
1569 | 1567 |
1570 virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); } | 1568 virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); } |
1571 | 1569 |
1572 void SwapBuffers() { renderer_.SwapBuffers(ui::LatencyInfo()); } | 1570 void SwapBuffers() { renderer_.SwapBuffers(); } |
1573 | 1571 |
1574 void DrawFrame() { | 1572 void DrawFrame() { |
1575 gfx::Rect viewport_rect(DeviceViewport()); | 1573 gfx::Rect viewport_rect(DeviceViewport()); |
1576 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order(); | 1574 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order(); |
1577 render_passes->clear(); | 1575 render_passes->clear(); |
1578 | 1576 |
1579 RenderPass::Id render_pass_id(1, 0); | 1577 RenderPass::Id render_pass_id(1, 0); |
1580 TestRenderPass* render_pass = AddRenderPass( | 1578 TestRenderPass* render_pass = AddRenderPass( |
1581 render_passes, render_pass_id, viewport_rect, gfx::Transform()); | 1579 render_passes, render_pass_id, viewport_rect, gfx::Transform()); |
1582 AddQuad(render_pass, viewport_rect, SK_ColorGREEN); | 1580 AddQuad(render_pass, viewport_rect, SK_ColorGREEN); |
(...skipping 18 matching lines...) Expand all Loading... |
1601 | 1599 |
1602 StrictMock<MockOutputSurface> output_surface_; | 1600 StrictMock<MockOutputSurface> output_surface_; |
1603 scoped_ptr<ResourceProvider> resource_provider_; | 1601 scoped_ptr<ResourceProvider> resource_provider_; |
1604 FakeRendererGL renderer_; | 1602 FakeRendererGL renderer_; |
1605 }; | 1603 }; |
1606 | 1604 |
1607 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) { | 1605 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) { |
1608 DrawFrame(); | 1606 DrawFrame(); |
1609 | 1607 |
1610 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); | 1608 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); |
1611 renderer_.SwapBuffers(ui::LatencyInfo()); | 1609 renderer_.SwapBuffers(); |
1612 } | 1610 } |
1613 | 1611 |
1614 TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) { | 1612 TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) { |
1615 DrawFrame(); | 1613 DrawFrame(); |
1616 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); | 1614 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); |
1617 renderer_.SwapBuffers(ui::LatencyInfo()); | 1615 renderer_.SwapBuffers(); |
1618 | 1616 |
1619 set_viewport_and_scale(gfx::Size(2, 2), 2.f); | 1617 set_viewport_and_scale(gfx::Size(2, 2), 2.f); |
1620 renderer_.ViewportChanged(); | 1618 renderer_.ViewportChanged(); |
1621 | 1619 |
1622 DrawFrame(); | 1620 DrawFrame(); |
1623 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); | 1621 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); |
1624 renderer_.SwapBuffers(ui::LatencyInfo()); | 1622 renderer_.SwapBuffers(); |
1625 | 1623 |
1626 DrawFrame(); | 1624 DrawFrame(); |
1627 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); | 1625 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); |
1628 renderer_.SwapBuffers(ui::LatencyInfo()); | 1626 renderer_.SwapBuffers(); |
1629 | 1627 |
1630 set_viewport_and_scale(gfx::Size(1, 1), 1.f); | 1628 set_viewport_and_scale(gfx::Size(1, 1), 1.f); |
1631 renderer_.ViewportChanged(); | 1629 renderer_.ViewportChanged(); |
1632 | 1630 |
1633 DrawFrame(); | 1631 DrawFrame(); |
1634 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); | 1632 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); |
1635 renderer_.SwapBuffers(ui::LatencyInfo()); | 1633 renderer_.SwapBuffers(); |
1636 } | |
1637 | |
1638 class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest { | |
1639 public: | |
1640 virtual const LayerTreeSettings& Settings() const OVERRIDE { | |
1641 static LayerTreeSettings fake_settings; | |
1642 fake_settings.partial_swap_enabled = true; | |
1643 return fake_settings; | |
1644 } | |
1645 }; | |
1646 | |
1647 TEST_F(MockOutputSurfaceTestWithPartialSwap, DrawFrameAndSwap) { | |
1648 DrawFrame(); | |
1649 | |
1650 EXPECT_CALL(output_surface_, PostSubBuffer(_, _)).Times(1); | |
1651 renderer_.SwapBuffers(ui::LatencyInfo()); | |
1652 } | |
1653 | |
1654 class MockOutputSurfaceTestWithSendCompositorFrame | |
1655 : public MockOutputSurfaceTest { | |
1656 public: | |
1657 virtual const LayerTreeSettings& Settings() const OVERRIDE { | |
1658 static LayerTreeSettings fake_settings; | |
1659 fake_settings.compositor_frame_message = true; | |
1660 return fake_settings; | |
1661 } | |
1662 }; | |
1663 | |
1664 TEST_F(MockOutputSurfaceTestWithSendCompositorFrame, DrawFrame) { | |
1665 EXPECT_CALL(output_surface_, SendFrameToParentCompositor(_)).Times(1); | |
1666 DrawFrame(); | |
1667 } | 1634 } |
1668 | 1635 |
1669 class GLRendererTestSyncPoint : public GLRendererPixelTest { | 1636 class GLRendererTestSyncPoint : public GLRendererPixelTest { |
1670 protected: | 1637 protected: |
1671 static void SyncPointCallback(int* callback_count) { | 1638 static void SyncPointCallback(int* callback_count) { |
1672 ++(*callback_count); | 1639 ++(*callback_count); |
1673 base::MessageLoop::current()->QuitWhenIdle(); | 1640 base::MessageLoop::current()->QuitWhenIdle(); |
1674 } | 1641 } |
1675 | 1642 |
1676 static void OtherCallback(int* callback_count) { | 1643 static void OtherCallback(int* callback_count) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 base::MessageLoop::current()->Run(); | 1698 base::MessageLoop::current()->Run(); |
1732 | 1699 |
1733 // The sync point should have happened. | 1700 // The sync point should have happened. |
1734 EXPECT_EQ(1, sync_point_callback_count); | 1701 EXPECT_EQ(1, sync_point_callback_count); |
1735 EXPECT_EQ(1, other_callback_count); | 1702 EXPECT_EQ(1, other_callback_count); |
1736 } | 1703 } |
1737 #endif // OS_ANDROID | 1704 #endif // OS_ANDROID |
1738 | 1705 |
1739 } // namespace | 1706 } // namespace |
1740 } // namespace cc | 1707 } // namespace cc |
OLD | NEW |