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

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

Issue 18191020: UI Resource Manager (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 5 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
OLDNEW
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 16 matching lines...) Expand all
27 #include "cc/test/fake_content_layer_client.h" 27 #include "cc/test/fake_content_layer_client.h"
28 #include "cc/test/fake_layer_tree_host_client.h" 28 #include "cc/test/fake_layer_tree_host_client.h"
29 #include "cc/test/fake_output_surface.h" 29 #include "cc/test/fake_output_surface.h"
30 #include "cc/test/fake_picture_layer.h" 30 #include "cc/test/fake_picture_layer.h"
31 #include "cc/test/fake_picture_layer_impl.h" 31 #include "cc/test/fake_picture_layer_impl.h"
32 #include "cc/test/fake_proxy.h" 32 #include "cc/test/fake_proxy.h"
33 #include "cc/test/fake_scrollbar_layer.h" 33 #include "cc/test/fake_scrollbar_layer.h"
34 #include "cc/test/geometry_test_utils.h" 34 #include "cc/test/geometry_test_utils.h"
35 #include "cc/test/layer_tree_test.h" 35 #include "cc/test/layer_tree_test.h"
36 #include "cc/test/occlusion_tracker_test_common.h" 36 #include "cc/test/occlusion_tracker_test_common.h"
37 #include "cc/test/test_ui_resource_client.h"
37 #include "cc/trees/layer_tree_host_impl.h" 38 #include "cc/trees/layer_tree_host_impl.h"
38 #include "cc/trees/layer_tree_impl.h" 39 #include "cc/trees/layer_tree_impl.h"
39 #include "cc/trees/single_thread_proxy.h" 40 #include "cc/trees/single_thread_proxy.h"
40 #include "cc/trees/thread_proxy.h" 41 #include "cc/trees/thread_proxy.h"
41 #include "gpu/GLES2/gl2extchromium.h" 42 #include "gpu/GLES2/gl2extchromium.h"
42 #include "skia/ext/refptr.h" 43 #include "skia/ext/refptr.h"
43 #include "testing/gmock/include/gmock/gmock.h" 44 #include "testing/gmock/include/gmock/gmock.h"
44 #include "third_party/khronos/GLES2/gl2.h" 45 #include "third_party/khronos/GLES2/gl2.h"
45 #include "third_party/khronos/GLES2/gl2ext.h" 46 #include "third_party/khronos/GLES2/gl2ext.h"
46 #include "third_party/skia/include/core/SkPicture.h" 47 #include "third_party/skia/include/core/SkPicture.h"
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 1101
1101 private: 1102 private:
1102 FakeContentLayerClient client_; 1103 FakeContentLayerClient client_;
1103 scoped_refptr<NoScaleContentLayer> root_layer_; 1104 scoped_refptr<NoScaleContentLayer> root_layer_;
1104 scoped_refptr<ContentLayer> child_layer_; 1105 scoped_refptr<ContentLayer> child_layer_;
1105 }; 1106 };
1106 1107
1107 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); 1108 MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers);
1108 1109
1109 // Verify atomicity of commits and reuse of textures. 1110 // Verify atomicity of commits and reuse of textures.
1110 class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest { 1111 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest {
1111 public: 1112 public:
1112 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 1113 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
1113 // Make sure partial texture updates are turned off. 1114 // Make sure partial texture updates are turned off.
1114 settings->max_partial_texture_updates = 0; 1115 settings->max_partial_texture_updates = 0;
1115 // Linear fade animator prevents scrollbars from drawing immediately. 1116 // Linear fade animator prevents scrollbars from drawing immediately.
1116 settings->use_linear_fade_scrollbar_animator = false; 1117 settings->use_linear_fade_scrollbar_animator = false;
1117 } 1118 }
1118 1119
1119 virtual void SetupTree() OVERRIDE { 1120 virtual void SetupTree() OVERRIDE {
1120 layer_ = FakeContentLayer::Create(&client_); 1121 layer_ = FakeContentLayer::Create(&client_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 // Verify that used texture is correct. 1154 // Verify that used texture is correct.
1154 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1155 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1155 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1156 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
1156 1157
1157 context->ResetUsedTextures(); 1158 context->ResetUsedTextures();
1158 PostSetNeedsCommitToMainThread(); 1159 PostSetNeedsCommitToMainThread();
1159 break; 1160 break;
1160 case 1: 1161 case 1:
1161 // Number of textures should be doubled as the first textures 1162 // Number of textures should be doubled as the first textures
1162 // are used by impl thread and cannot by used for update. 1163 // are used by impl thread and cannot by used for update.
1163 ASSERT_EQ(4u, context->NumTextures()); 1164 ASSERT_EQ(3u, context->NumTextures());
1164 // Number of textures used for commit should still be 1165 // Number of textures used for commit should still be
1165 // one for each layer. 1166 // one for each layer.
1166 EXPECT_EQ(2u, context->NumUsedTextures()); 1167 EXPECT_EQ(2u, context->NumUsedTextures());
1167 // First textures should not have been used. 1168 // First textures should not have been used.
1168 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0))); 1169 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0)));
1169 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1))); 1170 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
1170 // New textures should have been used. 1171 // New textures should have been used.
1171 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2))); 1172 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2)));
1172 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3)));
1173
1174 context->ResetUsedTextures(); 1173 context->ResetUsedTextures();
1175 PostSetNeedsCommitToMainThread(); 1174 PostSetNeedsCommitToMainThread();
1176 break; 1175 break;
1177 case 2: 1176 case 2:
1178 EndTest(); 1177 EndTest();
1179 break; 1178 break;
1180 default: 1179 default:
1181 NOTREACHED(); 1180 NOTREACHED();
1182 break; 1181 break;
1183 } 1182 }
(...skipping 12 matching lines...) Expand all
1196 // We draw/ship one texture each frame for each layer. 1195 // We draw/ship one texture each frame for each layer.
1197 EXPECT_EQ(2u, context->NumUsedTextures()); 1196 EXPECT_EQ(2u, context->NumUsedTextures());
1198 context->ResetUsedTextures(); 1197 context->ResetUsedTextures();
1199 } 1198 }
1200 1199
1201 virtual void Layout() OVERRIDE { 1200 virtual void Layout() OVERRIDE {
1202 layer_->SetNeedsDisplay(); 1201 layer_->SetNeedsDisplay();
1203 scrollbar_->SetNeedsDisplay(); 1202 scrollbar_->SetNeedsDisplay();
1204 } 1203 }
1205 1204
1206 virtual void AfterTest() OVERRIDE {} 1205 virtual void AfterTest() OVERRIDE { }
1207 1206
1208 private: 1207 protected:
1209 FakeContentLayerClient client_; 1208 FakeContentLayerClient client_;
1210 scoped_refptr<FakeContentLayer> layer_; 1209 scoped_refptr<FakeContentLayer> layer_;
1211 scoped_refptr<FakeScrollbarLayer> scrollbar_; 1210 scoped_refptr<FakeScrollbarLayer> scrollbar_;
1212 int drew_frame_; 1211 int drew_frame_;
1213 }; 1212 };
1214 1213
1215 MULTI_THREAD_TEST_F(LayerTreeHostTestAtomicCommit); 1214 MULTI_THREAD_DIRECT_RENDERER_TEST_F(
1215 LayerTreeHostTestDirectRendererAtomicCommit);
1216
1217 class LayerTreeHostTestDelegatingRendererAtomicCommit
1218 : public LayerTreeHostTestDirectRendererAtomicCommit {
1219 public:
1220 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1221 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1222
1223 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
1224 impl->output_surface()->context3d());
1225
1226 switch (impl->active_tree()->source_frame_number()) {
1227 case 0:
1228 // Number of textures should be one for each layer
1229 ASSERT_EQ(2u, context->NumTextures());
1230 // Number of textures used for commit should be one for each layer.
1231 EXPECT_EQ(2u, context->NumUsedTextures());
1232 // Verify that used texture is correct.
1233 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1234 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
1235 context->ResetUsedTextures();
1236 PostSetNeedsCommitToMainThread();
1237 break;
1238 case 1:
1239 // Number of textures should be doubled as the first textures
1240 // are used by impl thread and cannot by used for update.
1241 ASSERT_EQ(4u, context->NumTextures());
1242 // Number of textures used for commit should still be
1243 // one for each layer.
1244 EXPECT_EQ(2u, context->NumUsedTextures());
1245 // First textures should not have been used.
1246 EXPECT_FALSE(context->UsedTexture(context->TextureAt(0)));
1247 EXPECT_FALSE(context->UsedTexture(context->TextureAt(1)));
1248 // New textures should have been used.
1249 EXPECT_TRUE(context->UsedTexture(context->TextureAt(2)));
1250 EXPECT_TRUE(context->UsedTexture(context->TextureAt(3)));
1251 context->ResetUsedTextures();
1252 PostSetNeedsCommitToMainThread();
1253 break;
1254 case 2:
1255 EndTest();
1256 break;
1257 default:
1258 NOTREACHED();
1259 break;
1260 }
1261 }
1262 };
1263
1264 MULTI_THREAD_DELEGATING_RENDERER_TEST_F(
1265 LayerTreeHostTestDelegatingRendererAtomicCommit);
1216 1266
1217 static void SetLayerPropertiesForTesting(Layer* layer, 1267 static void SetLayerPropertiesForTesting(Layer* layer,
1218 Layer* parent, 1268 Layer* parent,
1219 const gfx::Transform& transform, 1269 const gfx::Transform& transform,
1220 gfx::PointF anchor, 1270 gfx::PointF anchor,
1221 gfx::PointF position, 1271 gfx::PointF position,
1222 gfx::Size bounds, 1272 gfx::Size bounds,
1223 bool opaque) { 1273 bool opaque) {
1224 layer->RemoveAllChildren(); 1274 layer->RemoveAllChildren();
1225 if (parent) 1275 if (parent)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 1462
1413 private: 1463 private:
1414 FakeContentLayerClient client_; 1464 FakeContentLayerClient client_;
1415 scoped_refptr<FakeContentLayer> parent_; 1465 scoped_refptr<FakeContentLayer> parent_;
1416 scoped_refptr<FakeContentLayer> child_; 1466 scoped_refptr<FakeContentLayer> child_;
1417 scoped_refptr<FakeScrollbarLayer> scrollbar_with_paints_; 1467 scoped_refptr<FakeScrollbarLayer> scrollbar_with_paints_;
1418 scoped_refptr<FakeScrollbarLayer> scrollbar_without_paints_; 1468 scoped_refptr<FakeScrollbarLayer> scrollbar_without_paints_;
1419 }; 1469 };
1420 1470
1421 // Partial updates are not possible with a delegating renderer. 1471 // Partial updates are not possible with a delegating renderer.
1422 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 1472 // No partial updates with impl-side painting scrollbar.
1423 LayerTreeHostTestAtomicCommitWithPartialUpdate); 1473 // SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
enne (OOO) 2013/07/22 23:09:15 Please don't comment out this test. There's still
powei 2013/07/24 02:28:29 Done. Uncommented the test and kept the content l
1474 // LayerTreeHostTestAtomicCommitWithPartialUpdate);
1424 1475
1425 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { 1476 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest {
1426 public: 1477 public:
1427 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {} 1478 LayerTreeHostTestFinishAllRendering() : once_(false), draw_count_(0) {}
1428 1479
1429 virtual void BeginTest() OVERRIDE { 1480 virtual void BeginTest() OVERRIDE {
1430 layer_tree_host()->SetNeedsRedraw(); 1481 layer_tree_host()->SetNeedsRedraw();
1431 PostSetNeedsCommitToMainThread(); 1482 PostSetNeedsCommitToMainThread();
1432 } 1483 }
1433 1484
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 3209
3159 private: 3210 private:
3160 FakeContentLayerClient client_; 3211 FakeContentLayerClient client_;
3161 scoped_refptr<FakePictureLayer> layer_; 3212 scoped_refptr<FakePictureLayer> layer_;
3162 bool initialized_gl_; 3213 bool initialized_gl_;
3163 int num_draws_; 3214 int num_draws_;
3164 }; 3215 };
3165 3216
3166 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize); 3217 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferredInitialize);
3167 3218
3219 // Test for UI Resource management.
3220 class LayerTreeHostTestUIResource : public LayerTreeHostTest {
3221 public:
3222 virtual void BeginTest() OVERRIDE {
3223 ui_resource_client_ = new TestUIResourceClient();
3224 PostSetNeedsCommitToMainThread();
3225 }
3226
3227 virtual void DidCommit() OVERRIDE {
3228 int frame = layer_tree_host()->commit_number();
3229 switch (frame) {
3230 case 1:
3231 ui_resource_id_ =
3232 layer_tree_host()->CreateUIResource(
3233 base::Bind(&TestUIResourceClient::GetBitmap,
3234 ui_resource_client_.get()));
3235 layer_tree_host()->CreateUIResource(
3236 base::Bind(&TestUIResourceClient::GetBitmap,
3237 ui_resource_client_.get()));
3238 PostSetNeedsCommitToMainThread();
3239 break;
3240 case 2:
3241 layer_tree_host()->DeleteUIResource(ui_resource_id_);
3242 PostSetNeedsCommitToMainThread();
3243 break;
3244 case 3:
3245 layer_tree_host()->DeleteUIResource(ui_resource_id_);
3246 PostSetNeedsCommitToMainThread();
3247 break;
3248 case 4:
3249 layer_tree_host()->CreateUIResource(
3250 base::Bind(&TestUIResourceClient::GetBitmap,
3251 ui_resource_client_.get()));
3252 layer_tree_host()->CreateUIResource(
3253 base::Bind(&TestUIResourceClient::GetBitmap,
3254 ui_resource_client_.get()));
3255 PostSetNeedsCommitToMainThread();
3256 break;
3257 case 5:
3258 EndTest();
3259 break;
3260 }
3261 }
3262
3263 void PerformTest(LayerTreeHostImpl* impl) {
3264 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
3265 impl->output_surface()->context3d());
3266
3267 int frame = layer_tree_host()->commit_number();
3268 switch (frame) {
3269 case 1:
3270 ASSERT_EQ(0u, context->NumTextures());
3271 break;
3272 case 2:
3273 // Created two textures.
3274 ASSERT_EQ(2u, context->NumTextures());
3275 break;
3276 case 3:
3277 // One texture left after one deletion.
3278 ASSERT_EQ(1u, context->NumTextures());
3279 break;
3280 case 4:
3281 // Texture state should not change when delete is called on an
3282 // invalid id.
3283 ASSERT_EQ(1u, context->NumTextures());
3284 break;
3285 case 5:
3286 // Creation after deletion: two more creates should total up to
3287 // three textures.
3288 ASSERT_EQ(3u, context->NumTextures());
3289 break;
3290 }
3291 }
3292
3293 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
3294 if (!layer_tree_host()->settings().impl_side_painting)
3295 PerformTest(impl);
3296 }
3297
3298 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
3299 if (layer_tree_host()->settings().impl_side_painting)
3300 PerformTest(impl);
3301 }
3302
3303 virtual void AfterTest() {}
3304
3305 private:
3306 scoped_refptr<TestUIResourceClient> ui_resource_client_;
3307 UIResourceId ui_resource_id_;
3308 };
3309
3310 MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource);
3311
3312
3168 } // namespace 3313 } // namespace
3169 } // namespace cc 3314 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698