Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
| 12 #include "cc/base/swap_promise.h" | 12 #include "cc/base/swap_promise.h" |
| 13 #include "cc/debug/frame_rate_counter.h" | 13 #include "cc/debug/frame_rate_counter.h" |
| 14 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
| 15 #include "cc/layers/content_layer_client.h" | 15 #include "cc/layers/content_layer_client.h" |
| 16 #include "cc/layers/io_surface_layer.h" | 16 #include "cc/layers/io_surface_layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/layers/painted_scrollbar_layer.h" | 18 #include "cc/layers/painted_scrollbar_layer.h" |
| 19 #include "cc/layers/picture_layer.h" | 19 #include "cc/layers/picture_layer.h" |
| 20 #include "cc/layers/solid_color_layer.h" | 20 #include "cc/layers/solid_color_layer.h" |
| 21 #include "cc/layers/video_layer.h" | 21 #include "cc/layers/video_layer.h" |
| 22 #include "cc/output/begin_frame_args.h" | 22 #include "cc/output/begin_frame_args.h" |
| 23 #include "cc/output/compositor_frame_ack.h" | |
| 23 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
| 24 #include "cc/output/copy_output_result.h" | 25 #include "cc/output/copy_output_result.h" |
| 25 #include "cc/output/output_surface.h" | 26 #include "cc/output/output_surface.h" |
| 26 #include "cc/quads/draw_quad.h" | 27 #include "cc/quads/draw_quad.h" |
| 27 #include "cc/quads/io_surface_draw_quad.h" | 28 #include "cc/quads/io_surface_draw_quad.h" |
| 28 #include "cc/resources/prioritized_resource.h" | 29 #include "cc/resources/prioritized_resource.h" |
| 29 #include "cc/resources/prioritized_resource_manager.h" | 30 #include "cc/resources/prioritized_resource_manager.h" |
| 30 #include "cc/resources/resource_update_queue.h" | 31 #include "cc/resources/resource_update_queue.h" |
| 31 #include "cc/test/fake_content_layer.h" | 32 #include "cc/test/fake_content_layer.h" |
| 32 #include "cc/test/fake_content_layer_client.h" | 33 #include "cc/test/fake_content_layer_client.h" |
| (...skipping 2721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2754 did_release_gl_ = false; | 2755 did_release_gl_ = false; |
| 2755 last_source_frame_number_drawn_ = -1; // Never drawn. | 2756 last_source_frame_number_drawn_ = -1; // Never drawn. |
| 2756 PostSetNeedsCommitToMainThread(); | 2757 PostSetNeedsCommitToMainThread(); |
| 2757 } | 2758 } |
| 2758 | 2759 |
| 2759 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 2760 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
| 2760 OVERRIDE { | 2761 OVERRIDE { |
| 2761 scoped_ptr<TestWebGraphicsContext3D> context3d( | 2762 scoped_ptr<TestWebGraphicsContext3D> context3d( |
| 2762 TestWebGraphicsContext3D::Create()); | 2763 TestWebGraphicsContext3D::Create()); |
| 2763 | 2764 |
| 2764 return FakeOutputSurface::CreateDeferredGL( | 2765 scoped_ptr<FakeOutputSurface> output_surface = |
| 2765 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)); | 2766 FakeOutputSurface::CreateDeferredGL( |
| 2767 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), | |
| 2768 delegating_renderer()); | |
| 2769 output_surface->set_forced_draw_to_software_device(true); | |
|
danakj
2014/05/16 22:08:47
Why are these set calls needed/correct?
boliu
2014/05/16 22:15:10
To avoid failing this DCHECK in GetDrawMode: https
danakj
2014/05/16 22:19:29
We should update this DCHECK then, to allow this w
boliu
2014/05/16 22:34:37
Relaxed DCHECK to allow deferred_gl too. It should
| |
| 2770 return output_surface.Pass(); | |
| 2766 } | 2771 } |
| 2767 | 2772 |
| 2768 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2773 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 2769 ASSERT_TRUE(host_impl->RootLayer()); | 2774 ASSERT_TRUE(host_impl->RootLayer()); |
| 2770 FakePictureLayerImpl* layer_impl = | 2775 FakePictureLayerImpl* layer_impl = |
| 2771 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); | 2776 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); |
| 2772 | 2777 |
| 2773 // The same frame can be draw multiple times if new visible tiles are | 2778 // The same frame can be draw multiple times if new visible tiles are |
| 2774 // rasterized. But we want to make sure we only post DeferredInitialize | 2779 // rasterized. But we want to make sure we only post DeferredInitialize |
| 2775 // and ReleaseGL once, so early out if the same frame is drawn again. | 2780 // and ReleaseGL once, so early out if the same frame is drawn again. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2803 | 2808 |
| 2804 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { | 2809 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { |
| 2805 EXPECT_FALSE(did_initialize_gl_); | 2810 EXPECT_FALSE(did_initialize_gl_); |
| 2806 // SetAndInitializeContext3D calls SetNeedsCommit. | 2811 // SetAndInitializeContext3D calls SetNeedsCommit. |
| 2807 FakeOutputSurface* fake_output_surface = | 2812 FakeOutputSurface* fake_output_surface = |
| 2808 static_cast<FakeOutputSurface*>(host_impl->output_surface()); | 2813 static_cast<FakeOutputSurface*>(host_impl->output_surface()); |
| 2809 scoped_refptr<TestContextProvider> context_provider = | 2814 scoped_refptr<TestContextProvider> context_provider = |
| 2810 TestContextProvider::Create(); // Not bound to thread. | 2815 TestContextProvider::Create(); // Not bound to thread. |
| 2811 EXPECT_TRUE( | 2816 EXPECT_TRUE( |
| 2812 fake_output_surface->InitializeAndSetContext3d(context_provider)); | 2817 fake_output_surface->InitializeAndSetContext3d(context_provider)); |
| 2818 fake_output_surface->set_forced_draw_to_software_device(false); | |
| 2813 did_initialize_gl_ = true; | 2819 did_initialize_gl_ = true; |
| 2814 } | 2820 } |
| 2815 | 2821 |
| 2816 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { | 2822 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { |
| 2817 EXPECT_TRUE(did_initialize_gl_); | 2823 EXPECT_TRUE(did_initialize_gl_); |
| 2818 EXPECT_FALSE(did_release_gl_); | 2824 EXPECT_FALSE(did_release_gl_); |
| 2819 // ReleaseGL calls SetNeedsCommit. | 2825 // ReleaseGL calls SetNeedsCommit. |
| 2820 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); | 2826 FakeOutputSurface* output_surface = |
| 2827 static_cast<FakeOutputSurface*>(host_impl->output_surface()); | |
| 2828 output_surface->ReleaseGL(); | |
| 2829 output_surface->set_forced_draw_to_software_device(true); | |
| 2821 did_release_gl_ = true; | 2830 did_release_gl_ = true; |
| 2822 } | 2831 } |
| 2823 | 2832 |
| 2833 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | |
| 2834 bool result) OVERRIDE { | |
| 2835 ASSERT_TRUE(result); | |
| 2836 DelegatedFrameData* delegated_frame_data = | |
| 2837 output_surface()->last_sent_frame().delegated_frame_data.get(); | |
| 2838 if (!delegated_frame_data) | |
| 2839 return; | |
| 2840 | |
| 2841 // Return all resources immediately. | |
| 2842 TransferableResourceArray resources_to_return = | |
| 2843 output_surface()->resources_held_by_parent(); | |
| 2844 | |
| 2845 CompositorFrameAck ack; | |
| 2846 for (size_t i = 0; i < resources_to_return.size(); ++i) | |
| 2847 output_surface()->ReturnResource(resources_to_return[i].id, &ack); | |
| 2848 host_impl->ReclaimResources(&ack); | |
| 2849 } | |
| 2850 | |
| 2824 virtual void AfterTest() OVERRIDE { | 2851 virtual void AfterTest() OVERRIDE { |
| 2825 EXPECT_TRUE(did_initialize_gl_); | 2852 EXPECT_TRUE(did_initialize_gl_); |
| 2826 EXPECT_TRUE(did_release_gl_); | 2853 EXPECT_TRUE(did_release_gl_); |
| 2827 } | 2854 } |
| 2828 | 2855 |
| 2829 private: | 2856 private: |
| 2830 FakeContentLayerClient client_; | 2857 FakeContentLayerClient client_; |
| 2831 scoped_refptr<FakePictureLayer> layer_; | 2858 scoped_refptr<FakePictureLayer> layer_; |
| 2832 bool did_initialize_gl_; | 2859 bool did_initialize_gl_; |
| 2833 bool did_release_gl_; | 2860 bool did_release_gl_; |
| 2834 int last_source_frame_number_drawn_; | 2861 int last_source_frame_number_drawn_; |
| 2835 }; | 2862 }; |
| 2836 | 2863 |
| 2837 MULTI_THREAD_DIRECT_RENDERER_TEST_F(LayerTreeHostTestDeferredInitialize); | 2864 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
| 2838 | 2865 |
| 2839 // Test for UI Resource management. | 2866 // Test for UI Resource management. |
| 2840 class LayerTreeHostTestUIResource : public LayerTreeHostTest { | 2867 class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
| 2841 public: | 2868 public: |
| 2842 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} | 2869 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} |
| 2843 | 2870 |
| 2844 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2871 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 2845 settings->texture_id_allocation_chunk_size = 1; | 2872 settings->texture_id_allocation_chunk_size = 1; |
| 2846 } | 2873 } |
| 2847 | 2874 |
| (...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4934 const gfx::Size bounds_; | 4961 const gfx::Size bounds_; |
| 4935 FakeContentLayerClient client_; | 4962 FakeContentLayerClient client_; |
| 4936 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 4963 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
| 4937 scoped_refptr<FakePictureLayer> picture_layer_; | 4964 scoped_refptr<FakePictureLayer> picture_layer_; |
| 4938 Layer* child_layer_; | 4965 Layer* child_layer_; |
| 4939 }; | 4966 }; |
| 4940 | 4967 |
| 4941 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 4968 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
| 4942 | 4969 |
| 4943 } // namespace cc | 4970 } // namespace cc |
| OLD | NEW |