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

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

Issue 23548022: [cc] Evict UIResources when the renderer is not visible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 3 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/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.cc » ('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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "cc/debug/test_context_provider.h" 8 #include "cc/debug/test_context_provider.h"
9 #include "cc/debug/test_web_graphics_context_3d.h" 9 #include "cc/debug/test_web_graphics_context_3d.h"
10 #include "cc/layers/content_layer.h" 10 #include "cc/layers/content_layer.h"
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 // backtrack). 1728 // backtrack).
1729 EXPECT_EQ(1, scrollbar_layer_->update_count()); 1729 EXPECT_EQ(1, scrollbar_layer_->update_count());
1730 LoseContext(); 1730 LoseContext();
1731 break; 1731 break;
1732 case 2: 1732 case 2:
1733 // Second update, after the lost context, we should still upload 2 1733 // Second update, after the lost context, we should still upload 2
1734 // resources even if the contents haven't changed. 1734 // resources even if the contents haven't changed.
1735 EXPECT_EQ(2, scrollbar_layer_->update_count()); 1735 EXPECT_EQ(2, scrollbar_layer_->update_count());
1736 EndTest(); 1736 EndTest();
1737 break; 1737 break;
1738 case 3:
1739 // Single thread proxy issues extra commits after context lost.
1740 // http://crbug.com/287250
1741 if (HasImplThread())
1742 NOTREACHED();
1743 break;
1738 default: 1744 default:
1739 NOTREACHED(); 1745 NOTREACHED();
1740 } 1746 }
1741 } 1747 }
1742 1748
1743 private: 1749 private:
1744 int commits_; 1750 int commits_;
1745 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; 1751 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
1746 }; 1752 };
1747 1753
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 // Expects a valid UIResourceId. 1910 // Expects a valid UIResourceId.
1905 EXPECT_NE(0, ui_resource_->id()); 1911 EXPECT_NE(0, ui_resource_->id());
1906 PostSetNeedsCommitToMainThread(); 1912 PostSetNeedsCommitToMainThread();
1907 break; 1913 break;
1908 case 4: 1914 case 4:
1909 // Release resource before ending the test. 1915 // Release resource before ending the test.
1910 ui_resource_.reset(); 1916 ui_resource_.reset();
1911 EndTest(); 1917 EndTest();
1912 break; 1918 break;
1913 case 5: 1919 case 5:
1914 // Make sure no extra commits happened. 1920 // Single thread proxy issues extra commits after context lost.
1921 // http://crbug.com/287250
1922 if (HasImplThread())
1923 NOTREACHED();
1924 break;
1925 case 6:
1915 NOTREACHED(); 1926 NOTREACHED();
1916 } 1927 }
1917 } 1928 }
1918 1929
1919 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 1930 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
1920 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1931 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1921 switch (time_step_) { 1932 switch (time_step_) {
1922 case 1: 1933 case 1:
1923 // The resource should have been created on LTHI after the commit. 1934 // The resource should have been created on LTHI after the commit.
1924 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); 1935 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 case 8: 2021 case 8:
2011 NOTREACHED(); 2022 NOTREACHED();
2012 } 2023 }
2013 } 2024 }
2014 2025
2015 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 2026 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
2016 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 2027 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
2017 switch (time_step_) { 2028 switch (time_step_) {
2018 case 1: 2029 case 1:
2019 // Sequence 1 (continued): 2030 // Sequence 1 (continued):
2020 if (HasImplThread()) { 2031 // The first context lost happens before the resources were created,
2021 // The resources should have been recreated. 2032 // and because it resulted in no resources being destroyed, it does not
2022 EXPECT_EQ(2, ui_resource_->resource_create_count); 2033 // trigger resource re-creation.
2023 // The "resource lost" callback was called once for the resource in 2034 EXPECT_EQ(1, ui_resource_->resource_create_count);
2024 // the resource map. 2035 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2025 EXPECT_EQ(1, ui_resource_->lost_resource_count); 2036 // Resource Id on the impl-side has been created.
2026 } else {
2027 // The extra commit that happens at context lost in the single thread
2028 // proxy changes the timing so that the resource recreation callback
2029 // is skipped.
2030 // http://crbug.com/287250
2031 EXPECT_EQ(1, ui_resource_->resource_create_count);
2032 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2033 }
2034 // Resource Id on the impl-side have been recreated as well. Note
2035 // that the same UIResourceId persists after the context lost.
2036 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2037 PostSetNeedsCommitToMainThread(); 2037 PostSetNeedsCommitToMainThread();
2038 break; 2038 break;
2039 case 3: 2039 case 3:
2040 // Sequence 2 (continued): 2040 // Sequence 2 (continued):
2041 // The previous resource should have been deleted. 2041 // The previous resource should have been deleted.
2042 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); 2042 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
2043 // The second resource should have been created.
2044 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
2045 if (HasImplThread()) { 2043 if (HasImplThread()) {
2046 // The second resource called the resource callback once and since the 2044 // The second resource should have been created.
2047 // context is lost, a "resource lost" callback was also issued. 2045 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
2048 EXPECT_EQ(2, ui_resource_->resource_create_count);
2049 EXPECT_EQ(1, ui_resource_->lost_resource_count);
2050 } else { 2046 } else {
2051 // The extra commit that happens at context lost in the single thread 2047 // The extra commit that happens at context lost in the single thread
2052 // proxy changes the timing so that the resource recreation callback 2048 // proxy changes the timing so that the resource has been destroyed.
2053 // is skipped.
2054 // http://crbug.com/287250 2049 // http://crbug.com/287250
2055 EXPECT_EQ(1, ui_resource_->resource_create_count); 2050 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id1_));
2056 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2057 } 2051 }
2052 // The second resource called the resource callback once and since the
2053 // context is lost, a "resource lost" callback was also issued.
2054 EXPECT_EQ(2, ui_resource_->resource_create_count);
2055 EXPECT_EQ(1, ui_resource_->lost_resource_count);
2058 break; 2056 break;
2059 case 5: 2057 case 5:
2060 // Sequence 3 (continued): 2058 // Sequence 3 (continued):
2061 // Expect the resource callback to have been called once. 2059 // Expect the resource callback to have been called once.
2062 EXPECT_EQ(1, ui_resource_->resource_create_count); 2060 EXPECT_EQ(1, ui_resource_->resource_create_count);
2063 // No "resource lost" callbacks. 2061 // No "resource lost" callbacks.
2064 EXPECT_EQ(0, ui_resource_->lost_resource_count); 2062 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2065 // The UI resource id should not be valid 2063 // The UI resource id should not be valid
2066 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); 2064 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
2067 break; 2065 break;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2159 TEST_F(UIResourceLostBeforeActivateTree, 2157 TEST_F(UIResourceLostBeforeActivateTree,
2160 RunMultiThread_DirectRenderer_ImplSidePaint) { 2158 RunMultiThread_DirectRenderer_ImplSidePaint) {
2161 RunTest(true, false, true); 2159 RunTest(true, false, true);
2162 } 2160 }
2163 2161
2164 TEST_F(UIResourceLostBeforeActivateTree, 2162 TEST_F(UIResourceLostBeforeActivateTree,
2165 RunMultiThread_DelegatingRenderer_ImplSidePaint) { 2163 RunMultiThread_DelegatingRenderer_ImplSidePaint) {
2166 RunTest(true, true, true); 2164 RunTest(true, true, true);
2167 } 2165 }
2168 2166
2167 // Resources evicted explicitly and by visibility changes.
2168 class UIResourceLostEviction : public UIResourceLostTestSimple {
2169 public:
2170 virtual void StepCompleteOnMainThread(int step) OVERRIDE {
2171 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
2172 switch (step) {
2173 case 0:
2174 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host());
2175 EXPECT_NE(0, ui_resource_->id());
2176 PostSetNeedsCommitToMainThread();
2177 break;
2178 case 2:
2179 // Make the tree not visible.
2180 PostSetVisibleToMainThread(false);
2181 break;
2182 case 3:
2183 // Release resource before ending the test.
2184 ui_resource_.reset();
2185 EndTest();
2186 break;
2187 case 4:
2188 NOTREACHED();
2189 }
2190 }
2191
2192 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl,
2193 bool visible) OVERRIDE {
2194 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
2195 impl->output_surface()->context_provider()->Context3d());
2196 if (!visible) {
2197 // All resources should have been evicted.
2198 ASSERT_EQ(0u, context->NumTextures());
2199 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2200 EXPECT_EQ(2, ui_resource_->resource_create_count);
2201 EXPECT_EQ(1, ui_resource_->lost_resource_count);
2202 // Drawing is disabled both because of the evicted resources and
2203 // because the renderer is not visible.
2204 EXPECT_FALSE(impl->CanDraw());
2205 // Make the renderer visible again.
2206 PostSetVisibleToMainThread(true);
2207 }
2208 }
2209
2210 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
2211 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
2212 impl->output_surface()->context_provider()->Context3d());
2213 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
2214 switch (time_step_) {
2215 case 1:
2216 // The resource should have been created on LTHI after the commit.
2217 ASSERT_EQ(1u, context->NumTextures());
2218 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2219 EXPECT_EQ(1, ui_resource_->resource_create_count);
2220 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2221 EXPECT_TRUE(impl->CanDraw());
2222 // Evict all UI resources. This will trigger a commit.
2223 impl->EvictAllUIResources();
2224 ASSERT_EQ(0u, context->NumTextures());
2225 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2226 EXPECT_EQ(1, ui_resource_->resource_create_count);
2227 EXPECT_EQ(0, ui_resource_->lost_resource_count);
2228 EXPECT_FALSE(impl->CanDraw());
2229 break;
2230 case 2:
2231 // The resource should have been recreated.
2232 ASSERT_EQ(1u, context->NumTextures());
2233 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2234 EXPECT_EQ(2, ui_resource_->resource_create_count);
2235 EXPECT_EQ(1, ui_resource_->lost_resource_count);
2236 EXPECT_TRUE(impl->CanDraw());
2237 break;
2238 case 3:
2239 // The resource should have been recreated after visibility was
2240 // restored.
2241 ASSERT_EQ(1u, context->NumTextures());
2242 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
2243 EXPECT_EQ(3, ui_resource_->resource_create_count);
2244 EXPECT_EQ(2, ui_resource_->lost_resource_count);
2245 EXPECT_TRUE(impl->CanDraw());
2246 break;
2247 }
2248 }
2249 };
2250
2251 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction);
2252
2169 } // namespace 2253 } // namespace
2170 } // namespace cc 2254 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698