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

Side by Side Diff: cc/trees/layer_tree_host_unittest_delegated.cc

Issue 139053002: cc: Release main thread earlier (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: old chunk mismatch Created 6 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 EXPECT_EQ(1u, delegated_impl->Resources().count(555)); 1849 EXPECT_EQ(1u, delegated_impl->Resources().count(555));
1850 } 1850 }
1851 } 1851 }
1852 }; 1852 };
1853 1853
1854 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake); 1854 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDelegatedTestCommitWithoutTake);
1855 1855
1856 class DelegatedFrameIsActivatedDuringCommit 1856 class DelegatedFrameIsActivatedDuringCommit
1857 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { 1857 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1858 protected: 1858 protected:
1859 DelegatedFrameIsActivatedDuringCommit() 1859 DelegatedFrameIsActivatedDuringCommit() : returned_resource_count_(0) {}
1860 : wait_thread_("WAIT"),
1861 wait_event_(false, false),
1862 returned_resource_count_(0) {
1863 wait_thread_.Start();
1864 }
1865 1860
1866 virtual void BeginTest() OVERRIDE { 1861 virtual void BeginTest() OVERRIDE {
1867 activate_count_ = 0; 1862 activate_count_ = 0;
1868 1863
1869 scoped_ptr<DelegatedFrameData> frame = 1864 scoped_ptr<DelegatedFrameData> frame =
1870 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1865 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1871 AddTextureQuad(frame.get(), 999); 1866 AddTextureQuad(frame.get(), 999);
1872 AddTransferableResource(frame.get(), 999); 1867 AddTransferableResource(frame.get(), 999);
1873 SetFrameData(frame.Pass()); 1868 SetFrameData(frame.Pass());
1874 1869
1875 PostSetNeedsCommitToMainThread(); 1870 PostSetNeedsCommitToMainThread();
1876 } 1871 }
1877 1872
1878 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1873 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1879 // Slow down activation so the main thread DidCommit() will run if
1880 // not blocked.
1881 wait_thread_.message_loop()->PostDelayedTask(
1882 FROM_HERE,
1883 base::Bind(&base::WaitableEvent::Signal,
1884 base::Unretained(&wait_event_)),
1885 base::TimeDelta::FromMilliseconds(10));
1886 wait_event_.Wait();
1887
1888 base::AutoLock lock(activate_lock_);
1889 ++activate_count_; 1874 ++activate_count_;
1890 } 1875 }
1891 1876
1892 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1877 virtual void DidCommit() OVERRIDE {
1893 // The main thread is awake now, and will run DidCommit() immediately. 1878 switch (layer_tree_host()->source_frame_number()) {
1894 // Run DidActivate() afterwards by posting it now.
1895 proxy()->MainThreadTaskRunner()->PostTask(
1896 FROM_HERE,
1897 base::Bind(&DelegatedFrameIsActivatedDuringCommit::DidActivate,
1898 base::Unretained(this)));
1899 }
1900
1901 void DidActivate() {
1902 base::AutoLock lock(activate_lock_);
1903 switch (activate_count_) {
1904 case 1: { 1879 case 1: {
1905 // The first frame has been activated. Set a new frame, and 1880 // The first frame has been activated. Set a new frame, and
1906 // expect the next commit to finish *after* it is activated. 1881 // expect the next commit to finish *after* it is activated.
1907 scoped_ptr<DelegatedFrameData> frame = 1882 scoped_ptr<DelegatedFrameData> frame =
1908 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)); 1883 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1909 AddTextureQuad(frame.get(), 555); 1884 AddTextureQuad(frame.get(), 555);
1910 AddTransferableResource(frame.get(), 555); 1885 AddTransferableResource(frame.get(), 555);
1911 SetFrameData(frame.Pass()); 1886 SetFrameData(frame.Pass());
1912 // So this commit number should complete after the second activate.
1913 EXPECT_EQ(1, layer_tree_host()->source_frame_number());
1914 break; 1887 break;
1915 } 1888 }
1916 case 2: 1889 case 2:
1917 // The second frame has been activated. Remove the layer from 1890 // The second frame has been activated. Remove the layer from
1918 // the tree to cause another commit/activation. The commit should 1891 // the tree to cause another commit/activation. The commit should
1919 // finish *after* the layer is removed from the active tree. 1892 // finish *after* the layer is removed from the active tree.
1920 delegated_->RemoveFromParent(); 1893 delegated_->RemoveFromParent();
1921 // So this commit number should complete after the third activate. 1894 break;
1922 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); 1895 case 3:
1896 scoped_ptr<DelegatedFrameData> frame =
1897 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1898 SetFrameData(frame.Pass());
brianderson 2014/01/15 00:59:38 What is this extra case needed for?
enne (OOO) 2014/01/15 01:21:49 This is needed to kick off the UnusedResourcesAreA
1923 break; 1899 break;
1924 } 1900 }
1925 } 1901 }
1926 1902
1927 virtual void DidCommit() OVERRIDE { 1903 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
enne (OOO) 2014/01/15 00:36:04 Main thread DidCommit is now racy with respect to
1928 switch (layer_tree_host()->source_frame_number()) { 1904 switch (host_impl->active_tree()->source_frame_number()) {
1929 case 2: { 1905 case 2: {
1930 // The activate for the 2nd frame should have happened before now. 1906 // The activate for the 2nd frame should have happened before now.
1931 base::AutoLock lock(activate_lock_);
1932 EXPECT_EQ(2, activate_count_); 1907 EXPECT_EQ(2, activate_count_);
1933 break; 1908 break;
1934 } 1909 }
1935 case 3: { 1910 case 3: {
1936 // The activate to remove the layer should have happened before now. 1911 // The activate to remove the layer should have happened before now.
1937 base::AutoLock lock(activate_lock_);
1938 EXPECT_EQ(3, activate_count_); 1912 EXPECT_EQ(3, activate_count_);
1939
1940 scoped_ptr<DelegatedFrameData> frame =
1941 CreateFrameData(gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1));
1942 SetFrameData(frame.Pass());
1943 break; 1913 break;
1944 } 1914 }
1945 } 1915 }
1946 } 1916 }
1947 1917
1948 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, 1918 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl,
1949 bool result) OVERRIDE { 1919 bool result) OVERRIDE {
1950 ReturnUnusedResourcesFromParent(host_impl); 1920 ReturnUnusedResourcesFromParent(host_impl);
1951 } 1921 }
1952 1922
1953 virtual void UnusedResourcesAreAvailable() OVERRIDE { 1923 virtual void UnusedResourcesAreAvailable() OVERRIDE {
1954 LayerTreeHostDelegatedTestCaseSingleDelegatedLayer:: 1924 LayerTreeHostDelegatedTestCaseSingleDelegatedLayer::
1955 UnusedResourcesAreAvailable(); 1925 UnusedResourcesAreAvailable();
1956 ReturnedResourceArray resources; 1926 ReturnedResourceArray resources;
1957 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources); 1927 resource_collection_->TakeUnusedResourcesForChildCompositor(&resources);
1958 EXPECT_TRUE(TestAndResetAvailable()); 1928 EXPECT_TRUE(TestAndResetAvailable());
1959 returned_resource_count_ += resources.size(); 1929 returned_resource_count_ += resources.size();
1960 if (returned_resource_count_ == 2) 1930 if (returned_resource_count_ == 2)
1961 EndTest(); 1931 EndTest();
1962 } 1932 }
1963 1933
1964 base::Thread wait_thread_;
1965 base::WaitableEvent wait_event_;
1966 base::Lock activate_lock_;
1967 int activate_count_; 1934 int activate_count_;
1968 size_t returned_resource_count_; 1935 size_t returned_resource_count_;
1969 }; 1936 };
1970 1937
1971 SINGLE_AND_MULTI_THREAD_TEST_F( 1938 SINGLE_AND_MULTI_THREAD_TEST_F(
1972 DelegatedFrameIsActivatedDuringCommit); 1939 DelegatedFrameIsActivatedDuringCommit);
1973 1940
1974 class LayerTreeHostDelegatedTestTwoImplLayers 1941 class LayerTreeHostDelegatedTestTwoImplLayers
1975 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer { 1942 : public LayerTreeHostDelegatedTestCaseSingleDelegatedLayer {
1976 public: 1943 public:
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2326 }
2360 2327
2361 scoped_refptr<DelegatedRendererLayer> delegated_thief_; 2328 scoped_refptr<DelegatedRendererLayer> delegated_thief_;
2362 }; 2329 };
2363 2330
2364 SINGLE_AND_MULTI_THREAD_TEST_F( 2331 SINGLE_AND_MULTI_THREAD_TEST_F(
2365 LayerTreeHostDelegatedTestRemoveAndChangeResources); 2332 LayerTreeHostDelegatedTestRemoveAndChangeResources);
2366 2333
2367 } // namespace 2334 } // namespace
2368 } // namespace cc 2335 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698