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/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 | 709 |
710 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks()); | 710 EXPECT_NE(first_frame_time_, impl->CurrentFrameTimeTicks()); |
711 EndTest(); | 711 EndTest(); |
712 } | 712 } |
713 | 713 |
714 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 714 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
715 // Ensure there isn't a commit between the two draws, to ensure that a | 715 // Ensure there isn't a commit between the two draws, to ensure that a |
716 // commit isn't required for updating the current frame time. We can | 716 // commit isn't required for updating the current frame time. We can |
717 // only check for this in the multi-threaded case, since in the single- | 717 // only check for this in the multi-threaded case, since in the single- |
718 // threaded case there will always be a commit between consecutive draws. | 718 // threaded case there will always be a commit between consecutive draws. |
719 if (ImplThread()) | 719 if (HasImplThread()) |
720 EXPECT_EQ(0, frame_); | 720 EXPECT_EQ(0, frame_); |
721 } | 721 } |
722 | 722 |
723 virtual void AfterTest() OVERRIDE {} | 723 virtual void AfterTest() OVERRIDE {} |
724 | 724 |
725 private: | 725 private: |
726 int frame_; | 726 int frame_; |
727 base::TimeTicks first_frame_time_; | 727 base::TimeTicks first_frame_time_; |
728 }; | 728 }; |
729 | 729 |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 identity_matrix, | 1617 identity_matrix, |
1618 gfx::PointF(0.f, 0.f), | 1618 gfx::PointF(0.f, 0.f), |
1619 gfx::PointF(0.f, 0.f), | 1619 gfx::PointF(0.f, 0.f), |
1620 gfx::Size(10, 20), | 1620 gfx::Size(10, 20), |
1621 true); | 1621 true); |
1622 | 1622 |
1623 PostSetNeedsCommitToMainThread(); | 1623 PostSetNeedsCommitToMainThread(); |
1624 } | 1624 } |
1625 | 1625 |
1626 void PostEvictTextures() { | 1626 void PostEvictTextures() { |
1627 DCHECK(ImplThread()); | 1627 DCHECK(HasImplThread()); |
1628 ImplThread()->PostTask( | 1628 ImplThreadTaskRunner()->PostTask( |
| 1629 FROM_HERE, |
1629 base::Bind(&LayerTreeHostTestEvictTextures::EvictTexturesOnImplThread, | 1630 base::Bind(&LayerTreeHostTestEvictTextures::EvictTexturesOnImplThread, |
1630 base::Unretained(this))); | 1631 base::Unretained(this))); |
1631 } | 1632 } |
1632 | 1633 |
1633 void EvictTexturesOnImplThread() { | 1634 void EvictTexturesOnImplThread() { |
1634 DCHECK(impl_for_evict_textures_); | 1635 DCHECK(impl_for_evict_textures_); |
1635 impl_for_evict_textures_->EnforceManagedMemoryPolicy( | 1636 impl_for_evict_textures_->EnforceManagedMemoryPolicy( |
1636 ManagedMemoryPolicy(0)); | 1637 ManagedMemoryPolicy(0)); |
1637 } | 1638 } |
1638 | 1639 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 proxy->SetLayerTreeHost(this); | 1872 proxy->SetLayerTreeHost(this); |
1872 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); | 1873 EXPECT_TRUE(InitializeForTesting(proxy.PassAs<Proxy>())); |
1873 } | 1874 } |
1874 }; | 1875 }; |
1875 | 1876 |
1876 TEST(LayerTreeHostTest, LimitPartialUpdates) { | 1877 TEST(LayerTreeHostTest, LimitPartialUpdates) { |
1877 // When partial updates are not allowed, max updates should be 0. | 1878 // When partial updates are not allowed, max updates should be 0. |
1878 { | 1879 { |
1879 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1880 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1880 | 1881 |
1881 scoped_ptr<FakeProxy> proxy = | 1882 scoped_ptr<FakeProxy> proxy(new FakeProxy); |
1882 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); | |
1883 proxy->GetRendererCapabilities().allow_partial_texture_updates = false; | 1883 proxy->GetRendererCapabilities().allow_partial_texture_updates = false; |
1884 proxy->SetMaxPartialTextureUpdates(5); | 1884 proxy->SetMaxPartialTextureUpdates(5); |
1885 | 1885 |
1886 LayerTreeSettings settings; | 1886 LayerTreeSettings settings; |
1887 settings.max_partial_texture_updates = 10; | 1887 settings.max_partial_texture_updates = 10; |
1888 | 1888 |
1889 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); | 1889 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); |
1890 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); | 1890 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); |
1891 | 1891 |
1892 EXPECT_EQ(0u, host.settings().max_partial_texture_updates); | 1892 EXPECT_EQ(0u, host.settings().max_partial_texture_updates); |
1893 } | 1893 } |
1894 | 1894 |
1895 // When partial updates are allowed, | 1895 // When partial updates are allowed, |
1896 // max updates should be limited by the proxy. | 1896 // max updates should be limited by the proxy. |
1897 { | 1897 { |
1898 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1898 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1899 | 1899 |
1900 scoped_ptr<FakeProxy> proxy = | 1900 scoped_ptr<FakeProxy> proxy(new FakeProxy); |
1901 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); | |
1902 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; | 1901 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; |
1903 proxy->SetMaxPartialTextureUpdates(5); | 1902 proxy->SetMaxPartialTextureUpdates(5); |
1904 | 1903 |
1905 LayerTreeSettings settings; | 1904 LayerTreeSettings settings; |
1906 settings.max_partial_texture_updates = 10; | 1905 settings.max_partial_texture_updates = 10; |
1907 | 1906 |
1908 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); | 1907 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); |
1909 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); | 1908 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); |
1910 | 1909 |
1911 EXPECT_EQ(5u, host.settings().max_partial_texture_updates); | 1910 EXPECT_EQ(5u, host.settings().max_partial_texture_updates); |
1912 } | 1911 } |
1913 | 1912 |
1914 // When partial updates are allowed, | 1913 // When partial updates are allowed, |
1915 // max updates should also be limited by the settings. | 1914 // max updates should also be limited by the settings. |
1916 { | 1915 { |
1917 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1916 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1918 | 1917 |
1919 scoped_ptr<FakeProxy> proxy = | 1918 scoped_ptr<FakeProxy> proxy(new FakeProxy); |
1920 make_scoped_ptr(new FakeProxy(scoped_ptr<Thread>())); | |
1921 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; | 1919 proxy->GetRendererCapabilities().allow_partial_texture_updates = true; |
1922 proxy->SetMaxPartialTextureUpdates(20); | 1920 proxy->SetMaxPartialTextureUpdates(20); |
1923 | 1921 |
1924 LayerTreeSettings settings; | 1922 LayerTreeSettings settings; |
1925 settings.max_partial_texture_updates = 10; | 1923 settings.max_partial_texture_updates = 10; |
1926 | 1924 |
1927 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); | 1925 LayerTreeHostWithProxy host(&client, settings, proxy.Pass()); |
1928 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); | 1926 EXPECT_TRUE(host.InitializeOutputSurfaceIfNeeded()); |
1929 | 1927 |
1930 EXPECT_EQ(10u, host.settings().max_partial_texture_updates); | 1928 EXPECT_EQ(10u, host.settings().max_partial_texture_updates); |
1931 } | 1929 } |
1932 } | 1930 } |
1933 | 1931 |
1934 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { | 1932 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { |
1935 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); | 1933 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
1936 | 1934 |
1937 LayerTreeSettings settings; | 1935 LayerTreeSettings settings; |
1938 settings.max_partial_texture_updates = 4; | 1936 settings.max_partial_texture_updates = 4; |
1939 | 1937 |
1940 scoped_ptr<LayerTreeHost> host = | 1938 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create( |
1941 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); | 1939 &client, |
| 1940 settings, |
| 1941 scoped_refptr<base::SingleThreadTaskRunner>()); |
1942 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); | 1942 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); |
1943 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | 1943 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
1944 } | 1944 } |
1945 | 1945 |
1946 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { | 1946 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { |
1947 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); | 1947 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); |
1948 | 1948 |
1949 LayerTreeSettings settings; | 1949 LayerTreeSettings settings; |
1950 settings.max_partial_texture_updates = 4; | 1950 settings.max_partial_texture_updates = 4; |
1951 | 1951 |
1952 scoped_ptr<LayerTreeHost> host = | 1952 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create( |
1953 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); | 1953 &client, |
| 1954 settings, |
| 1955 scoped_refptr<base::SingleThreadTaskRunner>()); |
1954 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); | 1956 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); |
1955 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); | 1957 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); |
1956 } | 1958 } |
1957 | 1959 |
1958 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { | 1960 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { |
1959 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); | 1961 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); |
1960 | 1962 |
1961 LayerTreeSettings settings; | 1963 LayerTreeSettings settings; |
1962 settings.max_partial_texture_updates = 4; | 1964 settings.max_partial_texture_updates = 4; |
1963 | 1965 |
1964 scoped_ptr<LayerTreeHost> host = | 1966 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create( |
1965 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); | 1967 &client, |
| 1968 settings, |
| 1969 scoped_refptr<base::SingleThreadTaskRunner>()); |
1966 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); | 1970 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); |
1967 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); | 1971 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); |
1968 } | 1972 } |
1969 | 1973 |
1970 TEST(LayerTreeHostTest, | 1974 TEST(LayerTreeHostTest, |
1971 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { | 1975 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { |
1972 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); | 1976 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); |
1973 | 1977 |
1974 LayerTreeSettings settings; | 1978 LayerTreeSettings settings; |
1975 settings.max_partial_texture_updates = 4; | 1979 settings.max_partial_texture_updates = 4; |
1976 | 1980 |
1977 scoped_ptr<LayerTreeHost> host = | 1981 scoped_ptr<LayerTreeHost> host = LayerTreeHost::Create( |
1978 LayerTreeHost::Create(&client, settings, scoped_ptr<Thread>()); | 1982 &client, |
| 1983 settings, |
| 1984 scoped_refptr<base::SingleThreadTaskRunner>()); |
1979 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); | 1985 EXPECT_TRUE(host->InitializeOutputSurfaceIfNeeded()); |
1980 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); | 1986 EXPECT_EQ(0u, host->settings().max_partial_texture_updates); |
1981 } | 1987 } |
1982 | 1988 |
1983 class LayerTreeHostTestCapturePicture : public LayerTreeHostTest { | 1989 class LayerTreeHostTestCapturePicture : public LayerTreeHostTest { |
1984 public: | 1990 public: |
1985 LayerTreeHostTestCapturePicture() | 1991 LayerTreeHostTestCapturePicture() |
1986 : bounds_(gfx::Size(100, 100)), | 1992 : bounds_(gfx::Size(100, 100)), |
1987 layer_(PictureLayer::Create(&content_client_)) {} | 1993 layer_(PictureLayer::Create(&content_client_)) {} |
1988 | 1994 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2260 FakeOutputSurface* fake_output_surface = | 2266 FakeOutputSurface* fake_output_surface = |
2261 reinterpret_cast<FakeOutputSurface*>(host_impl->output_surface()); | 2267 reinterpret_cast<FakeOutputSurface*>(host_impl->output_surface()); |
2262 | 2268 |
2263 // The BeginFrame notification is turned off now but will get | 2269 // The BeginFrame notification is turned off now but will get |
2264 // enabled once we return, so post a task to trigger it. | 2270 // enabled once we return, so post a task to trigger it. |
2265 ASSERT_FALSE(fake_output_surface->needs_begin_frame()); | 2271 ASSERT_FALSE(fake_output_surface->needs_begin_frame()); |
2266 PostBeginFrameOnImplThread(fake_output_surface); | 2272 PostBeginFrameOnImplThread(fake_output_surface); |
2267 } | 2273 } |
2268 | 2274 |
2269 void PostBeginFrameOnImplThread(FakeOutputSurface* fake_output_surface) { | 2275 void PostBeginFrameOnImplThread(FakeOutputSurface* fake_output_surface) { |
2270 DCHECK(ImplThread()); | 2276 DCHECK(HasImplThread()); |
2271 ImplThread()->PostTask( | 2277 ImplThreadTaskRunner()->PostTask( |
| 2278 FROM_HERE, |
2272 base::Bind(&LayerTreeHostTestBeginFrameNotification::BeginFrame, | 2279 base::Bind(&LayerTreeHostTestBeginFrameNotification::BeginFrame, |
2273 base::Unretained(this), | 2280 base::Unretained(this), |
2274 base::Unretained(fake_output_surface))); | 2281 base::Unretained(fake_output_surface))); |
2275 } | 2282 } |
2276 | 2283 |
2277 void BeginFrame(FakeOutputSurface* fake_output_surface) { | 2284 void BeginFrame(FakeOutputSurface* fake_output_surface) { |
2278 ASSERT_TRUE(fake_output_surface->needs_begin_frame()); | 2285 ASSERT_TRUE(fake_output_surface->needs_begin_frame()); |
2279 fake_output_surface->BeginFrame(frame_time_); | 2286 fake_output_surface->BeginFrame(frame_time_); |
2280 } | 2287 } |
2281 | 2288 |
(...skipping 19 matching lines...) Expand all Loading... |
2301 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2308 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2302 settings->begin_frame_scheduling_enabled = true; | 2309 settings->begin_frame_scheduling_enabled = true; |
2303 settings->using_synchronous_renderer_compositor = true; | 2310 settings->using_synchronous_renderer_compositor = true; |
2304 } | 2311 } |
2305 | 2312 |
2306 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 2313 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
2307 | 2314 |
2308 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2315 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
2309 // The BeginFrame notification is turned off now but will get enabled | 2316 // The BeginFrame notification is turned off now but will get enabled |
2310 // once we return. End test while it's enabled. | 2317 // once we return. End test while it's enabled. |
2311 ImplThread()->PostTask(base::Bind( | 2318 ImplThreadTaskRunner()->PostTask( |
2312 &LayerTreeHostTestBeginFrameNotification::EndTest, | 2319 FROM_HERE, |
2313 base::Unretained(this))); | 2320 base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest, |
| 2321 base::Unretained(this))); |
2314 } | 2322 } |
2315 | 2323 |
2316 virtual void AfterTest() OVERRIDE {} | 2324 virtual void AfterTest() OVERRIDE {} |
2317 }; | 2325 }; |
2318 | 2326 |
2319 MULTI_THREAD_TEST_F( | 2327 MULTI_THREAD_TEST_F( |
2320 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); | 2328 LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); |
2321 | 2329 |
2322 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation | 2330 class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation |
2323 : public LayerTreeHostTest { | 2331 : public LayerTreeHostTest { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2871 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) | 2879 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) |
2872 .PassAs<OutputSurface>(); | 2880 .PassAs<OutputSurface>(); |
2873 } | 2881 } |
2874 | 2882 |
2875 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 2883 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
2876 ASSERT_TRUE(host_impl->RootLayer()); | 2884 ASSERT_TRUE(host_impl->RootLayer()); |
2877 FakePictureLayerImpl* layer_impl = | 2885 FakePictureLayerImpl* layer_impl = |
2878 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); | 2886 static_cast<FakePictureLayerImpl*>(host_impl->RootLayer()); |
2879 if (!initialized_gl_) { | 2887 if (!initialized_gl_) { |
2880 EXPECT_EQ(1u, layer_impl->append_quads_count()); | 2888 EXPECT_EQ(1u, layer_impl->append_quads_count()); |
2881 ImplThread()->PostTask(base::Bind( | 2889 ImplThreadTaskRunner()->PostTask(FROM_HERE, base::Bind( |
2882 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw, | 2890 &LayerTreeHostTestDeferredInitialize::DeferredInitializeAndRedraw, |
2883 base::Unretained(this), | 2891 base::Unretained(this), |
2884 base::Unretained(host_impl))); | 2892 base::Unretained(host_impl))); |
2885 } else { | 2893 } else { |
2886 EXPECT_EQ(2u, layer_impl->append_quads_count()); | 2894 EXPECT_EQ(2u, layer_impl->append_quads_count()); |
2887 EndTest(); | 2895 EndTest(); |
2888 } | 2896 } |
2889 } | 2897 } |
2890 | 2898 |
2891 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { | 2899 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { |
(...skipping 12 matching lines...) Expand all Loading... |
2904 private: | 2912 private: |
2905 FakeContentLayerClient client_; | 2913 FakeContentLayerClient client_; |
2906 scoped_refptr<FakePictureLayer> layer_; | 2914 scoped_refptr<FakePictureLayer> layer_; |
2907 bool initialized_gl_; | 2915 bool initialized_gl_; |
2908 }; | 2916 }; |
2909 | 2917 |
2910 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); | 2918 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); |
2911 | 2919 |
2912 } // namespace | 2920 } // namespace |
2913 } // namespace cc | 2921 } // namespace cc |
OLD | NEW |