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 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 return FakeOutputSurface::CreateDeferredGL( |
2765 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)); | 2766 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), |
| 2767 delegating_renderer()); |
2766 } | 2768 } |
2767 | 2769 |
2768 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2770 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
2769 ASSERT_TRUE(host_impl->RootLayer()); | 2771 ASSERT_TRUE(host_impl->RootLayer()); |
2770 FakePictureLayerImpl* layer_impl = | 2772 FakePictureLayerImpl* layer_impl = |
2771 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); | 2773 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); |
2772 | 2774 |
2773 // The same frame can be draw multiple times if new visible tiles are | 2775 // 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 | 2776 // 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. | 2777 // and ReleaseGL once, so early out if the same frame is drawn again. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 } | 2816 } |
2815 | 2817 |
2816 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { | 2818 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { |
2817 EXPECT_TRUE(did_initialize_gl_); | 2819 EXPECT_TRUE(did_initialize_gl_); |
2818 EXPECT_FALSE(did_release_gl_); | 2820 EXPECT_FALSE(did_release_gl_); |
2819 // ReleaseGL calls SetNeedsCommit. | 2821 // ReleaseGL calls SetNeedsCommit. |
2820 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); | 2822 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); |
2821 did_release_gl_ = true; | 2823 did_release_gl_ = true; |
2822 } | 2824 } |
2823 | 2825 |
| 2826 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| 2827 bool result) OVERRIDE { |
| 2828 ASSERT_TRUE(result); |
| 2829 DelegatedFrameData* delegated_frame_data = |
| 2830 output_surface()->last_sent_frame().delegated_frame_data.get(); |
| 2831 if (!delegated_frame_data) |
| 2832 return; |
| 2833 |
| 2834 // Return all resources immediately. |
| 2835 TransferableResourceArray resources_to_return = |
| 2836 output_surface()->resources_held_by_parent(); |
| 2837 |
| 2838 CompositorFrameAck ack; |
| 2839 for (size_t i = 0; i < resources_to_return.size(); ++i) |
| 2840 output_surface()->ReturnResource(resources_to_return[i].id, &ack); |
| 2841 host_impl->ReclaimResources(&ack); |
| 2842 } |
| 2843 |
2824 virtual void AfterTest() OVERRIDE { | 2844 virtual void AfterTest() OVERRIDE { |
2825 EXPECT_TRUE(did_initialize_gl_); | 2845 EXPECT_TRUE(did_initialize_gl_); |
2826 EXPECT_TRUE(did_release_gl_); | 2846 EXPECT_TRUE(did_release_gl_); |
2827 } | 2847 } |
2828 | 2848 |
2829 private: | 2849 private: |
2830 FakeContentLayerClient client_; | 2850 FakeContentLayerClient client_; |
2831 scoped_refptr<FakePictureLayer> layer_; | 2851 scoped_refptr<FakePictureLayer> layer_; |
2832 bool did_initialize_gl_; | 2852 bool did_initialize_gl_; |
2833 bool did_release_gl_; | 2853 bool did_release_gl_; |
2834 int last_source_frame_number_drawn_; | 2854 int last_source_frame_number_drawn_; |
2835 }; | 2855 }; |
2836 | 2856 |
2837 MULTI_THREAD_DIRECT_RENDERER_TEST_F(LayerTreeHostTestDeferredInitialize); | 2857 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
2838 | 2858 |
2839 // Test for UI Resource management. | 2859 // Test for UI Resource management. |
2840 class LayerTreeHostTestUIResource : public LayerTreeHostTest { | 2860 class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
2841 public: | 2861 public: |
2842 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} | 2862 LayerTreeHostTestUIResource() : num_ui_resources_(0) {} |
2843 | 2863 |
2844 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2864 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2845 settings->texture_id_allocation_chunk_size = 1; | 2865 settings->texture_id_allocation_chunk_size = 1; |
2846 } | 2866 } |
2847 | 2867 |
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4934 const gfx::Size bounds_; | 4954 const gfx::Size bounds_; |
4935 FakeContentLayerClient client_; | 4955 FakeContentLayerClient client_; |
4936 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 4956 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
4937 scoped_refptr<FakePictureLayer> picture_layer_; | 4957 scoped_refptr<FakePictureLayer> picture_layer_; |
4938 Layer* child_layer_; | 4958 Layer* child_layer_; |
4939 }; | 4959 }; |
4940 | 4960 |
4941 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 4961 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
4942 | 4962 |
4943 } // namespace cc | 4963 } // namespace cc |
OLD | NEW |