Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: cc/gl_renderer_unittest.cc

Issue 12371002: [cc] Mailbox Output Surface Support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/gl_renderer.cc ('k') | cc/layer_tree_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gl_renderer.h" 5 #include "cc/gl_renderer.h"
6 6
7 #include "cc/compositor_frame_metadata.h" 7 #include "cc/compositor_frame_metadata.h"
8 #include "cc/draw_quad.h" 8 #include "cc/draw_quad.h"
9 #include "cc/prioritized_resource_manager.h" 9 #include "cc/prioritized_resource_manager.h"
10 #include "cc/resource_provider.h" 10 #include "cc/resource_provider.h"
11 #include "cc/test/fake_impl_proxy.h" 11 #include "cc/test/fake_impl_proxy.h"
12 #include "cc/test/fake_layer_tree_host_impl.h" 12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/fake_output_surface.h" 13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/render_pass_test_common.h" 14 #include "cc/test/render_pass_test_common.h"
15 #include "cc/test/render_pass_test_utils.h" 15 #include "cc/test/render_pass_test_utils.h"
16 #include "cc/test/test_web_graphics_context_3d.h" 16 #include "cc/test/test_web_graphics_context_3d.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/khronos/GLES2/gl2.h" 19 #include "third_party/khronos/GLES2/gl2.h"
20 #include "ui/gfx/transform.h" 20 #include "ui/gfx/transform.h"
21 21
22 using namespace WebKit; 22 using namespace WebKit;
23 23
24 using testing::_; 24 using testing::_;
25 using testing::AnyNumber; 25 using testing::AnyNumber;
26 using testing::AtLeast; 26 using testing::AtLeast;
27 using testing::Expectation; 27 using testing::Expectation;
28 using testing::InSequence; 28 using testing::InSequence;
29 using testing::Mock; 29 using testing::Mock;
30 using testing::Return;
31 using testing::StrictMock;
30 32
31 namespace cc { 33 namespace cc {
32 namespace { 34 namespace {
33 35
34 class FrameCountingMemoryAllocationSettingContext : public TestWebGraphicsContex t3D { 36 class FrameCountingMemoryAllocationSettingContext : public TestWebGraphicsContex t3D {
35 public: 37 public:
36 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } 38 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { }
37 39
38 // WebGraphicsContext3D methods. 40 // WebGraphicsContext3D methods.
39 41
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 TestRenderPass* rootPass = addRenderPass(renderPasses, rootPassId, viewportR ect, gfx::Transform()); 689 TestRenderPass* rootPass = addRenderPass(renderPasses, rootPassId, viewportR ect, gfx::Transform());
688 addQuad(rootPass, viewportRect, SK_ColorGREEN); 690 addQuad(rootPass, viewportRect, SK_ColorGREEN);
689 691
690 addRenderPassQuad(rootPass, childPass); 692 addRenderPassQuad(rootPass, childPass);
691 addRenderPassQuad(childPass, grandChildPass); 693 addRenderPassQuad(childPass, grandChildPass);
692 694
693 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr der()); 695 renderer.decideRenderPassAllocationsForFrame(mockClient.renderPassesInDrawOr der());
694 renderer.drawFrame(mockClient.renderPassesInDrawOrder()); 696 renderer.drawFrame(mockClient.renderPassesInDrawOrder());
695 } 697 }
696 698
699 class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
700 public:
701 // Specifically override methods even if they are unused (used in conjunctio n with StrictMock).
702 // We need to make sure that GLRenderer does not issue framebuffer-related G L calls directly. Instead these
703 // are supposed to go through the OutputSurface abstraction.
704 MOCK_METHOD0(ensureBackbufferCHROMIUM, void());
705 MOCK_METHOD0(discardBackbufferCHROMIUM, void());
706 MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer));
707 MOCK_METHOD0(prepareTexture, void());
708 MOCK_METHOD2(reshape, void(int width, int height));
709 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum type, WGC3Dintptr offset));
710
711 virtual WebString getString(WebKit::WGC3Denum name)
712 {
713 if (name == GL_EXTENSIONS)
714 return WebString("GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_ba ckbuffer");
715 return WebString();
716 }
717 };
718
719 class MockOutputSurface : public OutputSurface {
720 public:
721 MockOutputSurface()
722 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(new StrictMock< OutputSurfaceMockContext>)) { }
723 virtual ~MockOutputSurface() { }
724
725 MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame));
726 MOCK_METHOD0(EnsureBackbuffer, void());
727 MOCK_METHOD0(DiscardBackbuffer, void());
728 MOCK_METHOD1(Reshape, void(gfx::Size size));
729 MOCK_METHOD0(BindFramebuffer, void());
730 MOCK_METHOD1(PostSubBuffer, void(gfx::Rect rect));
731 MOCK_METHOD0(SwapBuffers, void());
732 };
733
734 class MockOutputSurfaceTest : public testing::Test,
735 public FakeRendererClient {
736 protected:
737 MockOutputSurfaceTest()
738 : m_resourceProvider(ResourceProvider::create(&m_outputSurface))
739 , m_renderer(this, &m_outputSurface, m_resourceProvider.get())
740 {
741 }
742
743 virtual void SetUp()
744 {
745 EXPECT_TRUE(m_renderer.initialize());
746 }
747
748 void swapBuffers()
749 {
750 m_renderer.swapBuffers();
751 }
752
753 void drawFrame()
754 {
755 gfx::Rect viewportRect(deviceViewportSize());
756 ScopedPtrVector<RenderPass>& renderPasses = renderPassesInDrawOrder();
757 renderPasses.clear();
758
759 RenderPass::Id renderPassId(1, 0);
760 TestRenderPass* renderPass = addRenderPass(renderPasses, renderPassId, v iewportRect, gfx::Transform());
761 addQuad(renderPass, viewportRect, SK_ColorGREEN);
762
763 EXPECT_CALL(m_outputSurface, EnsureBackbuffer())
764 .WillRepeatedly(Return());
765
766 EXPECT_CALL(m_outputSurface, Reshape(_))
767 .Times(1);
768
769 EXPECT_CALL(m_outputSurface, BindFramebuffer())
770 .Times(1);
771
772 EXPECT_CALL(*context(), drawElements(_, _, _, _))
773 .Times(1);
774
775 m_renderer.decideRenderPassAllocationsForFrame(renderPassesInDrawOrder() );
776 m_renderer.drawFrame(renderPassesInDrawOrder());
777 }
778
779 OutputSurfaceMockContext* context() { return static_cast<OutputSurfaceMockCo ntext*>(m_outputSurface.context3d()); }
780
781 StrictMock<MockOutputSurface> m_outputSurface;
782 scoped_ptr<ResourceProvider> m_resourceProvider;
783 FakeRendererGL m_renderer;
784 };
785
786 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap)
787 {
788 drawFrame();
789
790 EXPECT_CALL(m_outputSurface, SwapBuffers())
791 .Times(1);
792 m_renderer.swapBuffers();
793 }
794
795 class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest {
796 public:
797 virtual const LayerTreeSettings& settings() const OVERRIDE
798 {
799 static LayerTreeSettings fakeSettings;
800 fakeSettings.partialSwapEnabled = true;
801 return fakeSettings;
802 }
803 };
804
805 TEST_F(MockOutputSurfaceTestWithPartialSwap, DrawFrameAndSwap)
806 {
807 drawFrame();
808
809 EXPECT_CALL(m_outputSurface, PostSubBuffer(_))
810 .Times(1);
811 m_renderer.swapBuffers();
812 }
813
814 class MockOutputSurfaceTestWithSendCompositorFrame : public MockOutputSurfaceTes t {
815 public:
816 virtual const LayerTreeSettings& settings() const OVERRIDE
817 {
818 static LayerTreeSettings fakeSettings;
819 fakeSettings.compositorFrameMessage = true;
820 return fakeSettings;
821 }
822 };
823
824 TEST_F(MockOutputSurfaceTestWithSendCompositorFrame, DrawFrame)
825 {
826 EXPECT_CALL(m_outputSurface, SendFrameToParentCompositor(_))
827 .Times(1);
828 drawFrame();
829 }
830
697 } // namespace 831 } // namespace
698 } // namespace cc 832 } // namespace cc
OLDNEW
« no previous file with comments | « cc/gl_renderer.cc ('k') | cc/layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698