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

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

Issue 926023003: cc: Fix bug in generating picture layer pairs from 2 lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layerlistbug: . Created 5 years, 10 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 8052 matching lines...) Expand 10 before | Expand all | Expand 10 after
8063 scrolling_layer->CurrentScrollOffset()); 8063 scrolling_layer->CurrentScrollOffset());
8064 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); 8064 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer());
8065 } 8065 }
8066 8066
8067 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { 8067 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) {
8068 host_impl_->CreatePendingTree(); 8068 host_impl_->CreatePendingTree();
8069 8069
8070 scoped_ptr<PictureLayerImpl> layer = 8070 scoped_ptr<PictureLayerImpl> layer =
8071 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10); 8071 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10);
8072 layer->SetBounds(gfx::Size(10, 10)); 8072 layer->SetBounds(gfx::Size(10, 10));
8073 scoped_ptr<FakePictureLayerImpl> nondraw_layer =
8074 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12);
8075 nondraw_layer->SetBounds(gfx::Size(10, 10));
8073 8076
8074 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( 8077 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile(
8075 gfx::Size(10, 10), gfx::Size(10, 10))); 8078 gfx::Size(10, 10), gfx::Size(10, 10)));
8076 Region empty_invalidation; 8079 Region empty_invalidation;
8077 const PictureLayerTilingSet* null_tiling_set = nullptr; 8080 const PictureLayerTilingSet* null_tiling_set = nullptr;
8078 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); 8081 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
8082 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
8079 8083
8084 layer->AddChild(nondraw_layer.Pass());
8080 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); 8085 host_impl_->pending_tree()->SetRootLayer(layer.Pass());
8081 8086
8082 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 8087 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
8083 LayerImpl* pending_layer = pending_tree->root_layer(); 8088 LayerImpl* pending_layer = pending_tree->root_layer();
8089 FakePictureLayerImpl* pending_nondraw_layer =
8090 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]);
8091
8092 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8084 8093
8085 std::vector<PictureLayerImpl::Pair> layer_pairs; 8094 std::vector<PictureLayerImpl::Pair> layer_pairs;
8086 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 8095 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8087 EXPECT_EQ(1u, layer_pairs.size()); 8096 EXPECT_EQ(1u, layer_pairs.size());
8088 EXPECT_EQ(pending_layer, layer_pairs[0].pending); 8097 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8089 EXPECT_EQ(nullptr, layer_pairs[0].active); 8098 EXPECT_EQ(nullptr, layer_pairs[0].active);
8090 8099
8091 host_impl_->ActivateSyncTree(); 8100 host_impl_->ActivateSyncTree();
8092 8101
8093 LayerTreeImpl* active_tree = host_impl_->active_tree(); 8102 LayerTreeImpl* active_tree = host_impl_->active_tree();
8094 LayerImpl* active_layer = active_tree->root_layer(); 8103 LayerImpl* active_layer = active_tree->root_layer();
8104 FakePictureLayerImpl* active_nondraw_layer =
8105 static_cast<FakePictureLayerImpl*>(active_layer->children()[0]);
8095 EXPECT_NE(active_tree, pending_tree); 8106 EXPECT_NE(active_tree, pending_tree);
8096 EXPECT_NE(active_layer, pending_layer); 8107 EXPECT_NE(active_layer, pending_layer);
8108 EXPECT_NE(active_nondraw_layer, pending_nondraw_layer);
8097 EXPECT_NE(nullptr, active_tree); 8109 EXPECT_NE(nullptr, active_tree);
8098 EXPECT_NE(nullptr, active_layer); 8110 EXPECT_NE(nullptr, active_layer);
8111 EXPECT_NE(nullptr, active_nondraw_layer);
8112
8113 active_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8099 8114
8100 host_impl_->CreatePendingTree(); 8115 host_impl_->CreatePendingTree();
8101 8116
8102 layer_pairs.clear(); 8117 layer_pairs.clear();
8103 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 8118 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8104 EXPECT_EQ(1u, layer_pairs.size()); 8119 EXPECT_EQ(1u, layer_pairs.size());
8105 EXPECT_EQ(active_layer, layer_pairs[0].active); 8120 EXPECT_EQ(active_layer, layer_pairs[0].active);
8106 EXPECT_EQ(pending_layer, layer_pairs[0].pending); 8121 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8107 8122
8108 // Activate, the active layer has no twin now. 8123 // Activate, the active layer has no twin now.
8109 host_impl_->ActivateSyncTree(); 8124 host_impl_->ActivateSyncTree();
8110 8125
8111 layer_pairs.clear(); 8126 layer_pairs.clear();
8112 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 8127 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8113 EXPECT_EQ(1u, layer_pairs.size()); 8128 EXPECT_EQ(1u, layer_pairs.size());
8114 EXPECT_EQ(active_layer, layer_pairs[0].active); 8129 EXPECT_EQ(active_layer, layer_pairs[0].active);
8115 EXPECT_EQ(nullptr, layer_pairs[0].pending); 8130 EXPECT_EQ(nullptr, layer_pairs[0].pending);
8116 8131
8117 // Create another layer in the pending tree that's not in the active tree. We 8132 // Create another layer in the pending tree that's not in the active tree. We
8118 // should get two pairs. 8133 // should get two pairs.
8119 host_impl_->CreatePendingTree(); 8134 host_impl_->CreatePendingTree();
8120 host_impl_->pending_tree()->root_layer()->AddChild( 8135 host_impl_->pending_tree()->root_layer()->AddChild(
8121 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11)); 8136 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11));
8122 8137
8123 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[0]; 8138 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[1];
8124 8139
8125 layer_pairs.clear(); 8140 layer_pairs.clear();
8126 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); 8141 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8127 EXPECT_EQ(2u, layer_pairs.size()); 8142 EXPECT_EQ(2u, layer_pairs.size());
8128
8129 // The pair ordering is flaky, so make it consistent. 8143 // The pair ordering is flaky, so make it consistent.
8130 if (layer_pairs[0].active != active_layer) 8144 if (layer_pairs[0].active != active_layer)
8131 std::swap(layer_pairs[0], layer_pairs[1]); 8145 std::swap(layer_pairs[0], layer_pairs[1]);
8132
8133 EXPECT_EQ(active_layer, layer_pairs[0].active); 8146 EXPECT_EQ(active_layer, layer_pairs[0].active);
8134 EXPECT_EQ(pending_layer, layer_pairs[0].pending); 8147 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8135 EXPECT_EQ(new_pending_layer, layer_pairs[1].pending); 8148 EXPECT_EQ(new_pending_layer, layer_pairs[1].pending);
8136 EXPECT_EQ(nullptr, layer_pairs[1].active); 8149 EXPECT_EQ(nullptr, layer_pairs[1].active);
8150
8151 host_impl_->pending_tree()->root_layer()->RemoveChild(new_pending_layer);
8152
8153 // Have the pending layer be part of the RSLL now. It should appear in the
8154 // list without an active twin.
8155 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(true);
8156
8157 layer_pairs.clear();
8158 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8159 EXPECT_EQ(2u, layer_pairs.size());
8160 // The pair ordering is flaky, so make it consistent.
8161 if (layer_pairs[0].active != active_layer)
8162 std::swap(layer_pairs[0], layer_pairs[1]);
8163 EXPECT_EQ(active_layer, layer_pairs[0].active);
8164 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8165 EXPECT_EQ(pending_nondraw_layer, layer_pairs[1].pending);
8166 EXPECT_EQ(nullptr, layer_pairs[1].active);
8167
8168 // Have the active layer be part of the RSLL now instead. It should appear in
8169 // the list without a pending twin.
8170 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8171 active_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(true);
8172
8173 layer_pairs.clear();
8174 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true);
8175 EXPECT_EQ(2u, layer_pairs.size());
8176 // The pair ordering is flaky, so make it consistent.
8177 if (layer_pairs[0].active != active_layer)
8178 std::swap(layer_pairs[0], layer_pairs[1]);
8179 EXPECT_EQ(active_layer, layer_pairs[0].active);
8180 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8181 EXPECT_EQ(nullptr, layer_pairs[1].pending);
8182 EXPECT_EQ(active_nondraw_layer, layer_pairs[1].active);
8183 }
8184
8185 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairsWithNonRSLLMembers) {
8186 host_impl_->CreatePendingTree();
8187
8188 scoped_ptr<PictureLayerImpl> layer =
8189 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 10);
8190 layer->SetBounds(gfx::Size(10, 10));
8191 scoped_ptr<FakePictureLayerImpl> nondraw_layer =
8192 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 12);
8193 nondraw_layer->SetBounds(gfx::Size(10, 10));
8194
8195 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile(
8196 gfx::Size(10, 10), gfx::Size(10, 10)));
8197 Region empty_invalidation;
8198 const PictureLayerTilingSet* null_tiling_set = nullptr;
8199 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
8200 nondraw_layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set);
8201
8202 layer->AddChild(nondraw_layer.Pass());
8203 host_impl_->pending_tree()->SetRootLayer(layer.Pass());
8204
8205 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
8206 LayerImpl* pending_layer = pending_tree->root_layer();
8207 FakePictureLayerImpl* pending_nondraw_layer =
8208 static_cast<FakePictureLayerImpl*>(pending_layer->children()[0]);
8209
8210 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8211
8212 std::vector<PictureLayerImpl::Pair> layer_pairs;
8213 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8214 EXPECT_EQ(2u, layer_pairs.size());
8215 // The pair ordering is flaky, so make it consistent.
8216 if (layer_pairs[0].pending != pending_layer)
8217 std::swap(layer_pairs[0], layer_pairs[1]);
8218 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8219 EXPECT_EQ(nullptr, layer_pairs[0].active);
8220 EXPECT_EQ(pending_nondraw_layer, layer_pairs[1].pending);
8221 EXPECT_EQ(nullptr, layer_pairs[1].active);
8222
8223 host_impl_->ActivateSyncTree();
8224
8225 LayerTreeImpl* active_tree = host_impl_->active_tree();
8226 LayerImpl* active_layer = active_tree->root_layer();
8227 FakePictureLayerImpl* active_nondraw_layer =
8228 static_cast<FakePictureLayerImpl*>(active_layer->children()[0]);
8229 EXPECT_NE(active_tree, pending_tree);
8230 EXPECT_NE(active_layer, pending_layer);
8231 EXPECT_NE(active_nondraw_layer, pending_nondraw_layer);
8232 EXPECT_NE(nullptr, active_tree);
8233 EXPECT_NE(nullptr, active_layer);
8234 EXPECT_NE(nullptr, active_nondraw_layer);
8235
8236 active_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8237
8238 host_impl_->CreatePendingTree();
8239
8240 layer_pairs.clear();
8241 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8242 EXPECT_EQ(2u, layer_pairs.size());
8243 // The pair ordering is flaky, so make it consistent.
8244 if (layer_pairs[0].active != active_layer)
8245 std::swap(layer_pairs[0], layer_pairs[1]);
8246 EXPECT_EQ(active_layer, layer_pairs[0].active);
8247 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8248 EXPECT_EQ(pending_nondraw_layer, layer_pairs[1].pending);
8249 EXPECT_EQ(active_nondraw_layer, layer_pairs[1].active);
8250
8251 // Activate, the active layer has no twin now.
8252 host_impl_->ActivateSyncTree();
8253
8254 layer_pairs.clear();
8255 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8256 EXPECT_EQ(2u, layer_pairs.size());
8257 // The pair ordering is flaky, so make it consistent.
8258 if (layer_pairs[0].active != active_layer)
8259 std::swap(layer_pairs[0], layer_pairs[1]);
8260 EXPECT_EQ(active_layer, layer_pairs[0].active);
8261 EXPECT_EQ(nullptr, layer_pairs[0].pending);
8262 EXPECT_EQ(active_nondraw_layer, layer_pairs[1].active);
8263 EXPECT_EQ(nullptr, layer_pairs[1].pending);
8264
8265 // Create another layer in the pending tree that's not in the active tree. We
8266 // should get three pairs including the nondraw layers.
8267 host_impl_->CreatePendingTree();
8268 host_impl_->pending_tree()->root_layer()->AddChild(
8269 FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11));
8270
8271 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[1];
8272
8273 layer_pairs.clear();
8274 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8275 EXPECT_EQ(3u, layer_pairs.size());
8276 // The pair ordering is flaky, so make it consistent.
8277 if (layer_pairs[0].active != active_layer)
8278 std::swap(layer_pairs[0], layer_pairs[1]);
8279 if (layer_pairs[0].active != active_layer)
8280 std::swap(layer_pairs[0], layer_pairs[2]);
8281 if (layer_pairs[1].pending != new_pending_layer)
8282 std::swap(layer_pairs[1], layer_pairs[2]);
8283 EXPECT_EQ(active_layer, layer_pairs[0].active);
8284 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8285 EXPECT_EQ(new_pending_layer, layer_pairs[1].pending);
8286 EXPECT_EQ(nullptr, layer_pairs[1].active);
8287 EXPECT_EQ(active_nondraw_layer, layer_pairs[2].active);
8288 EXPECT_EQ(pending_nondraw_layer, layer_pairs[2].pending);
8289
8290 host_impl_->pending_tree()->root_layer()->RemoveChild(new_pending_layer);
8291
8292 // Have the pending layer be part of the RSLL now. It should appear in the
8293 // list, as should its active twin since we don't request only layers with
8294 // valid draw properties.
8295 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(true);
8296
8297 layer_pairs.clear();
8298 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8299 EXPECT_EQ(2u, layer_pairs.size());
8300 // The pair ordering is flaky, so make it consistent.
8301 if (layer_pairs[0].active != active_layer)
8302 std::swap(layer_pairs[0], layer_pairs[1]);
8303 EXPECT_EQ(active_layer, layer_pairs[0].active);
8304 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8305 EXPECT_EQ(pending_nondraw_layer, layer_pairs[1].pending);
8306 EXPECT_EQ(active_nondraw_layer, layer_pairs[1].active);
8307
8308 // Have the active layer be part of the RSLL now instead. It should appear in
8309 // the list, as should its pending twin since we don't request only layers
8310 // with valid draw properties.
8311 pending_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(false);
8312 active_nondraw_layer->SetIsDrawnRenderSurfaceLayerListMember(true);
8313
8314 layer_pairs.clear();
8315 host_impl_->GetPictureLayerImplPairs(&layer_pairs, false);
8316 EXPECT_EQ(2u, layer_pairs.size());
8317 // The pair ordering is flaky, so make it consistent.
8318 if (layer_pairs[0].active != active_layer)
8319 std::swap(layer_pairs[0], layer_pairs[1]);
8320 EXPECT_EQ(active_layer, layer_pairs[0].active);
8321 EXPECT_EQ(pending_layer, layer_pairs[0].pending);
8322 EXPECT_EQ(active_nondraw_layer, layer_pairs[1].active);
8323 EXPECT_EQ(pending_nondraw_layer, layer_pairs[1].pending);
8137 } 8324 }
8138 8325
8139 TEST_F(LayerTreeHostImplTest, DidBecomeActive) { 8326 TEST_F(LayerTreeHostImplTest, DidBecomeActive) {
8140 host_impl_->CreatePendingTree(); 8327 host_impl_->CreatePendingTree();
8141 host_impl_->ActivateSyncTree(); 8328 host_impl_->ActivateSyncTree();
8142 host_impl_->CreatePendingTree(); 8329 host_impl_->CreatePendingTree();
8143 8330
8144 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 8331 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
8145 8332
8146 scoped_ptr<FakePictureLayerImpl> pending_layer = 8333 scoped_ptr<FakePictureLayerImpl> pending_layer =
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
8235 // surface. 8422 // surface.
8236 EXPECT_EQ(0, num_lost_surfaces_); 8423 EXPECT_EQ(0, num_lost_surfaces_);
8237 host_impl_->DidLoseOutputSurface(); 8424 host_impl_->DidLoseOutputSurface();
8238 EXPECT_EQ(1, num_lost_surfaces_); 8425 EXPECT_EQ(1, num_lost_surfaces_);
8239 host_impl_->DidLoseOutputSurface(); 8426 host_impl_->DidLoseOutputSurface();
8240 EXPECT_LE(1, num_lost_surfaces_); 8427 EXPECT_LE(1, num_lost_surfaces_);
8241 } 8428 }
8242 8429
8243 } // namespace 8430 } // namespace
8244 } // namespace cc 8431 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698