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

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

Issue 12662021: cc: Don't draw and swap if the frame will not change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add perf test Created 7 years, 9 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 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 <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 layer->SetBounds(size); 215 layer->SetBounds(size);
216 layer->SetContentBounds(size); 216 layer->SetContentBounds(size);
217 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, 217 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2,
218 size.height() * 2)); 218 size.height() * 2));
219 return layer.Pass(); 219 return layer.Pass();
220 } 220 }
221 221
222 void InitializeRendererAndDrawFrame() { 222 void InitializeRendererAndDrawFrame() {
223 host_impl_->InitializeRenderer(CreateOutputSurface()); 223 host_impl_->InitializeRenderer(CreateOutputSurface());
224 LayerTreeHostImpl::FrameData frame; 224 LayerTreeHostImpl::FrameData frame;
225 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 225 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
226 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 226 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
227 host_impl_->DidDrawAllLayers(frame); 227 host_impl_->DidDrawAllLayers(frame);
228 } 228 }
229 229
230 void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor); 230 void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor);
231 void pinch_zoom_pan_viewport_test(float device_scale_factor); 231 void pinch_zoom_pan_viewport_test(float device_scale_factor);
232 void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor); 232 void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor);
233 void pinch_zoom_pan_viewport_and_scroll_boundary_test( 233 void pinch_zoom_pan_viewport_and_scroll_boundary_test(
234 float device_scale_factor); 234 float device_scale_factor);
235 235
236 protected: 236 protected:
237 virtual scoped_ptr<OutputSurface> CreateOutputSurface() { 237 virtual scoped_ptr<OutputSurface> CreateOutputSurface() {
238 return CreateFakeOutputSurface(); 238 return CreateFakeOutputSurface();
239 } 239 }
240 240
241 void DrawOneFrame() { 241 void DrawOneFrame() {
242 LayerTreeHostImpl::FrameData frame_data; 242 LayerTreeHostImpl::FrameData frame_data;
243 host_impl_->PrepareToDraw(&frame_data); 243 host_impl_->PrepareToDraw(&frame_data, gfx::Rect());
244 host_impl_->DidDrawAllLayers(frame_data); 244 host_impl_->DidDrawAllLayers(frame_data);
245 } 245 }
246 246
247 FakeProxy proxy_; 247 FakeProxy proxy_;
248 DebugScopedSetImplThread always_impl_thread_; 248 DebugScopedSetImplThread always_impl_thread_;
249 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; 249 DebugScopedSetMainThreadBlocked always_main_thread_blocked_;
250 250
251 scoped_ptr<LayerTreeHostImpl> host_impl_; 251 scoped_ptr<LayerTreeHostImpl> host_impl_;
252 FakeRenderingStatsInstrumentation stats_instrumentation_; 252 FakeRenderingStatsInstrumentation stats_instrumentation_;
253 bool on_can_draw_state_changed_called_; 253 bool on_can_draw_state_changed_called_;
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 // Ensure visible_content_rect for layer is empty. 1049 // Ensure visible_content_rect for layer is empty.
1050 layer->SetPosition(gfx::PointF(100.f, 100.f)); 1050 layer->SetPosition(gfx::PointF(100.f, 100.f));
1051 layer->SetBounds(gfx::Size(10, 10)); 1051 layer->SetBounds(gfx::Size(10, 10));
1052 layer->SetContentBounds(gfx::Size(10, 10)); 1052 layer->SetContentBounds(gfx::Size(10, 10));
1053 1053
1054 LayerTreeHostImpl::FrameData frame; 1054 LayerTreeHostImpl::FrameData frame;
1055 1055
1056 EXPECT_FALSE(layer->will_draw_called()); 1056 EXPECT_FALSE(layer->will_draw_called());
1057 EXPECT_FALSE(layer->did_draw_called()); 1057 EXPECT_FALSE(layer->did_draw_called());
1058 1058
1059 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1059 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1060 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1060 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1061 host_impl_->DidDrawAllLayers(frame); 1061 host_impl_->DidDrawAllLayers(frame);
1062 1062
1063 EXPECT_FALSE(layer->will_draw_called()); 1063 EXPECT_FALSE(layer->will_draw_called());
1064 EXPECT_FALSE(layer->did_draw_called()); 1064 EXPECT_FALSE(layer->did_draw_called());
1065 1065
1066 EXPECT_TRUE(layer->visible_content_rect().IsEmpty()); 1066 EXPECT_TRUE(layer->visible_content_rect().IsEmpty());
1067 1067
1068 // Ensure visible_content_rect for layer is not empty 1068 // Ensure visible_content_rect for layer is not empty
1069 layer->SetPosition(gfx::PointF()); 1069 layer->SetPosition(gfx::PointF());
1070 1070
1071 EXPECT_FALSE(layer->will_draw_called()); 1071 EXPECT_FALSE(layer->will_draw_called());
1072 EXPECT_FALSE(layer->did_draw_called()); 1072 EXPECT_FALSE(layer->did_draw_called());
1073 1073
1074 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1074 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1075 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1075 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1076 host_impl_->DidDrawAllLayers(frame); 1076 host_impl_->DidDrawAllLayers(frame);
1077 1077
1078 EXPECT_TRUE(layer->will_draw_called()); 1078 EXPECT_TRUE(layer->will_draw_called());
1079 EXPECT_TRUE(layer->did_draw_called()); 1079 EXPECT_TRUE(layer->did_draw_called());
1080 1080
1081 EXPECT_FALSE(layer->visible_content_rect().IsEmpty()); 1081 EXPECT_FALSE(layer->visible_content_rect().IsEmpty());
1082 } 1082 }
1083 1083
1084 TEST_F(LayerTreeHostImplTest, WillDrawNotCalledOnOccludedLayer) { 1084 TEST_F(LayerTreeHostImplTest, WillDrawNotCalledOnOccludedLayer) {
(...skipping 18 matching lines...) Expand all
1103 top_layer->SetContentBounds(big_size); 1103 top_layer->SetContentBounds(big_size);
1104 top_layer->SetContentsOpaque(true); 1104 top_layer->SetContentsOpaque(true);
1105 1105
1106 LayerTreeHostImpl::FrameData frame; 1106 LayerTreeHostImpl::FrameData frame;
1107 1107
1108 EXPECT_FALSE(occluded_layer->will_draw_called()); 1108 EXPECT_FALSE(occluded_layer->will_draw_called());
1109 EXPECT_FALSE(occluded_layer->did_draw_called()); 1109 EXPECT_FALSE(occluded_layer->did_draw_called());
1110 EXPECT_FALSE(top_layer->will_draw_called()); 1110 EXPECT_FALSE(top_layer->will_draw_called());
1111 EXPECT_FALSE(top_layer->did_draw_called()); 1111 EXPECT_FALSE(top_layer->did_draw_called());
1112 1112
1113 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1113 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1114 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1114 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1115 host_impl_->DidDrawAllLayers(frame); 1115 host_impl_->DidDrawAllLayers(frame);
1116 1116
1117 EXPECT_FALSE(occluded_layer->will_draw_called()); 1117 EXPECT_FALSE(occluded_layer->will_draw_called());
1118 EXPECT_FALSE(occluded_layer->did_draw_called()); 1118 EXPECT_FALSE(occluded_layer->did_draw_called());
1119 EXPECT_TRUE(top_layer->will_draw_called()); 1119 EXPECT_TRUE(top_layer->will_draw_called());
1120 EXPECT_TRUE(top_layer->did_draw_called()); 1120 EXPECT_TRUE(top_layer->did_draw_called());
1121 } 1121 }
1122 1122
1123 TEST_F(LayerTreeHostImplTest, DidDrawCalledOnAllLayers) { 1123 TEST_F(LayerTreeHostImplTest, DidDrawCalledOnAllLayers) {
(...skipping 11 matching lines...) Expand all
1135 static_cast<DidDrawCheckLayer*>(layer1->children()[0]); 1135 static_cast<DidDrawCheckLayer*>(layer1->children()[0]);
1136 1136
1137 layer1->SetOpacity(0.3f); 1137 layer1->SetOpacity(0.3f);
1138 layer1->SetPreserves3d(false); 1138 layer1->SetPreserves3d(false);
1139 1139
1140 EXPECT_FALSE(root->did_draw_called()); 1140 EXPECT_FALSE(root->did_draw_called());
1141 EXPECT_FALSE(layer1->did_draw_called()); 1141 EXPECT_FALSE(layer1->did_draw_called());
1142 EXPECT_FALSE(layer2->did_draw_called()); 1142 EXPECT_FALSE(layer2->did_draw_called());
1143 1143
1144 LayerTreeHostImpl::FrameData frame; 1144 LayerTreeHostImpl::FrameData frame;
1145 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1145 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1146 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1146 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1147 host_impl_->DidDrawAllLayers(frame); 1147 host_impl_->DidDrawAllLayers(frame);
1148 1148
1149 EXPECT_TRUE(root->did_draw_called()); 1149 EXPECT_TRUE(root->did_draw_called());
1150 EXPECT_TRUE(layer1->did_draw_called()); 1150 EXPECT_TRUE(layer1->did_draw_called());
1151 EXPECT_TRUE(layer2->did_draw_called()); 1151 EXPECT_TRUE(layer2->did_draw_called());
1152 1152
1153 EXPECT_NE(root->render_surface(), layer1->render_surface()); 1153 EXPECT_NE(root->render_surface(), layer1->render_surface());
1154 EXPECT_TRUE(!!layer1->render_surface()); 1154 EXPECT_TRUE(!!layer1->render_surface());
1155 } 1155 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 root->AddChild( 1207 root->AddChild(
1208 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(), 1208 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(),
1209 2, 1209 2,
1210 false, 1210 false,
1211 false, 1211 false,
1212 true, 1212 true,
1213 host_impl_->resource_provider())); 1213 host_impl_->resource_provider()));
1214 1214
1215 LayerTreeHostImpl::FrameData frame; 1215 LayerTreeHostImpl::FrameData frame;
1216 1216
1217 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1217 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1218 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1218 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1219 host_impl_->DidDrawAllLayers(frame); 1219 host_impl_->DidDrawAllLayers(frame);
1220 1220
1221 // When a texture is missing and we're not animating, we draw as usual with 1221 // When a texture is missing and we're not animating, we draw as usual with
1222 // checkerboarding. 1222 // checkerboarding.
1223 host_impl_->active_tree()->SetRootLayer( 1223 host_impl_->active_tree()->SetRootLayer(
1224 DidDrawCheckLayer::Create(host_impl_->active_tree(), 3)); 1224 DidDrawCheckLayer::Create(host_impl_->active_tree(), 3));
1225 root = 1225 root =
1226 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer()); 1226 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer());
1227 root->AddChild( 1227 root->AddChild(
1228 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(), 1228 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(),
1229 4, 1229 4,
1230 true, 1230 true,
1231 false, 1231 false,
1232 false, 1232 false,
1233 host_impl_->resource_provider())); 1233 host_impl_->resource_provider()));
1234 1234
1235 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1235 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1236 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1236 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1237 host_impl_->DidDrawAllLayers(frame); 1237 host_impl_->DidDrawAllLayers(frame);
1238 1238
1239 // When a texture is missing and we're animating, we don't want to draw 1239 // When a texture is missing and we're animating, we don't want to draw
1240 // anything. 1240 // anything.
1241 host_impl_->active_tree()->SetRootLayer( 1241 host_impl_->active_tree()->SetRootLayer(
1242 DidDrawCheckLayer::Create(host_impl_->active_tree(), 5)); 1242 DidDrawCheckLayer::Create(host_impl_->active_tree(), 5));
1243 root = 1243 root =
1244 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer()); 1244 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer());
1245 root->AddChild( 1245 root->AddChild(
1246 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(), 1246 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(),
1247 6, 1247 6,
1248 true, 1248 true,
1249 false, 1249 false,
1250 true, 1250 true,
1251 host_impl_->resource_provider())); 1251 host_impl_->resource_provider()));
1252 1252
1253 EXPECT_FALSE(host_impl_->PrepareToDraw(&frame)); 1253 EXPECT_FALSE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1254 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1254 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1255 host_impl_->DidDrawAllLayers(frame); 1255 host_impl_->DidDrawAllLayers(frame);
1256 1256
1257 // When the layer skips draw and we're animating, we still draw the frame. 1257 // When the layer skips draw and we're animating, we still draw the frame.
1258 host_impl_->active_tree()->SetRootLayer( 1258 host_impl_->active_tree()->SetRootLayer(
1259 DidDrawCheckLayer::Create(host_impl_->active_tree(), 7)); 1259 DidDrawCheckLayer::Create(host_impl_->active_tree(), 7));
1260 root = 1260 root =
1261 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer()); 1261 static_cast<DidDrawCheckLayer*>(host_impl_->active_tree()->root_layer());
1262 root->AddChild( 1262 root->AddChild(
1263 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(), 1263 MissingTextureAnimatingLayer::Create(host_impl_->active_tree(),
1264 8, 1264 8,
1265 false, 1265 false,
1266 true, 1266 true,
1267 true, 1267 true,
1268 host_impl_->resource_provider())); 1268 host_impl_->resource_provider()));
1269 1269
1270 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1270 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1271 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1271 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1272 host_impl_->DidDrawAllLayers(frame); 1272 host_impl_->DidDrawAllLayers(frame);
1273 } 1273 }
1274 1274
1275 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { 1275 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) {
1276 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); 1276 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1);
1277 root->SetScrollable(false); 1277 root->SetScrollable(false);
1278 host_impl_->active_tree()->SetRootLayer(root.Pass()); 1278 host_impl_->active_tree()->SetRootLayer(root.Pass());
1279 InitializeRendererAndDrawFrame(); 1279 InitializeRendererAndDrawFrame();
1280 1280
(...skipping 18 matching lines...) Expand all
1299 1299
1300 gfx::Size layer_size(5, 5); 1300 gfx::Size layer_size(5, 5);
1301 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); 1301 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1);
1302 root->SetScrollable(true); 1302 root->SetScrollable(true);
1303 root->SetMaxScrollOffset(gfx::Vector2d(layer_size.width(), 1303 root->SetMaxScrollOffset(gfx::Vector2d(layer_size.width(),
1304 layer_size.height())); 1304 layer_size.height()));
1305 root->SetBounds(layer_size); 1305 root->SetBounds(layer_size);
1306 root->SetContentBounds(layer_size); 1306 root->SetContentBounds(layer_size);
1307 root->SetPosition(gfx::PointF()); 1307 root->SetPosition(gfx::PointF());
1308 root->SetAnchorPoint(gfx::PointF()); 1308 root->SetAnchorPoint(gfx::PointF());
1309 root->SetDrawsContent(false);
1309 host_impl_->active_tree()->SetRootLayer(root.Pass()); 1310 host_impl_->active_tree()->SetRootLayer(root.Pass());
1310 host_impl_->active_tree()->FindRootScrollLayer(); 1311 host_impl_->active_tree()->FindRootScrollLayer();
1311 InitializeRendererAndDrawFrame(); 1312 InitializeRendererAndDrawFrame();
1312 1313
1313 EXPECT_EQ(InputHandlerClient::ScrollIgnored, 1314 EXPECT_EQ(InputHandlerClient::ScrollIgnored,
1314 host_impl_->ScrollBegin(gfx::Point(), InputHandlerClient::Gesture)); 1315 host_impl_->ScrollBegin(gfx::Point(), InputHandlerClient::Gesture));
1315 1316
1316 host_impl_->top_controls_manager()->ScrollBegin(); 1317 host_impl_->top_controls_manager()->ScrollBegin();
1317 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); 1318 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f));
1318 host_impl_->top_controls_manager()->ScrollEnd(); 1319 host_impl_->top_controls_manager()->ScrollEnd();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 DrawOneFrame(); 1601 DrawOneFrame();
1601 1602
1602 // The page scale delta should only be applied to the scrollable root layer. 1603 // The page scale delta should only be applied to the scrollable root layer.
1603 EXPECT_EQ(root->impl_transform(), new_page_scale_matrix); 1604 EXPECT_EQ(root->impl_transform(), new_page_scale_matrix);
1604 EXPECT_EQ(child->impl_transform(), default_page_scale_matrix); 1605 EXPECT_EQ(child->impl_transform(), default_page_scale_matrix);
1605 EXPECT_EQ(grand_child->impl_transform(), default_page_scale_matrix); 1606 EXPECT_EQ(grand_child->impl_transform(), default_page_scale_matrix);
1606 1607
1607 // Make sure all the layers are drawn with the page scale delta applied, i.e., 1608 // Make sure all the layers are drawn with the page scale delta applied, i.e.,
1608 // the page scale delta on the root layer is applied hierarchically. 1609 // the page scale delta on the root layer is applied hierarchically.
1609 LayerTreeHostImpl::FrameData frame; 1610 LayerTreeHostImpl::FrameData frame;
1610 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 1611 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
1611 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 1612 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
1612 host_impl_->DidDrawAllLayers(frame); 1613 host_impl_->DidDrawAllLayers(frame);
1613 1614
1614 EXPECT_EQ(new_page_scale, root->draw_transform().matrix().getDouble(0, 0)); 1615 EXPECT_EQ(new_page_scale, root->draw_transform().matrix().getDouble(0, 0));
1615 EXPECT_EQ(new_page_scale, root->draw_transform().matrix().getDouble(1, 1)); 1616 EXPECT_EQ(new_page_scale, root->draw_transform().matrix().getDouble(1, 1));
1616 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); 1617 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0));
1617 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); 1618 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1));
1618 EXPECT_EQ(new_page_scale, 1619 EXPECT_EQ(new_page_scale,
1619 grand_child->draw_transform().matrix().getDouble(0, 0)); 1620 grand_child->draw_transform().matrix().getDouble(0, 0));
1620 EXPECT_EQ(new_page_scale, 1621 EXPECT_EQ(new_page_scale,
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2136 host_impl_->resource_provider())); 2137 host_impl_->resource_provider()));
2137 BlendStateCheckLayer* layer1 = 2138 BlendStateCheckLayer* layer1 =
2138 static_cast<BlendStateCheckLayer*>(root->children()[0]); 2139 static_cast<BlendStateCheckLayer*>(root->children()[0]);
2139 layer1->SetPosition(gfx::PointF(2.f, 2.f)); 2140 layer1->SetPosition(gfx::PointF(2.f, 2.f));
2140 2141
2141 LayerTreeHostImpl::FrameData frame; 2142 LayerTreeHostImpl::FrameData frame;
2142 2143
2143 // Opaque layer, drawn without blending. 2144 // Opaque layer, drawn without blending.
2144 layer1->SetContentsOpaque(true); 2145 layer1->SetContentsOpaque(true);
2145 layer1->SetExpectation(false, false); 2146 layer1->SetExpectation(false, false);
2146 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2147 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2148 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2147 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2149 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2148 EXPECT_TRUE(layer1->quads_appended()); 2150 EXPECT_TRUE(layer1->quads_appended());
2149 host_impl_->DidDrawAllLayers(frame); 2151 host_impl_->DidDrawAllLayers(frame);
2150 2152
2151 // Layer with translucent content and painting, so drawn with blending. 2153 // Layer with translucent content and painting, so drawn with blending.
2152 layer1->SetContentsOpaque(false); 2154 layer1->SetContentsOpaque(false);
2153 layer1->SetExpectation(true, false); 2155 layer1->SetExpectation(true, false);
2154 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2156 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2157 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2155 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2158 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2156 EXPECT_TRUE(layer1->quads_appended()); 2159 EXPECT_TRUE(layer1->quads_appended());
2157 host_impl_->DidDrawAllLayers(frame); 2160 host_impl_->DidDrawAllLayers(frame);
2158 2161
2159 // Layer with translucent opacity, drawn with blending. 2162 // Layer with translucent opacity, drawn with blending.
2160 layer1->SetContentsOpaque(true); 2163 layer1->SetContentsOpaque(true);
2161 layer1->SetOpacity(0.5f); 2164 layer1->SetOpacity(0.5f);
2162 layer1->SetExpectation(true, false); 2165 layer1->SetExpectation(true, false);
2163 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2166 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2167 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2164 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2168 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2165 EXPECT_TRUE(layer1->quads_appended()); 2169 EXPECT_TRUE(layer1->quads_appended());
2166 host_impl_->DidDrawAllLayers(frame); 2170 host_impl_->DidDrawAllLayers(frame);
2167 2171
2168 // Layer with translucent opacity and painting, drawn with blending. 2172 // Layer with translucent opacity and painting, drawn with blending.
2169 layer1->SetContentsOpaque(true); 2173 layer1->SetContentsOpaque(true);
2170 layer1->SetOpacity(0.5f); 2174 layer1->SetOpacity(0.5f);
2171 layer1->SetExpectation(true, false); 2175 layer1->SetExpectation(true, false);
2172 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2176 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2177 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2173 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2178 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2174 EXPECT_TRUE(layer1->quads_appended()); 2179 EXPECT_TRUE(layer1->quads_appended());
2175 host_impl_->DidDrawAllLayers(frame); 2180 host_impl_->DidDrawAllLayers(frame);
2176 2181
2177 layer1->AddChild( 2182 layer1->AddChild(
2178 BlendStateCheckLayer::Create(host_impl_->active_tree(), 2183 BlendStateCheckLayer::Create(host_impl_->active_tree(),
2179 3, 2184 3,
2180 host_impl_->resource_provider())); 2185 host_impl_->resource_provider()));
2181 BlendStateCheckLayer* layer2 = 2186 BlendStateCheckLayer* layer2 =
2182 static_cast<BlendStateCheckLayer*>(layer1->children()[0]); 2187 static_cast<BlendStateCheckLayer*>(layer1->children()[0]);
2183 layer2->SetPosition(gfx::PointF(4.f, 4.f)); 2188 layer2->SetPosition(gfx::PointF(4.f, 4.f));
2184 2189
2185 // 2 opaque layers, drawn without blending. 2190 // 2 opaque layers, drawn without blending.
2186 layer1->SetContentsOpaque(true); 2191 layer1->SetContentsOpaque(true);
2187 layer1->SetOpacity(1.f); 2192 layer1->SetOpacity(1.f);
2188 layer1->SetExpectation(false, false); 2193 layer1->SetExpectation(false, false);
2194 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2189 layer2->SetContentsOpaque(true); 2195 layer2->SetContentsOpaque(true);
2190 layer2->SetOpacity(1.f); 2196 layer2->SetOpacity(1.f);
2191 layer2->SetExpectation(false, false); 2197 layer2->SetExpectation(false, false);
2192 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2198 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2199 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2193 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2200 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2194 EXPECT_TRUE(layer1->quads_appended()); 2201 EXPECT_TRUE(layer1->quads_appended());
2195 EXPECT_TRUE(layer2->quads_appended()); 2202 EXPECT_TRUE(layer2->quads_appended());
2196 host_impl_->DidDrawAllLayers(frame); 2203 host_impl_->DidDrawAllLayers(frame);
2197 2204
2198 // Parent layer with translucent content, drawn with blending. 2205 // Parent layer with translucent content, drawn with blending.
2199 // Child layer with opaque content, drawn without blending. 2206 // Child layer with opaque content, drawn without blending.
2200 layer1->SetContentsOpaque(false); 2207 layer1->SetContentsOpaque(false);
2201 layer1->SetExpectation(true, false); 2208 layer1->SetExpectation(true, false);
2209 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2202 layer2->SetExpectation(false, false); 2210 layer2->SetExpectation(false, false);
2203 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2211 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2212 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2204 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2213 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2205 EXPECT_TRUE(layer1->quads_appended()); 2214 EXPECT_TRUE(layer1->quads_appended());
2206 EXPECT_TRUE(layer2->quads_appended()); 2215 EXPECT_TRUE(layer2->quads_appended());
2207 host_impl_->DidDrawAllLayers(frame); 2216 host_impl_->DidDrawAllLayers(frame);
2208 2217
2209 // Parent layer with translucent content but opaque painting, drawn without 2218 // Parent layer with translucent content but opaque painting, drawn without
2210 // blending. 2219 // blending.
2211 // Child layer with opaque content, drawn without blending. 2220 // Child layer with opaque content, drawn without blending.
2212 layer1->SetContentsOpaque(true); 2221 layer1->SetContentsOpaque(true);
2213 layer1->SetExpectation(false, false); 2222 layer1->SetExpectation(false, false);
2223 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2214 layer2->SetExpectation(false, false); 2224 layer2->SetExpectation(false, false);
2215 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2225 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2226 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2216 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2227 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2217 EXPECT_TRUE(layer1->quads_appended()); 2228 EXPECT_TRUE(layer1->quads_appended());
2218 EXPECT_TRUE(layer2->quads_appended()); 2229 EXPECT_TRUE(layer2->quads_appended());
2219 host_impl_->DidDrawAllLayers(frame); 2230 host_impl_->DidDrawAllLayers(frame);
2220 2231
2221 // Parent layer with translucent opacity and opaque content. Since it has a 2232 // Parent layer with translucent opacity and opaque content. Since it has a
2222 // drawing child, it's drawn to a render surface which carries the opacity, 2233 // drawing child, it's drawn to a render surface which carries the opacity,
2223 // so it's itself drawn without blending. 2234 // so it's itself drawn without blending.
2224 // Child layer with opaque content, drawn without blending (parent surface 2235 // Child layer with opaque content, drawn without blending (parent surface
2225 // carries the inherited opacity). 2236 // carries the inherited opacity).
2226 layer1->SetContentsOpaque(true); 2237 layer1->SetContentsOpaque(true);
2227 layer1->SetOpacity(0.5f); 2238 layer1->SetOpacity(0.5f);
2228 layer1->SetExpectation(false, true); 2239 layer1->SetExpectation(false, true);
2240 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2229 layer2->SetExpectation(false, false); 2241 layer2->SetExpectation(false, false);
2230 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2242 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2243 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2231 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2244 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2232 EXPECT_TRUE(layer1->quads_appended()); 2245 EXPECT_TRUE(layer1->quads_appended());
2233 EXPECT_TRUE(layer2->quads_appended()); 2246 EXPECT_TRUE(layer2->quads_appended());
2234 host_impl_->DidDrawAllLayers(frame); 2247 host_impl_->DidDrawAllLayers(frame);
2235 2248
2236 // Draw again, but with child non-opaque, to make sure 2249 // Draw again, but with child non-opaque, to make sure
2237 // layer1 not culled. 2250 // layer1 not culled.
2238 layer1->SetContentsOpaque(true); 2251 layer1->SetContentsOpaque(true);
2239 layer1->SetOpacity(1.f); 2252 layer1->SetOpacity(1.f);
2240 layer1->SetExpectation(false, false); 2253 layer1->SetExpectation(false, false);
2254 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2241 layer2->SetContentsOpaque(true); 2255 layer2->SetContentsOpaque(true);
2242 layer2->SetOpacity(0.5f); 2256 layer2->SetOpacity(0.5f);
2243 layer2->SetExpectation(true, false); 2257 layer2->SetExpectation(true, false);
2244 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2258 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2259 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2245 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2260 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2246 EXPECT_TRUE(layer1->quads_appended()); 2261 EXPECT_TRUE(layer1->quads_appended());
2247 EXPECT_TRUE(layer2->quads_appended()); 2262 EXPECT_TRUE(layer2->quads_appended());
2248 host_impl_->DidDrawAllLayers(frame); 2263 host_impl_->DidDrawAllLayers(frame);
2249 2264
2250 // A second way of making the child non-opaque. 2265 // A second way of making the child non-opaque.
2251 layer1->SetContentsOpaque(true); 2266 layer1->SetContentsOpaque(true);
2252 layer1->SetOpacity(1.f); 2267 layer1->SetOpacity(1.f);
2253 layer1->SetExpectation(false, false); 2268 layer1->SetExpectation(false, false);
2269 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2254 layer2->SetContentsOpaque(false); 2270 layer2->SetContentsOpaque(false);
2255 layer2->SetOpacity(1.f); 2271 layer2->SetOpacity(1.f);
2256 layer2->SetExpectation(true, false); 2272 layer2->SetExpectation(true, false);
2257 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2273 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2274 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2258 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2275 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2259 EXPECT_TRUE(layer1->quads_appended()); 2276 EXPECT_TRUE(layer1->quads_appended());
2260 EXPECT_TRUE(layer2->quads_appended()); 2277 EXPECT_TRUE(layer2->quads_appended());
2261 host_impl_->DidDrawAllLayers(frame); 2278 host_impl_->DidDrawAllLayers(frame);
2262 2279
2263 // And when the layer says its not opaque but is painted opaque, it is not 2280 // And when the layer says its not opaque but is painted opaque, it is not
2264 // blended. 2281 // blended.
2265 layer1->SetContentsOpaque(true); 2282 layer1->SetContentsOpaque(true);
2266 layer1->SetOpacity(1.f); 2283 layer1->SetOpacity(1.f);
2267 layer1->SetExpectation(false, false); 2284 layer1->SetExpectation(false, false);
2285 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2268 layer2->SetContentsOpaque(true); 2286 layer2->SetContentsOpaque(true);
2269 layer2->SetOpacity(1.f); 2287 layer2->SetOpacity(1.f);
2270 layer2->SetExpectation(false, false); 2288 layer2->SetExpectation(false, false);
2271 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2289 layer2->set_update_rect(gfx::RectF(layer1->content_bounds()));
2290 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2272 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2291 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2273 EXPECT_TRUE(layer1->quads_appended()); 2292 EXPECT_TRUE(layer1->quads_appended());
2274 EXPECT_TRUE(layer2->quads_appended()); 2293 EXPECT_TRUE(layer2->quads_appended());
2275 host_impl_->DidDrawAllLayers(frame); 2294 host_impl_->DidDrawAllLayers(frame);
2276 2295
2277 // Layer with partially opaque contents, drawn with blending. 2296 // Layer with partially opaque contents, drawn with blending.
2278 layer1->SetContentsOpaque(false); 2297 layer1->SetContentsOpaque(false);
2279 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); 2298 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5));
2280 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 5)); 2299 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 5));
2281 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 2300 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
2282 layer1->SetExpectation(true, false); 2301 layer1->SetExpectation(true, false);
2283 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2302 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2303 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2284 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2304 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2285 EXPECT_TRUE(layer1->quads_appended()); 2305 EXPECT_TRUE(layer1->quads_appended());
2286 host_impl_->DidDrawAllLayers(frame); 2306 host_impl_->DidDrawAllLayers(frame);
2287 2307
2288 // Layer with partially opaque contents partially culled, drawn with blending. 2308 // Layer with partially opaque contents partially culled, drawn with blending.
2289 layer1->SetContentsOpaque(false); 2309 layer1->SetContentsOpaque(false);
2290 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); 2310 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5));
2291 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 2)); 2311 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 2));
2292 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 2312 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
2293 layer1->SetExpectation(true, false); 2313 layer1->SetExpectation(true, false);
2294 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2314 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2315 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2295 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2316 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2296 EXPECT_TRUE(layer1->quads_appended()); 2317 EXPECT_TRUE(layer1->quads_appended());
2297 host_impl_->DidDrawAllLayers(frame); 2318 host_impl_->DidDrawAllLayers(frame);
2298 2319
2299 // Layer with partially opaque contents culled, drawn with blending. 2320 // Layer with partially opaque contents culled, drawn with blending.
2300 layer1->SetContentsOpaque(false); 2321 layer1->SetContentsOpaque(false);
2301 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); 2322 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5));
2302 layer1->SetQuadVisibleRect(gfx::Rect(7, 5, 3, 5)); 2323 layer1->SetQuadVisibleRect(gfx::Rect(7, 5, 3, 5));
2303 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 2324 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
2304 layer1->SetExpectation(true, false); 2325 layer1->SetExpectation(true, false);
2305 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2326 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2327 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2306 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2328 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2307 EXPECT_TRUE(layer1->quads_appended()); 2329 EXPECT_TRUE(layer1->quads_appended());
2308 host_impl_->DidDrawAllLayers(frame); 2330 host_impl_->DidDrawAllLayers(frame);
2309 2331
2310 // Layer with partially opaque contents and translucent contents culled, drawn 2332 // Layer with partially opaque contents and translucent contents culled, drawn
2311 // without blending. 2333 // without blending.
2312 layer1->SetContentsOpaque(false); 2334 layer1->SetContentsOpaque(false);
2313 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); 2335 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5));
2314 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); 2336 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5));
2315 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 2337 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
2316 layer1->SetExpectation(false, false); 2338 layer1->SetExpectation(false, false);
2317 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2339 layer1->set_update_rect(gfx::RectF(layer1->content_bounds()));
2340 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2318 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2341 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2319 EXPECT_TRUE(layer1->quads_appended()); 2342 EXPECT_TRUE(layer1->quads_appended());
2320 host_impl_->DidDrawAllLayers(frame); 2343 host_impl_->DidDrawAllLayers(frame);
2321 2344
2322 } 2345 }
2323 2346
2324 TEST_F(LayerTreeHostImplTest, ViewportCovered) { 2347 TEST_F(LayerTreeHostImplTest, ViewportCovered) {
2325 host_impl_->InitializeRenderer(CreateOutputSurface()); 2348 host_impl_->InitializeRenderer(CreateOutputSurface());
2326 host_impl_->active_tree()->set_background_color(SK_ColorGRAY); 2349 host_impl_->active_tree()->set_background_color(SK_ColorGRAY);
2327 2350
(...skipping 14 matching lines...) Expand all
2342 // No gutter rects 2365 // No gutter rects
2343 { 2366 {
2344 gfx::Rect layer_rect(0, 0, 1000, 1000); 2367 gfx::Rect layer_rect(0, 0, 1000, 1000);
2345 child->SetPosition(layer_rect.origin()); 2368 child->SetPosition(layer_rect.origin());
2346 child->SetBounds(layer_rect.size()); 2369 child->SetBounds(layer_rect.size());
2347 child->SetContentBounds(layer_rect.size()); 2370 child->SetContentBounds(layer_rect.size());
2348 child->SetQuadRect(gfx::Rect(layer_rect.size())); 2371 child->SetQuadRect(gfx::Rect(layer_rect.size()));
2349 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); 2372 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size()));
2350 2373
2351 LayerTreeHostImpl::FrameData frame; 2374 LayerTreeHostImpl::FrameData frame;
2352 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2375 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2353 ASSERT_EQ(1u, frame.render_passes.size()); 2376 ASSERT_EQ(1u, frame.render_passes.size());
2354 2377
2355 size_t num_gutter_quads = 0; 2378 size_t num_gutter_quads = 0;
2356 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) 2379 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2357 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material == 2380 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material ==
2358 DrawQuad::SOLID_COLOR) ? 1 : 0; 2381 DrawQuad::SOLID_COLOR) ? 1 : 0;
2359 EXPECT_EQ(0u, num_gutter_quads); 2382 EXPECT_EQ(0u, num_gutter_quads);
2360 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); 2383 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size());
2361 2384
2362 LayerTestCommon::VerifyQuadsExactlyCoverRect( 2385 LayerTestCommon::VerifyQuadsExactlyCoverRect(
2363 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size)); 2386 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size));
2364 host_impl_->DidDrawAllLayers(frame); 2387 host_impl_->DidDrawAllLayers(frame);
2365 } 2388 }
2366 2389
2367 // Empty visible content area (fullscreen gutter rect) 2390 // Empty visible content area (fullscreen gutter rect)
2368 { 2391 {
2369 gfx::Rect layer_rect(0, 0, 0, 0); 2392 gfx::Rect layer_rect(0, 0, 0, 0);
2370 child->SetPosition(layer_rect.origin()); 2393 child->SetPosition(layer_rect.origin());
2371 child->SetBounds(layer_rect.size()); 2394 child->SetBounds(layer_rect.size());
2372 child->SetContentBounds(layer_rect.size()); 2395 child->SetContentBounds(layer_rect.size());
2373 child->SetQuadRect(gfx::Rect(layer_rect.size())); 2396 child->SetQuadRect(gfx::Rect(layer_rect.size()));
2374 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); 2397 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size()));
2375 2398
2376 LayerTreeHostImpl::FrameData frame; 2399 LayerTreeHostImpl::FrameData frame;
2377 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2400 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2378 ASSERT_EQ(1u, frame.render_passes.size()); 2401 ASSERT_EQ(1u, frame.render_passes.size());
2379 2402
2380 size_t num_gutter_quads = 0; 2403 size_t num_gutter_quads = 0;
2381 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) 2404 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2382 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material == 2405 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material ==
2383 DrawQuad::SOLID_COLOR) ? 1 : 0; 2406 DrawQuad::SOLID_COLOR) ? 1 : 0;
2384 EXPECT_EQ(1u, num_gutter_quads); 2407 EXPECT_EQ(1u, num_gutter_quads);
2385 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); 2408 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size());
2386 2409
2387 LayerTestCommon::VerifyQuadsExactlyCoverRect( 2410 LayerTestCommon::VerifyQuadsExactlyCoverRect(
2388 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size)); 2411 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size));
2389 host_impl_->DidDrawAllLayers(frame); 2412 host_impl_->DidDrawAllLayers(frame);
2390 } 2413 }
2391 2414
2392 // Content area in middle of clip rect (four surrounding gutter rects) 2415 // Content area in middle of clip rect (four surrounding gutter rects)
2393 { 2416 {
2394 gfx::Rect layer_rect(500, 500, 200, 200); 2417 gfx::Rect layer_rect(500, 500, 200, 200);
2395 child->SetPosition(layer_rect.origin()); 2418 child->SetPosition(layer_rect.origin());
2396 child->SetBounds(layer_rect.size()); 2419 child->SetBounds(layer_rect.size());
2397 child->SetContentBounds(layer_rect.size()); 2420 child->SetContentBounds(layer_rect.size());
2398 child->SetQuadRect(gfx::Rect(layer_rect.size())); 2421 child->SetQuadRect(gfx::Rect(layer_rect.size()));
2399 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); 2422 child->SetQuadVisibleRect(gfx::Rect(layer_rect.size()));
2400 2423
2401 LayerTreeHostImpl::FrameData frame; 2424 LayerTreeHostImpl::FrameData frame;
2402 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2425 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2403 ASSERT_EQ(1u, frame.render_passes.size()); 2426 ASSERT_EQ(1u, frame.render_passes.size());
2404 2427
2405 size_t num_gutter_quads = 0; 2428 size_t num_gutter_quads = 0;
2406 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) 2429 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2407 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material == 2430 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material ==
2408 DrawQuad::SOLID_COLOR) ? 1 : 0; 2431 DrawQuad::SOLID_COLOR) ? 1 : 0;
2409 EXPECT_EQ(4u, num_gutter_quads); 2432 EXPECT_EQ(4u, num_gutter_quads);
2410 EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size()); 2433 EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size());
2411 2434
2412 LayerTestCommon::VerifyQuadsExactlyCoverRect( 2435 LayerTestCommon::VerifyQuadsExactlyCoverRect(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)) 2472 scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext))
2450 .PassAs<OutputSurface>(); 2473 .PassAs<OutputSurface>();
2451 ReshapeTrackerContext* reshape_tracker = 2474 ReshapeTrackerContext* reshape_tracker =
2452 static_cast<ReshapeTrackerContext*>(output_surface->context3d()); 2475 static_cast<ReshapeTrackerContext*>(output_surface->context3d());
2453 host_impl_->InitializeRenderer(output_surface.Pass()); 2476 host_impl_->InitializeRenderer(output_surface.Pass());
2454 2477
2455 scoped_ptr<LayerImpl> root = 2478 scoped_ptr<LayerImpl> root =
2456 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); 2479 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1);
2457 root->SetAnchorPoint(gfx::PointF()); 2480 root->SetAnchorPoint(gfx::PointF());
2458 root->SetBounds(gfx::Size(10, 10)); 2481 root->SetBounds(gfx::Size(10, 10));
2482 root->SetContentBounds(gfx::Size(10, 10));
2459 root->SetDrawsContent(true); 2483 root->SetDrawsContent(true);
2460 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2484 host_impl_->active_tree()->SetRootLayer(root.Pass());
2461 EXPECT_FALSE(reshape_tracker->reshape_called()); 2485 EXPECT_FALSE(reshape_tracker->reshape_called());
2462 2486
2463 LayerTreeHostImpl::FrameData frame; 2487 LayerTreeHostImpl::FrameData frame;
2464 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2488 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2465 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2489 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2466 EXPECT_TRUE(reshape_tracker->reshape_called()); 2490 EXPECT_TRUE(reshape_tracker->reshape_called());
2467 host_impl_->DidDrawAllLayers(frame); 2491 host_impl_->DidDrawAllLayers(frame);
2468 } 2492 }
2469 2493
2470 class PartialSwapTrackerContext : public TestWebGraphicsContext3D { 2494 class PartialSwapTrackerContext : public TestWebGraphicsContext3D {
2471 public: 2495 public:
2472 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) 2496 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height)
2473 OVERRIDE { 2497 OVERRIDE {
2474 partial_swap_rect_ = gfx::Rect(x, y, width, height); 2498 partial_swap_rect_ = gfx::Rect(x, y, width, height);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 root->SetAnchorPoint(gfx::PointF()); 2547 root->SetAnchorPoint(gfx::PointF());
2524 root->SetBounds(gfx::Size(500, 500)); 2548 root->SetBounds(gfx::Size(500, 500));
2525 root->SetContentBounds(gfx::Size(500, 500)); 2549 root->SetContentBounds(gfx::Size(500, 500));
2526 root->SetDrawsContent(true); 2550 root->SetDrawsContent(true);
2527 root->AddChild(child.Pass()); 2551 root->AddChild(child.Pass());
2528 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass()); 2552 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass());
2529 2553
2530 LayerTreeHostImpl::FrameData frame; 2554 LayerTreeHostImpl::FrameData frame;
2531 2555
2532 // First frame, the entire screen should get swapped. 2556 // First frame, the entire screen should get swapped.
2533 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame)); 2557 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect()));
2534 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 2558 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
2535 layer_tree_host_impl->DidDrawAllLayers(frame); 2559 layer_tree_host_impl->DidDrawAllLayers(frame);
2536 layer_tree_host_impl->SwapBuffers(); 2560 layer_tree_host_impl->SwapBuffers(frame);
2537 gfx::Rect actual_swap_rect = partial_swap_tracker->partial_swap_rect(); 2561 gfx::Rect actual_swap_rect = partial_swap_tracker->partial_swap_rect();
2538 gfx::Rect expected_swap_rect = gfx::Rect(0, 0, 500, 500); 2562 gfx::Rect expected_swap_rect = gfx::Rect(0, 0, 500, 500);
2539 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); 2563 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x());
2540 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); 2564 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y());
2541 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); 2565 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width());
2542 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); 2566 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height());
2543 2567
2544 // Second frame, only the damaged area should get swapped. Damage should be 2568 // Second frame, only the damaged area should get swapped. Damage should be
2545 // the union of old and new child rects. 2569 // the union of old and new child rects.
2546 // expected damage rect: gfx::Rect(26, 28); 2570 // expected damage rect: gfx::Rect(26, 28);
2547 // expected swap rect: vertically flipped, with origin at bottom left corner. 2571 // expected swap rect: vertically flipped, with origin at bottom left corner.
2548 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition( 2572 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition(
2549 gfx::PointF()); 2573 gfx::PointF());
2550 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame)); 2574 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect()));
2551 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 2575 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
2552 host_impl_->DidDrawAllLayers(frame); 2576 host_impl_->DidDrawAllLayers(frame);
2553 layer_tree_host_impl->SwapBuffers(); 2577 layer_tree_host_impl->SwapBuffers(frame);
2554 actual_swap_rect = partial_swap_tracker->partial_swap_rect(); 2578 actual_swap_rect = partial_swap_tracker->partial_swap_rect();
2555 expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); 2579 expected_swap_rect = gfx::Rect(0, 500-28, 26, 28);
2556 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); 2580 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x());
2557 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); 2581 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y());
2558 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); 2582 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width());
2559 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); 2583 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height());
2560 2584
2561 // Make sure that partial swap is constrained to the viewport dimensions 2585 // Make sure that partial swap is constrained to the viewport dimensions
2562 // expected damage rect: gfx::Rect(500, 500); 2586 // expected damage rect: gfx::Rect(500, 500);
2563 // expected swap rect: flipped damage rect, but also clamped to viewport 2587 // expected swap rect: flipped damage rect, but also clamped to viewport
2564 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 2588 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
2565 // This will damage everything. 2589 // This will damage everything.
2566 layer_tree_host_impl->active_tree()->root_layer()->SetOpacity(0.7f); 2590 layer_tree_host_impl->active_tree()->root_layer()->SetOpacity(0.7f);
2567 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame)); 2591 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect()));
2568 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 2592 layer_tree_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
2569 host_impl_->DidDrawAllLayers(frame); 2593 host_impl_->DidDrawAllLayers(frame);
2570 layer_tree_host_impl->SwapBuffers(); 2594 layer_tree_host_impl->SwapBuffers(frame);
2571 actual_swap_rect = partial_swap_tracker->partial_swap_rect(); 2595 actual_swap_rect = partial_swap_tracker->partial_swap_rect();
2572 expected_swap_rect = gfx::Rect(10, 10); 2596 expected_swap_rect = gfx::Rect(10, 10);
2573 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); 2597 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x());
2574 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); 2598 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y());
2575 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); 2599 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width());
2576 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); 2600 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height());
2577 } 2601 }
2578 2602
2579 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { 2603 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) {
2580 scoped_ptr<LayerImpl> root = 2604 scoped_ptr<LayerImpl> root =
2581 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); 2605 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1);
2582 scoped_ptr<LayerImpl> child = 2606 scoped_ptr<LayerImpl> child =
2583 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); 2607 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2);
2584 child->SetAnchorPoint(gfx::PointF()); 2608 child->SetAnchorPoint(gfx::PointF());
2585 child->SetBounds(gfx::Size(10, 10)); 2609 child->SetBounds(gfx::Size(10, 10));
2586 child->SetContentBounds(gfx::Size(10, 10)); 2610 child->SetContentBounds(gfx::Size(10, 10));
2587 child->SetDrawsContent(true); 2611 child->SetDrawsContent(true);
2588 root->SetAnchorPoint(gfx::PointF()); 2612 root->SetAnchorPoint(gfx::PointF());
2589 root->SetBounds(gfx::Size(10, 10)); 2613 root->SetBounds(gfx::Size(10, 10));
2590 root->SetContentBounds(gfx::Size(10, 10)); 2614 root->SetContentBounds(gfx::Size(10, 10));
2591 root->SetDrawsContent(true); 2615 root->SetDrawsContent(true);
2592 root->SetOpacity(0.7f); 2616 root->SetOpacity(0.7f);
2593 root->AddChild(child.Pass()); 2617 root->AddChild(child.Pass());
2594 2618
2595 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2619 host_impl_->active_tree()->SetRootLayer(root.Pass());
2596 2620
2597 LayerTreeHostImpl::FrameData frame; 2621 LayerTreeHostImpl::FrameData frame;
2598 2622
2599 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2623 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2600 EXPECT_EQ(1u, frame.render_surface_layer_list->size()); 2624 EXPECT_EQ(1u, frame.render_surface_layer_list->size());
2601 EXPECT_EQ(1u, frame.render_passes.size()); 2625 EXPECT_EQ(1u, frame.render_passes.size());
2602 host_impl_->DidDrawAllLayers(frame); 2626 host_impl_->DidDrawAllLayers(frame);
2603 } 2627 }
2604 2628
2605 class FakeLayerWithQuads : public LayerImpl { 2629 class FakeLayerWithQuads : public LayerImpl {
2606 public: 2630 public:
2607 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { 2631 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
2608 return scoped_ptr<LayerImpl>(new FakeLayerWithQuads(tree_impl, id)); 2632 return scoped_ptr<LayerImpl>(new FakeLayerWithQuads(tree_impl, id));
2609 } 2633 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 2759
2736 // Run test case 2760 // Run test case
2737 CreateLayerTreeHost(false, output_surface.Pass()); 2761 CreateLayerTreeHost(false, output_surface.Pass());
2738 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); 2762 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1));
2739 2763
2740 // Without partial swap, and no clipping, no scissor is set. 2764 // Without partial swap, and no clipping, no scissor is set.
2741 harness.MustDrawSolidQuad(); 2765 harness.MustDrawSolidQuad();
2742 harness.MustSetNoScissor(); 2766 harness.MustSetNoScissor();
2743 { 2767 {
2744 LayerTreeHostImpl::FrameData frame; 2768 LayerTreeHostImpl::FrameData frame;
2745 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2769 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2746 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2770 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2747 host_impl_->DidDrawAllLayers(frame); 2771 host_impl_->DidDrawAllLayers(frame);
2748 } 2772 }
2749 Mock::VerifyAndClearExpectations(&mock_context); 2773 Mock::VerifyAndClearExpectations(&mock_context);
2750 2774
2751 // Without partial swap, but a layer does clip its subtree, one scissor is 2775 // Without partial swap, but a layer does clip its subtree, one scissor is
2752 // set. 2776 // set.
2753 host_impl_->active_tree()->root_layer()->SetMasksToBounds(true); 2777 host_impl_->active_tree()->root_layer()->SetMasksToBounds(true);
2754 harness.MustDrawSolidQuad(); 2778 harness.MustDrawSolidQuad();
2755 harness.MustSetScissor(0, 0, 10, 10); 2779 harness.MustSetScissor(0, 0, 10, 10);
2756 { 2780 {
2757 LayerTreeHostImpl::FrameData frame; 2781 LayerTreeHostImpl::FrameData frame;
2758 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2782 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2759 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2783 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2760 host_impl_->DidDrawAllLayers(frame); 2784 host_impl_->DidDrawAllLayers(frame);
2761 } 2785 }
2762 Mock::VerifyAndClearExpectations(&mock_context); 2786 Mock::VerifyAndClearExpectations(&mock_context);
2763 } 2787 }
2764 2788
2765 TEST_F(LayerTreeHostImplTest, PartialSwap) { 2789 TEST_F(LayerTreeHostImplTest, PartialSwap) {
2766 scoped_ptr<OutputSurface> output_surface = 2790 scoped_ptr<OutputSurface> output_surface =
2767 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 2791 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
2768 new MockContext)).PassAs<OutputSurface>(); 2792 new MockContext)).PassAs<OutputSurface>();
2769 MockContext* mock_context = 2793 MockContext* mock_context =
2770 static_cast<MockContext*>(output_surface->context3d()); 2794 static_cast<MockContext*>(output_surface->context3d());
2771 MockContextHarness harness(mock_context); 2795 MockContextHarness harness(mock_context);
2772 2796
2773 CreateLayerTreeHost(true, output_surface.Pass()); 2797 CreateLayerTreeHost(true, output_surface.Pass());
2774 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); 2798 SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1));
2775 2799
2776 // The first frame is not a partially-swapped one. 2800 // The first frame is not a partially-swapped one.
2777 harness.MustSetScissor(0, 0, 10, 10); 2801 harness.MustSetScissor(0, 0, 10, 10);
2778 harness.MustDrawSolidQuad(); 2802 harness.MustDrawSolidQuad();
2779 { 2803 {
2780 LayerTreeHostImpl::FrameData frame; 2804 LayerTreeHostImpl::FrameData frame;
2781 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2805 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2782 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2806 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2783 host_impl_->DidDrawAllLayers(frame); 2807 host_impl_->DidDrawAllLayers(frame);
2784 } 2808 }
2785 Mock::VerifyAndClearExpectations(&mock_context); 2809 Mock::VerifyAndClearExpectations(&mock_context);
2786 2810
2787 // Damage a portion of the frame. 2811 // Damage a portion of the frame.
2788 host_impl_->active_tree()->root_layer()->set_update_rect( 2812 host_impl_->active_tree()->root_layer()->set_update_rect(
2789 gfx::Rect(0, 0, 2, 3)); 2813 gfx::Rect(0, 0, 2, 3));
2790 2814
2791 // The second frame will be partially-swapped (the y coordinates are flipped). 2815 // The second frame will be partially-swapped (the y coordinates are flipped).
2792 harness.MustSetScissor(0, 7, 2, 3); 2816 harness.MustSetScissor(0, 7, 2, 3);
2793 harness.MustDrawSolidQuad(); 2817 harness.MustDrawSolidQuad();
2794 { 2818 {
2795 LayerTreeHostImpl::FrameData frame; 2819 LayerTreeHostImpl::FrameData frame;
2796 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 2820 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
2797 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 2821 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
2798 host_impl_->DidDrawAllLayers(frame); 2822 host_impl_->DidDrawAllLayers(frame);
2799 } 2823 }
2800 Mock::VerifyAndClearExpectations(&mock_context); 2824 Mock::VerifyAndClearExpectations(&mock_context);
2801 } 2825 }
2802 2826
2803 class PartialSwapContext : public TestWebGraphicsContext3D { 2827 class PartialSwapContext : public TestWebGraphicsContext3D {
2804 public: 2828 public:
2805 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE { 2829 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE {
2806 if (name == GL_EXTENSIONS) 2830 if (name == GL_EXTENSIONS)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 2919
2896 my_host_impl->active_tree()->SetRootLayer(root.Pass()); 2920 my_host_impl->active_tree()->SetRootLayer(root.Pass());
2897 return my_host_impl.Pass(); 2921 return my_host_impl.Pass();
2898 } 2922 }
2899 2923
2900 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { 2924 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) {
2901 scoped_ptr<LayerTreeHostImpl> my_host_impl = 2925 scoped_ptr<LayerTreeHostImpl> my_host_impl =
2902 SetupLayersForOpacity(true, this, &proxy_, &stats_instrumentation_); 2926 SetupLayersForOpacity(true, this, &proxy_, &stats_instrumentation_);
2903 { 2927 {
2904 LayerTreeHostImpl::FrameData frame; 2928 LayerTreeHostImpl::FrameData frame;
2905 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 2929 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
2906 2930
2907 // Verify all quads have been computed 2931 // Verify all quads have been computed
2908 ASSERT_EQ(2U, frame.render_passes.size()); 2932 ASSERT_EQ(2U, frame.render_passes.size());
2909 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); 2933 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size());
2910 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); 2934 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size());
2911 EXPECT_EQ(DrawQuad::SOLID_COLOR, 2935 EXPECT_EQ(DrawQuad::SOLID_COLOR,
2912 frame.render_passes[0]->quad_list[0]->material); 2936 frame.render_passes[0]->quad_list[0]->material);
2913 EXPECT_EQ(DrawQuad::RENDER_PASS, 2937 EXPECT_EQ(DrawQuad::RENDER_PASS,
2914 frame.render_passes[1]->quad_list[0]->material); 2938 frame.render_passes[1]->quad_list[0]->material);
2915 2939
2916 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 2940 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
2917 my_host_impl->DidDrawAllLayers(frame); 2941 my_host_impl->DidDrawAllLayers(frame);
2918 } 2942 }
2919 } 2943 }
2920 2944
2921 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { 2945 TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) {
2922 scoped_ptr<LayerTreeHostImpl> my_host_impl = 2946 scoped_ptr<LayerTreeHostImpl> my_host_impl =
2923 SetupLayersForOpacity(false, this, &proxy_, &stats_instrumentation_); 2947 SetupLayersForOpacity(false, this, &proxy_, &stats_instrumentation_);
2924 { 2948 {
2925 LayerTreeHostImpl::FrameData frame; 2949 LayerTreeHostImpl::FrameData frame;
2926 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 2950 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
2927 2951
2928 // Verify all quads have been computed 2952 // Verify all quads have been computed
2929 ASSERT_EQ(2U, frame.render_passes.size()); 2953 ASSERT_EQ(2U, frame.render_passes.size());
2930 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); 2954 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size());
2931 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); 2955 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size());
2932 EXPECT_EQ(DrawQuad::SOLID_COLOR, 2956 EXPECT_EQ(DrawQuad::SOLID_COLOR,
2933 frame.render_passes[0]->quad_list[0]->material); 2957 frame.render_passes[0]->quad_list[0]->material);
2934 EXPECT_EQ(DrawQuad::RENDER_PASS, 2958 EXPECT_EQ(DrawQuad::RENDER_PASS,
2935 frame.render_passes[1]->quad_list[0]->material); 2959 frame.render_passes[1]->quad_list[0]->material);
2936 2960
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 io_surface_layer->SetContentBounds(gfx::Size(10, 10)); 3047 io_surface_layer->SetContentBounds(gfx::Size(10, 10));
3024 io_surface_layer->SetDrawsContent(true); 3048 io_surface_layer->SetDrawsContent(true);
3025 io_surface_layer->SetIOSurfaceProperties(1, gfx::Size(10, 10)); 3049 io_surface_layer->SetIOSurfaceProperties(1, gfx::Size(10, 10));
3026 root_layer->AddChild(io_surface_layer.PassAs<LayerImpl>()); 3050 root_layer->AddChild(io_surface_layer.PassAs<LayerImpl>());
3027 3051
3028 host_impl_->active_tree()->SetRootLayer(root_layer.Pass()); 3052 host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
3029 3053
3030 EXPECT_EQ(0u, context3d->NumTextures()); 3054 EXPECT_EQ(0u, context3d->NumTextures());
3031 3055
3032 LayerTreeHostImpl::FrameData frame; 3056 LayerTreeHostImpl::FrameData frame;
3033 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 3057 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
3034 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 3058 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
3035 host_impl_->DidDrawAllLayers(frame); 3059 host_impl_->DidDrawAllLayers(frame);
3036 host_impl_->SwapBuffers(); 3060 host_impl_->SwapBuffers(frame);
3037 3061
3038 EXPECT_GT(context3d->NumTextures(), 0u); 3062 EXPECT_GT(context3d->NumTextures(), 0u);
3039 3063
3040 // Kill the layer tree. 3064 // Kill the layer tree.
3041 host_impl_->active_tree()->SetRootLayer( 3065 host_impl_->active_tree()->SetRootLayer(
3042 LayerImpl::Create(host_impl_->active_tree(), 100)); 3066 LayerImpl::Create(host_impl_->active_tree(), 100));
3043 // There should be no textures left in use after. 3067 // There should be no textures left in use after.
3044 EXPECT_EQ(0u, context3d->NumTextures()); 3068 EXPECT_EQ(0u, context3d->NumTextures());
3045 } 3069 }
3046 3070
(...skipping 19 matching lines...) Expand all
3066 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); 3090 SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
3067 host_impl_->active_tree()->set_background_color(SK_ColorWHITE); 3091 host_impl_->active_tree()->set_background_color(SK_ColorWHITE);
3068 3092
3069 // Verify one quad is drawn when transparent background set is not set. 3093 // Verify one quad is drawn when transparent background set is not set.
3070 host_impl_->active_tree()->set_has_transparent_background(false); 3094 host_impl_->active_tree()->set_has_transparent_background(false);
3071 EXPECT_CALL(*mock_context, useProgram(_)) 3095 EXPECT_CALL(*mock_context, useProgram(_))
3072 .Times(1); 3096 .Times(1);
3073 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)) 3097 EXPECT_CALL(*mock_context, drawElements(_, _, _, _))
3074 .Times(1); 3098 .Times(1);
3075 LayerTreeHostImpl::FrameData frame; 3099 LayerTreeHostImpl::FrameData frame;
3076 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 3100 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
3077 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 3101 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
3078 host_impl_->DidDrawAllLayers(frame); 3102 host_impl_->DidDrawAllLayers(frame);
3079 Mock::VerifyAndClearExpectations(&mock_context); 3103 Mock::VerifyAndClearExpectations(&mock_context);
3080 3104
3081 // Verify no quads are drawn when transparent background is set. 3105 // Verify no quads are drawn when transparent background is set.
3082 host_impl_->active_tree()->set_has_transparent_background(true); 3106 host_impl_->active_tree()->set_has_transparent_background(true);
3083 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 3107 host_impl_->SetFullRootLayerDamage();
3108 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
3084 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 3109 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
3085 host_impl_->DidDrawAllLayers(frame); 3110 host_impl_->DidDrawAllLayers(frame);
3086 Mock::VerifyAndClearExpectations(&mock_context); 3111 Mock::VerifyAndClearExpectations(&mock_context);
3087 } 3112 }
3088 3113
3089 static void AddDrawingLayerTo(LayerImpl* parent, 3114 static void AddDrawingLayerTo(LayerImpl* parent,
3090 int id, 3115 int id,
3091 gfx::Rect layer_rect, 3116 gfx::Rect layer_rect,
3092 LayerImpl** result) { 3117 LayerImpl** result) {
3093 scoped_ptr<LayerImpl> layer = 3118 scoped_ptr<LayerImpl> layer =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 3243 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12
3219 3244
3220 AddDrawingLayerTo(root_ptr, 5, gfx::Rect(550, 250, 300, 400), &layer_s2_ptr); 3245 AddDrawingLayerTo(root_ptr, 5, gfx::Rect(550, 250, 300, 400), &layer_s2_ptr);
3221 layer_s2_ptr->SetForceRenderSurface(true); 3246 layer_s2_ptr->SetForceRenderSurface(true);
3222 3247
3223 AddDrawingLayerTo(layer_s2_ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 3248 AddDrawingLayerTo(layer_s2_ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21
3224 3249
3225 // Initial draw - must receive all quads 3250 // Initial draw - must receive all quads
3226 { 3251 {
3227 LayerTreeHostImpl::FrameData frame; 3252 LayerTreeHostImpl::FrameData frame;
3228 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3253 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3229 3254
3230 // Must receive 3 render passes. 3255 // Must receive 3 render passes.
3231 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded); 3256 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded);
3232 // for S2, there is 2 quads. 3257 // for S2, there is 2 quads.
3233 ASSERT_EQ(3U, frame.render_passes.size()); 3258 ASSERT_EQ(3U, frame.render_passes.size());
3234 3259
3235 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3260 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3236 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3261 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3237 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); 3262 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3238 3263
3239 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3264 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3240 my_host_impl->DidDrawAllLayers(frame); 3265 my_host_impl->DidDrawAllLayers(frame);
3241 } 3266 }
3242 3267
3243 // "Unocclude" surface S1 and repeat draw. 3268 // "Unocclude" surface S1 and repeat draw.
3244 // Must remove S2's render pass since it's cached; 3269 // Must remove S2's render pass since it's cached;
3245 // Must keep S1 quads because texture contained external occlusion. 3270 // Must keep S1 quads because texture contained external occlusion.
3246 gfx::Transform transform = layer_s2_ptr->transform(); 3271 gfx::Transform transform = layer_s2_ptr->transform();
3247 transform.Translate(150.0, 150.0); 3272 transform.Translate(150.0, 150.0);
3248 layer_s2_ptr->SetTransform(transform); 3273 layer_s2_ptr->SetTransform(transform);
3249 { 3274 {
3250 LayerTreeHostImpl::FrameData frame; 3275 LayerTreeHostImpl::FrameData frame;
3251 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3276 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3252 3277
3253 // Must receive 2 render passes. 3278 // Must receive 2 render passes.
3254 // For Root, there are 2 quads 3279 // For Root, there are 2 quads
3255 // For S1, the number of quads depends on what got unoccluded, so not 3280 // For S1, the number of quads depends on what got unoccluded, so not
3256 // asserted beyond being positive. 3281 // asserted beyond being positive.
3257 // For S2, there is no render pass 3282 // For S2, there is no render pass
3258 ASSERT_EQ(2U, frame.render_passes.size()); 3283 ASSERT_EQ(2U, frame.render_passes.size());
3259 3284
3260 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); 3285 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
3261 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3286 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3262 3287
3263 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3288 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3264 my_host_impl->DidDrawAllLayers(frame); 3289 my_host_impl->DidDrawAllLayers(frame);
3265 } 3290 }
3266 3291
3267 // "Re-occlude" surface S1 and repeat draw. 3292 // "Re-occlude" surface S1 and repeat draw.
3268 // Must remove S1's render pass since it is now available in full. 3293 // Must remove S1's render pass since it is now available in full.
3269 // S2 has no change so must also be removed. 3294 // S2 has no change so must also be removed.
3270 transform = layer_s2_ptr->transform(); 3295 transform = layer_s2_ptr->transform();
3271 transform.Translate(-15.0, -15.0); 3296 transform.Translate(-15.0, -15.0);
3272 layer_s2_ptr->SetTransform(transform); 3297 layer_s2_ptr->SetTransform(transform);
3273 { 3298 {
3274 LayerTreeHostImpl::FrameData frame; 3299 LayerTreeHostImpl::FrameData frame;
3275 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3300 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3276 3301
3277 // Must receive 1 render pass - for the root. 3302 // Must receive 1 render pass - for the root.
3278 ASSERT_EQ(1U, frame.render_passes.size()); 3303 ASSERT_EQ(1U, frame.render_passes.size());
3279 3304
3280 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3305 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3281 3306
3282 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3307 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3283 my_host_impl->DidDrawAllLayers(frame); 3308 my_host_impl->DidDrawAllLayers(frame);
3284 } 3309 }
3285 3310
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 AddDrawingLayerTo(layer_s1_ptr, 5, gfx::Rect(500, 0, 300, 300), 0); // L13 3365 AddDrawingLayerTo(layer_s1_ptr, 5, gfx::Rect(500, 0, 300, 300), 0); // L13
3341 AddDrawingLayerTo(layer_s1_ptr, 6, gfx::Rect(500, 500, 300, 300), 0); // L14 3366 AddDrawingLayerTo(layer_s1_ptr, 6, gfx::Rect(500, 500, 300, 300), 0); // L14
3342 AddDrawingLayerTo(layer_s1_ptr, 9, gfx::Rect(500, 500, 300, 300), 0); // L14 3367 AddDrawingLayerTo(layer_s1_ptr, 9, gfx::Rect(500, 500, 300, 300), 0); // L14
3343 3368
3344 AddDrawingLayerTo(root_ptr, 7, gfx::Rect(450, 450, 450, 450), &layer_s2_ptr); 3369 AddDrawingLayerTo(root_ptr, 7, gfx::Rect(450, 450, 450, 450), &layer_s2_ptr);
3345 layer_s2_ptr->SetForceRenderSurface(true); 3370 layer_s2_ptr->SetForceRenderSurface(true);
3346 3371
3347 // Initial draw - must receive all quads 3372 // Initial draw - must receive all quads
3348 { 3373 {
3349 LayerTreeHostImpl::FrameData frame; 3374 LayerTreeHostImpl::FrameData frame;
3350 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3375 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3351 3376
3352 // Must receive 3 render passes. 3377 // Must receive 3 render passes.
3353 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 3378 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is
3354 // 1 quad. 3379 // 1 quad.
3355 ASSERT_EQ(3U, frame.render_passes.size()); 3380 ASSERT_EQ(3U, frame.render_passes.size());
3356 3381
3357 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3382 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3358 3383
3359 // L14 is culled, so only 3 quads. 3384 // L14 is culled, so only 3 quads.
3360 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size()); 3385 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size());
3361 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); 3386 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3362 3387
3363 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3388 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3364 my_host_impl->DidDrawAllLayers(frame); 3389 my_host_impl->DidDrawAllLayers(frame);
3365 } 3390 }
3366 3391
3367 // "Unocclude" surface S1 and repeat draw. 3392 // "Unocclude" surface S1 and repeat draw.
3368 // Must remove S2's render pass since it's cached; 3393 // Must remove S2's render pass since it's cached;
3369 // Must keep S1 quads because texture contained external occlusion. 3394 // Must keep S1 quads because texture contained external occlusion.
3370 gfx::Transform transform = layer_s2_ptr->transform(); 3395 gfx::Transform transform = layer_s2_ptr->transform();
3371 transform.Translate(100.0, 100.0); 3396 transform.Translate(100.0, 100.0);
3372 layer_s2_ptr->SetTransform(transform); 3397 layer_s2_ptr->SetTransform(transform);
3373 { 3398 {
3374 LayerTreeHostImpl::FrameData frame; 3399 LayerTreeHostImpl::FrameData frame;
3375 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3400 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3376 3401
3377 // Must receive 2 render passes. 3402 // Must receive 2 render passes.
3378 // For Root, there are 2 quads 3403 // For Root, there are 2 quads
3379 // For S1, the number of quads depends on what got unoccluded, so not 3404 // For S1, the number of quads depends on what got unoccluded, so not
3380 // asserted beyond being positive. 3405 // asserted beyond being positive.
3381 // For S2, there is no render pass 3406 // For S2, there is no render pass
3382 ASSERT_EQ(2U, frame.render_passes.size()); 3407 ASSERT_EQ(2U, frame.render_passes.size());
3383 3408
3384 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); 3409 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
3385 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3410 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3386 3411
3387 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3412 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3388 my_host_impl->DidDrawAllLayers(frame); 3413 my_host_impl->DidDrawAllLayers(frame);
3389 } 3414 }
3390 3415
3391 // "Re-occlude" surface S1 and repeat draw. 3416 // "Re-occlude" surface S1 and repeat draw.
3392 // Must remove S1's render pass since it is now available in full. 3417 // Must remove S1's render pass since it is now available in full.
3393 // S2 has no change so must also be removed. 3418 // S2 has no change so must also be removed.
3394 transform = layer_s2_ptr->transform(); 3419 transform = layer_s2_ptr->transform();
3395 transform.Translate(-15.0, -15.0); 3420 transform.Translate(-15.0, -15.0);
3396 layer_s2_ptr->SetTransform(transform); 3421 layer_s2_ptr->SetTransform(transform);
3397 { 3422 {
3398 LayerTreeHostImpl::FrameData frame; 3423 LayerTreeHostImpl::FrameData frame;
3399 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3424 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3400 3425
3401 // Must receive 1 render pass - for the root. 3426 // Must receive 1 render pass - for the root.
3402 ASSERT_EQ(1U, frame.render_passes.size()); 3427 ASSERT_EQ(1U, frame.render_passes.size());
3403 3428
3404 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3429 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3405 3430
3406 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3431 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3407 my_host_impl->DidDrawAllLayers(frame); 3432 my_host_impl->DidDrawAllLayers(frame);
3408 } 3433 }
3409 } 3434 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3457 3482
3458 AddDrawingLayerTo(layer_s1_ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11 3483 AddDrawingLayerTo(layer_s1_ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11
3459 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(100, 0, 300, 300), 0); // L12 3484 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(100, 0, 300, 300), 0); // L12
3460 3485
3461 AddDrawingLayerTo(root_ptr, 7, gfx::Rect(200, 0, 300, 300), &layer_s2_ptr); 3486 AddDrawingLayerTo(root_ptr, 7, gfx::Rect(200, 0, 300, 300), &layer_s2_ptr);
3462 layer_s2_ptr->SetForceRenderSurface(true); 3487 layer_s2_ptr->SetForceRenderSurface(true);
3463 3488
3464 // Initial draw - must receive all quads 3489 // Initial draw - must receive all quads
3465 { 3490 {
3466 LayerTreeHostImpl::FrameData frame; 3491 LayerTreeHostImpl::FrameData frame;
3467 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3492 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3468 3493
3469 // Must receive 3 render passes. 3494 // Must receive 3 render passes.
3470 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 3495 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is
3471 // 1 quad. 3496 // 1 quad.
3472 ASSERT_EQ(3U, frame.render_passes.size()); 3497 ASSERT_EQ(3U, frame.render_passes.size());
3473 3498
3474 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3499 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3475 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size()); 3500 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size());
3476 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); 3501 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3477 3502
3478 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3503 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3479 my_host_impl->DidDrawAllLayers(frame); 3504 my_host_impl->DidDrawAllLayers(frame);
3480 } 3505 }
3481 3506
3482 // "Unocclude" surface S1 and repeat draw. 3507 // "Unocclude" surface S1 and repeat draw.
3483 // Must remove S2's render pass since it's cached; 3508 // Must remove S2's render pass since it's cached;
3484 // Must keep S1 quads because texture contained external occlusion. 3509 // Must keep S1 quads because texture contained external occlusion.
3485 gfx::Transform transform = layer_s2_ptr->transform(); 3510 gfx::Transform transform = layer_s2_ptr->transform();
3486 transform.Translate(300.0, 0.0); 3511 transform.Translate(300.0, 0.0);
3487 layer_s2_ptr->SetTransform(transform); 3512 layer_s2_ptr->SetTransform(transform);
3488 { 3513 {
3489 LayerTreeHostImpl::FrameData frame; 3514 LayerTreeHostImpl::FrameData frame;
3490 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3515 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3491 3516
3492 // Must receive 2 render passes. 3517 // Must receive 2 render passes.
3493 // For Root, there are 2 quads 3518 // For Root, there are 2 quads
3494 // For S1, the number of quads depends on what got unoccluded, so not 3519 // For S1, the number of quads depends on what got unoccluded, so not
3495 // asserted beyond being positive. 3520 // asserted beyond being positive.
3496 // For S2, there is no render pass 3521 // For S2, there is no render pass
3497 ASSERT_EQ(2U, frame.render_passes.size()); 3522 ASSERT_EQ(2U, frame.render_passes.size());
3498 3523
3499 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U); 3524 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
3500 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3525 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3548 transform.Translate(200.0, 200.0); 3573 transform.Translate(200.0, 200.0);
3549 transform.Rotate(45.0); 3574 transform.Rotate(45.0);
3550 transform.Translate(-200.0, -200.0); 3575 transform.Translate(-200.0, -200.0);
3551 layer_s1_ptr->SetTransform(transform); 3576 layer_s1_ptr->SetTransform(transform);
3552 3577
3553 AddDrawingLayerTo(layer_s1_ptr, 3, gfx::Rect(200, 0, 200, 400), 0); // L11 3578 AddDrawingLayerTo(layer_s1_ptr, 3, gfx::Rect(200, 0, 200, 400), 0); // L11
3554 3579
3555 // Initial draw - must receive all quads 3580 // Initial draw - must receive all quads
3556 { 3581 {
3557 LayerTreeHostImpl::FrameData frame; 3582 LayerTreeHostImpl::FrameData frame;
3558 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3583 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3559 3584
3560 // Must receive 2 render passes. 3585 // Must receive 2 render passes.
3561 ASSERT_EQ(2U, frame.render_passes.size()); 3586 ASSERT_EQ(2U, frame.render_passes.size());
3562 3587
3563 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3588 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3564 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); 3589 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3565 3590
3566 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3591 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3567 my_host_impl->DidDrawAllLayers(frame); 3592 my_host_impl->DidDrawAllLayers(frame);
3568 } 3593 }
3569 3594
3570 // Change opacity and draw. Verify we used cached texture. 3595 // Change opacity and draw. Verify we used cached texture.
3571 layer_s1_ptr->SetOpacity(0.2f); 3596 layer_s1_ptr->SetOpacity(0.2f);
3572 { 3597 {
3573 LayerTreeHostImpl::FrameData frame; 3598 LayerTreeHostImpl::FrameData frame;
3574 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3599 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3575 3600
3576 // One render pass must be gone due to cached texture. 3601 // One render pass must be gone due to cached texture.
3577 ASSERT_EQ(1U, frame.render_passes.size()); 3602 ASSERT_EQ(1U, frame.render_passes.size());
3578 3603
3579 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3604 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3580 3605
3581 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3606 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3582 my_host_impl->DidDrawAllLayers(frame); 3607 my_host_impl->DidDrawAllLayers(frame);
3583 } 3608 }
3584 } 3609 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3640 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 3665 AddDrawingLayerTo(layer_s1_ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12
3641 3666
3642 AddDrawingLayerTo(root_ptr, 5, gfx::Rect(550, 250, 300, 400), &layer_s2_ptr); 3667 AddDrawingLayerTo(root_ptr, 5, gfx::Rect(550, 250, 300, 400), &layer_s2_ptr);
3643 layer_s2_ptr->SetForceRenderSurface(true); 3668 layer_s2_ptr->SetForceRenderSurface(true);
3644 3669
3645 AddDrawingLayerTo(layer_s2_ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 3670 AddDrawingLayerTo(layer_s2_ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21
3646 3671
3647 // Initial draw - must receive all quads 3672 // Initial draw - must receive all quads
3648 { 3673 {
3649 LayerTreeHostImpl::FrameData frame; 3674 LayerTreeHostImpl::FrameData frame;
3650 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3675 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3651 3676
3652 // Must receive 3 render passes. 3677 // Must receive 3 render passes.
3653 // For Root, there are 2 quads; for S1, there are 2 quads (one is occluded); 3678 // For Root, there are 2 quads; for S1, there are 2 quads (one is occluded);
3654 // for S2, there is 2 quads. 3679 // for S2, there is 2 quads.
3655 ASSERT_EQ(3U, frame.render_passes.size()); 3680 ASSERT_EQ(3U, frame.render_passes.size());
3656 3681
3657 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3682 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3658 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3683 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3659 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size()); 3684 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3660 3685
3661 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3686 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3662 my_host_impl->DidDrawAllLayers(frame); 3687 my_host_impl->DidDrawAllLayers(frame);
3663 } 3688 }
3664 3689
3665 // "Unocclude" surface S1 and repeat draw. 3690 // "Unocclude" surface S1 and repeat draw.
3666 // Must remove S2's render pass since it's cached; 3691 // Must remove S2's render pass since it's cached;
3667 // Must keep S1 quads because texture contained external occlusion. 3692 // Must keep S1 quads because texture contained external occlusion.
3668 gfx::Transform transform = layer_s2_ptr->transform(); 3693 gfx::Transform transform = layer_s2_ptr->transform();
3669 transform.Translate(150.0, 150.0); 3694 transform.Translate(150.0, 150.0);
3670 layer_s2_ptr->SetTransform(transform); 3695 layer_s2_ptr->SetTransform(transform);
3671 { 3696 {
3672 LayerTreeHostImpl::FrameData frame; 3697 LayerTreeHostImpl::FrameData frame;
3673 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3698 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3674 3699
3675 // Must receive 2 render passes. 3700 // Must receive 2 render passes.
3676 // For Root, there are 2 quads. 3701 // For Root, there are 2 quads.
3677 // For S1, there are 2 quads. 3702 // For S1, there are 2 quads.
3678 // For S2, there is no render pass 3703 // For S2, there is no render pass
3679 ASSERT_EQ(2U, frame.render_passes.size()); 3704 ASSERT_EQ(2U, frame.render_passes.size());
3680 3705
3681 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); 3706 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3682 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size()); 3707 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3683 3708
3684 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3709 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3685 my_host_impl->DidDrawAllLayers(frame); 3710 my_host_impl->DidDrawAllLayers(frame);
3686 } 3711 }
3687 3712
3688 // "Re-occlude" surface S1 and repeat draw. 3713 // "Re-occlude" surface S1 and repeat draw.
3689 // Must remove S1's render pass since it is now available in full. 3714 // Must remove S1's render pass since it is now available in full.
3690 // S2 has no change so must also be removed. 3715 // S2 has no change so must also be removed.
3691 transform = layer_s2_ptr->transform(); 3716 transform = layer_s2_ptr->transform();
3692 transform.Translate(-15.0, -15.0); 3717 transform.Translate(-15.0, -15.0);
3693 layer_s2_ptr->SetTransform(transform); 3718 layer_s2_ptr->SetTransform(transform);
3694 { 3719 {
3695 LayerTreeHostImpl::FrameData frame; 3720 LayerTreeHostImpl::FrameData frame;
3696 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3721 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3697 3722
3698 // Root render pass only. 3723 // Root render pass only.
3699 ASSERT_EQ(1U, frame.render_passes.size()); 3724 ASSERT_EQ(1U, frame.render_passes.size());
3700 3725
3701 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3726 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3702 my_host_impl->DidDrawAllLayers(frame); 3727 my_host_impl->DidDrawAllLayers(frame);
3703 } 3728 }
3704 } 3729 }
3705 3730
3706 TEST_F(LayerTreeHostImplTest, TextureCachingWithScissor) { 3731 TEST_F(LayerTreeHostImplTest, TextureCachingWithScissor) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3780 3805
3781 child->AddChild(grand_child.Pass()); 3806 child->AddChild(grand_child.Pass());
3782 root->AddChild(child.PassAs<LayerImpl>()); 3807 root->AddChild(child.PassAs<LayerImpl>());
3783 my_host_impl->active_tree()->SetRootLayer(root.Pass()); 3808 my_host_impl->active_tree()->SetRootLayer(root.Pass());
3784 my_host_impl->SetViewportSize(root_rect.size(), root_rect.size()); 3809 my_host_impl->SetViewportSize(root_rect.size(), root_rect.size());
3785 3810
3786 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 3811 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
3787 child_pass_id)); 3812 child_pass_id));
3788 { 3813 {
3789 LayerTreeHostImpl::FrameData frame; 3814 LayerTreeHostImpl::FrameData frame;
3790 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3815 host_impl_->SetFullRootLayerDamage();
3816 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3791 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3817 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3792 my_host_impl->DidDrawAllLayers(frame); 3818 my_host_impl->DidDrawAllLayers(frame);
3793 } 3819 }
3794 3820
3795 // We should have cached textures for surface 2. 3821 // We should have cached textures for surface 2.
3796 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 3822 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
3797 child_pass_id)); 3823 child_pass_id));
3798 { 3824 {
3799 LayerTreeHostImpl::FrameData frame; 3825 LayerTreeHostImpl::FrameData frame;
3800 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3826 host_impl_->SetFullRootLayerDamage();
3827 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3801 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3828 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3802 my_host_impl->DidDrawAllLayers(frame); 3829 my_host_impl->DidDrawAllLayers(frame);
3803 } 3830 }
3804 3831
3805 // We should still have cached textures for surface 2 after drawing with no 3832 // We should still have cached textures for surface 2 after drawing with no
3806 // damage. 3833 // damage.
3807 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 3834 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
3808 child_pass_id)); 3835 child_pass_id));
3809 3836
3810 // Damage a single tile of surface 2. 3837 // Damage a single tile of surface 2.
3811 child_ptr->set_update_rect(gfx::Rect(10, 10, 10, 10)); 3838 child_ptr->set_update_rect(gfx::Rect(10, 10, 10, 10));
3812 { 3839 {
3813 LayerTreeHostImpl::FrameData frame; 3840 LayerTreeHostImpl::FrameData frame;
3814 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3841 host_impl_->SetFullRootLayerDamage();
3842 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3815 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3843 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3816 my_host_impl->DidDrawAllLayers(frame); 3844 my_host_impl->DidDrawAllLayers(frame);
3817 } 3845 }
3818 3846
3819 // We should have a cached texture for surface 2 again even though it was 3847 // We should have a cached texture for surface 2 again even though it was
3820 // damaged. 3848 // damaged.
3821 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 3849 EXPECT_TRUE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
3822 child_pass_id)); 3850 child_pass_id));
3823 } 3851 }
3824 3852
(...skipping 14 matching lines...) Expand all
3839 LayerImpl* child_ptr; 3867 LayerImpl* child_ptr;
3840 3868
3841 SetupLayersForTextureCaching(my_host_impl.get(), 3869 SetupLayersForTextureCaching(my_host_impl.get(),
3842 root_ptr, 3870 root_ptr,
3843 intermediate_layer_ptr, 3871 intermediate_layer_ptr,
3844 surface_layer_ptr, 3872 surface_layer_ptr,
3845 child_ptr, 3873 child_ptr,
3846 gfx::Size(100, 100)); 3874 gfx::Size(100, 100));
3847 { 3875 {
3848 LayerTreeHostImpl::FrameData frame; 3876 LayerTreeHostImpl::FrameData frame;
3849 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3877 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3850 3878
3851 // Must receive two render passes, each with one quad 3879 // Must receive two render passes, each with one quad
3852 ASSERT_EQ(2U, frame.render_passes.size()); 3880 ASSERT_EQ(2U, frame.render_passes.size());
3853 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3881 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3854 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); 3882 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3855 3883
3856 EXPECT_EQ(DrawQuad::RENDER_PASS, 3884 EXPECT_EQ(DrawQuad::RENDER_PASS,
3857 frame.render_passes[1]->quad_list[0]->material); 3885 frame.render_passes[1]->quad_list[0]->material);
3858 const RenderPassDrawQuad* quad = 3886 const RenderPassDrawQuad* quad =
3859 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 3887 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
3860 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 3888 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
3861 ASSERT_TRUE(target_pass); 3889 ASSERT_TRUE(target_pass);
3862 EXPECT_FALSE(target_pass->damage_rect.IsEmpty()); 3890 EXPECT_FALSE(target_pass->damage_rect.IsEmpty());
3863 3891
3864 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3892 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3865 my_host_impl->DidDrawAllLayers(frame); 3893 my_host_impl->DidDrawAllLayers(frame);
3866 } 3894 }
3867 3895
3868 // Draw without any change 3896 // Draw without any change
3869 { 3897 {
3870 LayerTreeHostImpl::FrameData frame; 3898 LayerTreeHostImpl::FrameData frame;
3871 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3899 host_impl_->SetFullRootLayerDamage();
3900 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3872 3901
3873 // Must receive one render pass, as the other one should be culled 3902 // Must receive one render pass, as the other one should be culled
3874 ASSERT_EQ(1U, frame.render_passes.size()); 3903 ASSERT_EQ(1U, frame.render_passes.size());
3875 3904
3876 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3905 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3877 EXPECT_EQ(DrawQuad::RENDER_PASS, 3906 EXPECT_EQ(DrawQuad::RENDER_PASS,
3878 frame.render_passes[0]->quad_list[0]->material); 3907 frame.render_passes[0]->quad_list[0]->material);
3879 const RenderPassDrawQuad* quad = 3908 const RenderPassDrawQuad* quad =
3880 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 3909 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
3881 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 3910 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
3882 frame.render_passes_by_id.end()); 3911 frame.render_passes_by_id.end());
3883 3912
3884 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3913 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3885 my_host_impl->DidDrawAllLayers(frame); 3914 my_host_impl->DidDrawAllLayers(frame);
3886 } 3915 }
3887 3916
3888 // Change opacity and draw 3917 // Change opacity and draw
3889 surface_layer_ptr->SetOpacity(0.6f); 3918 surface_layer_ptr->SetOpacity(0.6f);
3890 { 3919 {
3891 LayerTreeHostImpl::FrameData frame; 3920 LayerTreeHostImpl::FrameData frame;
3892 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3921 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3893 3922
3894 // Must receive one render pass, as the other one should be culled 3923 // Must receive one render pass, as the other one should be culled
3895 ASSERT_EQ(1U, frame.render_passes.size()); 3924 ASSERT_EQ(1U, frame.render_passes.size());
3896 3925
3897 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3926 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3898 EXPECT_EQ(DrawQuad::RENDER_PASS, 3927 EXPECT_EQ(DrawQuad::RENDER_PASS,
3899 frame.render_passes[0]->quad_list[0]->material); 3928 frame.render_passes[0]->quad_list[0]->material);
3900 const RenderPassDrawQuad* quad = 3929 const RenderPassDrawQuad* quad =
3901 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 3930 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
3902 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 3931 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
3903 frame.render_passes_by_id.end()); 3932 frame.render_passes_by_id.end());
3904 3933
3905 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3934 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3906 my_host_impl->DidDrawAllLayers(frame); 3935 my_host_impl->DidDrawAllLayers(frame);
3907 } 3936 }
3908 3937
3909 // Change less benign property and draw - should have contents changed flag 3938 // Change less benign property and draw - should have contents changed flag
3910 surface_layer_ptr->SetStackingOrderChanged(true); 3939 surface_layer_ptr->SetStackingOrderChanged(true);
3911 { 3940 {
3912 LayerTreeHostImpl::FrameData frame; 3941 LayerTreeHostImpl::FrameData frame;
3913 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3942 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3914 3943
3915 // Must receive two render passes, each with one quad 3944 // Must receive two render passes, each with one quad
3916 ASSERT_EQ(2U, frame.render_passes.size()); 3945 ASSERT_EQ(2U, frame.render_passes.size());
3917 3946
3918 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3947 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3919 EXPECT_EQ(DrawQuad::SOLID_COLOR, 3948 EXPECT_EQ(DrawQuad::SOLID_COLOR,
3920 frame.render_passes[0]->quad_list[0]->material); 3949 frame.render_passes[0]->quad_list[0]->material);
3921 3950
3922 EXPECT_EQ(DrawQuad::RENDER_PASS, 3951 EXPECT_EQ(DrawQuad::RENDER_PASS,
3923 frame.render_passes[1]->quad_list[0]->material); 3952 frame.render_passes[1]->quad_list[0]->material);
3924 const RenderPassDrawQuad* quad = 3953 const RenderPassDrawQuad* quad =
3925 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 3954 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
3926 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 3955 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
3927 ASSERT_TRUE(target_pass); 3956 ASSERT_TRUE(target_pass);
3928 EXPECT_FALSE(target_pass->damage_rect.IsEmpty()); 3957 EXPECT_FALSE(target_pass->damage_rect.IsEmpty());
3929 3958
3930 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3959 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3931 my_host_impl->DidDrawAllLayers(frame); 3960 my_host_impl->DidDrawAllLayers(frame);
3932 } 3961 }
3933 3962
3934 // Change opacity again, and evict the cached surface texture. 3963 // Change opacity again, and evict the cached surface texture.
3935 surface_layer_ptr->SetOpacity(0.5f); 3964 surface_layer_ptr->SetOpacity(0.5f);
3936 static_cast<GLRendererWithReleaseTextures*>( 3965 static_cast<GLRendererWithReleaseTextures*>(
3937 my_host_impl->renderer())->ReleaseRenderPassTextures(); 3966 my_host_impl->renderer())->ReleaseRenderPassTextures();
3938 3967
3939 // Change opacity and draw 3968 // Change opacity and draw
3940 surface_layer_ptr->SetOpacity(0.6f); 3969 surface_layer_ptr->SetOpacity(0.6f);
3941 { 3970 {
3942 LayerTreeHostImpl::FrameData frame; 3971 LayerTreeHostImpl::FrameData frame;
3943 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 3972 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3944 3973
3945 // Must receive two render passes 3974 // Must receive two render passes
3946 ASSERT_EQ(2U, frame.render_passes.size()); 3975 ASSERT_EQ(2U, frame.render_passes.size());
3947 3976
3948 // Even though not enough properties changed, the entire thing must be 3977 // Even though not enough properties changed, the entire thing must be
3949 // redrawn as we don't have cached textures 3978 // redrawn as we don't have cached textures
3950 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 3979 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3951 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); 3980 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3952 3981
3953 EXPECT_EQ(DrawQuad::RENDER_PASS, 3982 EXPECT_EQ(DrawQuad::RENDER_PASS,
3954 frame.render_passes[1]->quad_list[0]->material); 3983 frame.render_passes[1]->quad_list[0]->material);
3955 const RenderPassDrawQuad* quad = 3984 const RenderPassDrawQuad* quad =
3956 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 3985 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
3957 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 3986 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
3958 ASSERT_TRUE(target_pass); 3987 ASSERT_TRUE(target_pass);
3959 EXPECT_TRUE(target_pass->damage_rect.IsEmpty()); 3988 EXPECT_TRUE(target_pass->damage_rect.IsEmpty());
3960 3989
3961 // Was our surface evicted? 3990 // Was our surface evicted?
3962 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 3991 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
3963 target_pass->id)); 3992 target_pass->id));
3964 3993
3965 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 3994 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3966 my_host_impl->DidDrawAllLayers(frame); 3995 my_host_impl->DidDrawAllLayers(frame);
3967 } 3996 }
3968 3997
3969 // Draw without any change, to make sure the state is clear 3998 // Draw without any change, to make sure the state is clear
3970 { 3999 {
3971 LayerTreeHostImpl::FrameData frame; 4000 LayerTreeHostImpl::FrameData frame;
3972 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4001 host_impl_->SetFullRootLayerDamage();
4002 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3973 4003
3974 // Must receive one render pass, as the other one should be culled 4004 // Must receive one render pass, as the other one should be culled
3975 ASSERT_EQ(1U, frame.render_passes.size()); 4005 ASSERT_EQ(1U, frame.render_passes.size());
3976 4006
3977 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4007 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3978 EXPECT_EQ(DrawQuad::RENDER_PASS, 4008 EXPECT_EQ(DrawQuad::RENDER_PASS,
3979 frame.render_passes[0]->quad_list[0]->material); 4009 frame.render_passes[0]->quad_list[0]->material);
3980 const RenderPassDrawQuad* quad = 4010 const RenderPassDrawQuad* quad =
3981 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4011 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
3982 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 4012 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
3983 frame.render_passes_by_id.end()); 4013 frame.render_passes_by_id.end());
3984 4014
3985 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4015 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
3986 my_host_impl->DidDrawAllLayers(frame); 4016 my_host_impl->DidDrawAllLayers(frame);
3987 } 4017 }
3988 4018
3989 // Change location of the intermediate layer 4019 // Change location of the intermediate layer
3990 gfx::Transform transform = intermediate_layer_ptr->transform(); 4020 gfx::Transform transform = intermediate_layer_ptr->transform();
3991 transform.matrix().setDouble(0, 3, 1.0001); 4021 transform.matrix().setDouble(0, 3, 1.0001);
3992 intermediate_layer_ptr->SetTransform(transform); 4022 intermediate_layer_ptr->SetTransform(transform);
3993 { 4023 {
3994 LayerTreeHostImpl::FrameData frame; 4024 LayerTreeHostImpl::FrameData frame;
3995 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4025 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
3996 4026
3997 // Must receive one render pass, as the other one should be culled. 4027 // Must receive one render pass, as the other one should be culled.
3998 ASSERT_EQ(1U, frame.render_passes.size()); 4028 ASSERT_EQ(1U, frame.render_passes.size());
3999 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4029 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4000 4030
4001 EXPECT_EQ(DrawQuad::RENDER_PASS, 4031 EXPECT_EQ(DrawQuad::RENDER_PASS,
4002 frame.render_passes[0]->quad_list[0]->material); 4032 frame.render_passes[0]->quad_list[0]->material);
4003 const RenderPassDrawQuad* quad = 4033 const RenderPassDrawQuad* quad =
4004 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4034 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4005 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 4035 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
(...skipping 20 matching lines...) Expand all
4026 LayerImpl* child_ptr; 4056 LayerImpl* child_ptr;
4027 4057
4028 SetupLayersForTextureCaching(my_host_impl.get(), 4058 SetupLayersForTextureCaching(my_host_impl.get(),
4029 root_ptr, 4059 root_ptr,
4030 intermediate_layer_ptr, 4060 intermediate_layer_ptr,
4031 surface_layer_ptr, 4061 surface_layer_ptr,
4032 child_ptr, 4062 child_ptr,
4033 gfx::Size(100, 100)); 4063 gfx::Size(100, 100));
4034 { 4064 {
4035 LayerTreeHostImpl::FrameData frame; 4065 LayerTreeHostImpl::FrameData frame;
4036 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4066 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4037 4067
4038 // Must receive two render passes, each with one quad 4068 // Must receive two render passes, each with one quad
4039 ASSERT_EQ(2U, frame.render_passes.size()); 4069 ASSERT_EQ(2U, frame.render_passes.size());
4040 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4070 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4041 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); 4071 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
4042 4072
4043 EXPECT_EQ(DrawQuad::RENDER_PASS, 4073 EXPECT_EQ(DrawQuad::RENDER_PASS,
4044 frame.render_passes[1]->quad_list[0]->material); 4074 frame.render_passes[1]->quad_list[0]->material);
4045 const RenderPassDrawQuad* quad = 4075 const RenderPassDrawQuad* quad =
4046 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 4076 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
4047 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 4077 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
4048 EXPECT_FALSE(target_pass->damage_rect.IsEmpty()); 4078 EXPECT_FALSE(target_pass->damage_rect.IsEmpty());
4049 4079
4050 EXPECT_FALSE(frame.render_passes[0]->damage_rect.IsEmpty()); 4080 EXPECT_FALSE(frame.render_passes[0]->damage_rect.IsEmpty());
4051 EXPECT_FALSE(frame.render_passes[1]->damage_rect.IsEmpty()); 4081 EXPECT_FALSE(frame.render_passes[1]->damage_rect.IsEmpty());
4052 4082
4053 EXPECT_FALSE( 4083 EXPECT_FALSE(
4054 frame.render_passes[0]->has_occlusion_from_outside_target_surface); 4084 frame.render_passes[0]->has_occlusion_from_outside_target_surface);
4055 EXPECT_FALSE( 4085 EXPECT_FALSE(
4056 frame.render_passes[1]->has_occlusion_from_outside_target_surface); 4086 frame.render_passes[1]->has_occlusion_from_outside_target_surface);
4057 4087
4058 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4088 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4059 my_host_impl->DidDrawAllLayers(frame); 4089 my_host_impl->DidDrawAllLayers(frame);
4060 } 4090 }
4061 4091
4062 // Draw without any change 4092 // Draw without any change
4063 { 4093 {
4064 LayerTreeHostImpl::FrameData frame; 4094 LayerTreeHostImpl::FrameData frame;
4065 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4095 host_impl_->SetFullRootLayerDamage();
4096 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4066 4097
4067 // Even though there was no change, we set the damage to entire viewport. 4098 // Even though there was no change, we set the damage to entire viewport.
4068 // One of the passes should be culled as a result, since contents didn't 4099 // One of the passes should be culled as a result, since contents didn't
4069 // change and we have cached texture. 4100 // change and we have cached texture.
4070 ASSERT_EQ(1U, frame.render_passes.size()); 4101 ASSERT_EQ(1U, frame.render_passes.size());
4071 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4102 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4072 4103
4073 EXPECT_TRUE(frame.render_passes[0]->damage_rect.IsEmpty()); 4104 EXPECT_TRUE(frame.render_passes[0]->damage_rect.IsEmpty());
4074 4105
4075 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4106 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4076 my_host_impl->DidDrawAllLayers(frame); 4107 my_host_impl->DidDrawAllLayers(frame);
4077 } 4108 }
4078 4109
4079 // Change opacity and draw 4110 // Change opacity and draw
4080 surface_layer_ptr->SetOpacity(0.6f); 4111 surface_layer_ptr->SetOpacity(0.6f);
4081 { 4112 {
4082 LayerTreeHostImpl::FrameData frame; 4113 LayerTreeHostImpl::FrameData frame;
4083 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4114 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4084 4115
4085 // Must receive one render pass, as the other one should be culled 4116 // Must receive one render pass, as the other one should be culled
4086 ASSERT_EQ(1U, frame.render_passes.size()); 4117 ASSERT_EQ(1U, frame.render_passes.size());
4087 4118
4088 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4119 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4089 EXPECT_EQ(DrawQuad::RENDER_PASS, 4120 EXPECT_EQ(DrawQuad::RENDER_PASS,
4090 frame.render_passes[0]->quad_list[0]->material); 4121 frame.render_passes[0]->quad_list[0]->material);
4091 const RenderPassDrawQuad* quad = 4122 const RenderPassDrawQuad* quad =
4092 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4123 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4093 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 4124 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
4094 frame.render_passes_by_id.end()); 4125 frame.render_passes_by_id.end());
4095 4126
4096 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4127 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4097 my_host_impl->DidDrawAllLayers(frame); 4128 my_host_impl->DidDrawAllLayers(frame);
4098 } 4129 }
4099 4130
4100 // Change less benign property and draw - should have contents changed flag 4131 // Change less benign property and draw - should have contents changed flag
4101 surface_layer_ptr->SetStackingOrderChanged(true); 4132 surface_layer_ptr->SetStackingOrderChanged(true);
4102 { 4133 {
4103 LayerTreeHostImpl::FrameData frame; 4134 LayerTreeHostImpl::FrameData frame;
4104 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4135 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4105 4136
4106 // Must receive two render passes, each with one quad 4137 // Must receive two render passes, each with one quad
4107 ASSERT_EQ(2U, frame.render_passes.size()); 4138 ASSERT_EQ(2U, frame.render_passes.size());
4108 4139
4109 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4140 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4110 EXPECT_EQ(DrawQuad::SOLID_COLOR, 4141 EXPECT_EQ(DrawQuad::SOLID_COLOR,
4111 frame.render_passes[0]->quad_list[0]->material); 4142 frame.render_passes[0]->quad_list[0]->material);
4112 4143
4113 EXPECT_EQ(DrawQuad::RENDER_PASS, 4144 EXPECT_EQ(DrawQuad::RENDER_PASS,
4114 frame.render_passes[1]->quad_list[0]->material); 4145 frame.render_passes[1]->quad_list[0]->material);
4115 const RenderPassDrawQuad* quad = 4146 const RenderPassDrawQuad* quad =
4116 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 4147 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
4117 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 4148 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
4118 ASSERT_TRUE(target_pass); 4149 ASSERT_TRUE(target_pass);
4119 EXPECT_FALSE(target_pass->damage_rect.IsEmpty()); 4150 EXPECT_FALSE(target_pass->damage_rect.IsEmpty());
4120 4151
4121 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4152 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4122 my_host_impl->DidDrawAllLayers(frame); 4153 my_host_impl->DidDrawAllLayers(frame);
4123 } 4154 }
4124 4155
4125 // Change opacity again, and evict the cached surface texture. 4156 // Change opacity again, and evict the cached surface texture.
4126 surface_layer_ptr->SetOpacity(0.5f); 4157 surface_layer_ptr->SetOpacity(0.5f);
4127 static_cast<GLRendererWithReleaseTextures*>( 4158 static_cast<GLRendererWithReleaseTextures*>(
4128 my_host_impl->renderer())->ReleaseRenderPassTextures(); 4159 my_host_impl->renderer())->ReleaseRenderPassTextures();
4129 4160
4130 // Change opacity and draw 4161 // Change opacity and draw
4131 surface_layer_ptr->SetOpacity(0.6f); 4162 surface_layer_ptr->SetOpacity(0.6f);
4132 { 4163 {
4133 LayerTreeHostImpl::FrameData frame; 4164 LayerTreeHostImpl::FrameData frame;
4134 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4165 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4135 4166
4136 // Must receive two render passes 4167 // Must receive two render passes
4137 ASSERT_EQ(2U, frame.render_passes.size()); 4168 ASSERT_EQ(2U, frame.render_passes.size());
4138 4169
4139 // Even though not enough properties changed, the entire thing must be 4170 // Even though not enough properties changed, the entire thing must be
4140 // redrawn as we don't have cached textures 4171 // redrawn as we don't have cached textures
4141 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4172 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4142 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size()); 4173 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
4143 4174
4144 EXPECT_EQ(DrawQuad::RENDER_PASS, 4175 EXPECT_EQ(DrawQuad::RENDER_PASS,
4145 frame.render_passes[1]->quad_list[0]->material); 4176 frame.render_passes[1]->quad_list[0]->material);
4146 const RenderPassDrawQuad* quad = 4177 const RenderPassDrawQuad* quad =
4147 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]); 4178 RenderPassDrawQuad::MaterialCast(frame.render_passes[1]->quad_list[0]);
4148 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id]; 4179 RenderPass* target_pass = frame.render_passes_by_id[quad->render_pass_id];
4149 ASSERT_TRUE(target_pass); 4180 ASSERT_TRUE(target_pass);
4150 EXPECT_TRUE(target_pass->damage_rect.IsEmpty()); 4181 EXPECT_TRUE(target_pass->damage_rect.IsEmpty());
4151 4182
4152 // Was our surface evicted? 4183 // Was our surface evicted?
4153 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId( 4184 EXPECT_FALSE(my_host_impl->renderer()->HaveCachedResourcesForRenderPassId(
4154 target_pass->id)); 4185 target_pass->id));
4155 4186
4156 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4187 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4157 my_host_impl->DidDrawAllLayers(frame); 4188 my_host_impl->DidDrawAllLayers(frame);
4158 } 4189 }
4159 4190
4160 // Draw without any change, to make sure the state is clear 4191 // Draw without any change, to make sure the state is clear
4161 { 4192 {
4162 LayerTreeHostImpl::FrameData frame; 4193 LayerTreeHostImpl::FrameData frame;
4163 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4194 host_impl_->SetFullRootLayerDamage();
4195 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4164 4196
4165 // Even though there was no change, we set the damage to entire viewport. 4197 // Even though there was no change, we set the damage to entire viewport.
4166 // One of the passes should be culled as a result, since contents didn't 4198 // One of the passes should be culled as a result, since contents didn't
4167 // change and we have cached texture. 4199 // change and we have cached texture.
4168 ASSERT_EQ(1U, frame.render_passes.size()); 4200 ASSERT_EQ(1U, frame.render_passes.size());
4169 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4201 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4170 4202
4171 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); 4203 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now());
4172 my_host_impl->DidDrawAllLayers(frame); 4204 my_host_impl->DidDrawAllLayers(frame);
4173 } 4205 }
4174 4206
4175 // Change location of the intermediate layer 4207 // Change location of the intermediate layer
4176 gfx::Transform transform = intermediate_layer_ptr->transform(); 4208 gfx::Transform transform = intermediate_layer_ptr->transform();
4177 transform.matrix().setDouble(0, 3, 1.0001); 4209 transform.matrix().setDouble(0, 3, 1.0001);
4178 intermediate_layer_ptr->SetTransform(transform); 4210 intermediate_layer_ptr->SetTransform(transform);
4179 { 4211 {
4180 LayerTreeHostImpl::FrameData frame; 4212 LayerTreeHostImpl::FrameData frame;
4181 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); 4213 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame, gfx::Rect()));
4182 4214
4183 // Must receive one render pass, as the other one should be culled. 4215 // Must receive one render pass, as the other one should be culled.
4184 ASSERT_EQ(1U, frame.render_passes.size()); 4216 ASSERT_EQ(1U, frame.render_passes.size());
4185 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size()); 4217 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
4186 4218
4187 EXPECT_EQ(DrawQuad::RENDER_PASS, 4219 EXPECT_EQ(DrawQuad::RENDER_PASS,
4188 frame.render_passes[0]->quad_list[0]->material); 4220 frame.render_passes[0]->quad_list[0]->material);
4189 const RenderPassDrawQuad* quad = 4221 const RenderPassDrawQuad* quad =
4190 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4222 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4191 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == 4223 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) ==
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
4620 } 4652 }
4621 4653
4622 class LayerTreeHostImplTestWithDelegatingRenderer 4654 class LayerTreeHostImplTestWithDelegatingRenderer
4623 : public LayerTreeHostImplTest { 4655 : public LayerTreeHostImplTest {
4624 protected: 4656 protected:
4625 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE { 4657 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
4626 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>(); 4658 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>();
4627 } 4659 }
4628 4660
4629 void DrawFrameAndTestDamage(const gfx::RectF& expected_damage) { 4661 void DrawFrameAndTestDamage(const gfx::RectF& expected_damage) {
4662 bool expect_to_draw = !expected_damage.IsEmpty();
4663
4630 LayerTreeHostImpl::FrameData frame; 4664 LayerTreeHostImpl::FrameData frame;
4631 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4665 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4632 ASSERT_EQ(1u, frame.render_passes.size());
4633 4666
4634 // Verify the damage rect for the root render pass. 4667 if (!expect_to_draw) {
4635 const RenderPass* root_render_pass = frame.render_passes.back(); 4668 // With no damage, we don't draw, and no quads are created.
4636 EXPECT_RECT_EQ(expected_damage, root_render_pass->damage_rect); 4669 ASSERT_EQ(0u, frame.render_passes.size());
4670 } else {
4671 ASSERT_EQ(1u, frame.render_passes.size());
4637 4672
4638 // Verify the root layer's quad is generated and not being culled. 4673 // Verify the damage rect for the root render pass.
4639 ASSERT_EQ(1u, root_render_pass->quad_list.size()); 4674 const RenderPass* root_render_pass = frame.render_passes.back();
4640 gfx::Rect expected_visible_rect( 4675 EXPECT_RECT_EQ(expected_damage, root_render_pass->damage_rect);
4641 host_impl_->active_tree()->root_layer()->content_bounds()); 4676
4642 EXPECT_RECT_EQ(expected_visible_rect, 4677 // Verify the root layer's quad is generated and not being culled.
4643 root_render_pass->quad_list[0]->visible_rect); 4678 ASSERT_EQ(1u, root_render_pass->quad_list.size());
4679 gfx::Rect expected_visible_rect(
4680 host_impl_->active_tree()->root_layer()->content_bounds());
4681 EXPECT_RECT_EQ(expected_visible_rect,
4682 root_render_pass->quad_list[0]->visible_rect);
4683 }
4644 4684
4645 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4685 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4646 host_impl_->DidDrawAllLayers(frame); 4686 host_impl_->DidDrawAllLayers(frame);
4687 EXPECT_EQ(expect_to_draw, host_impl_->SwapBuffers(frame));
4647 } 4688 }
4648 }; 4689 };
4649 4690
4650 TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) { 4691 TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) {
4651 scoped_ptr<SolidColorLayerImpl> root = 4692 scoped_ptr<SolidColorLayerImpl> root =
4652 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); 4693 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
4653 root->SetAnchorPoint(gfx::PointF()); 4694 root->SetAnchorPoint(gfx::PointF());
4654 root->SetPosition(gfx::PointF()); 4695 root->SetPosition(gfx::PointF());
4655 root->SetBounds(gfx::Size(10, 10)); 4696 root->SetBounds(gfx::Size(10, 10));
4656 root->SetContentBounds(gfx::Size(10, 10)); 4697 root->SetContentBounds(gfx::Size(10, 10));
4657 root->SetDrawsContent(true); 4698 root->SetDrawsContent(true);
4658 host_impl_->active_tree()->SetRootLayer(root.PassAs<LayerImpl>()); 4699 host_impl_->active_tree()->SetRootLayer(root.PassAs<LayerImpl>());
4659 4700
4701 // Child layer is in the bottom right corner.
4702 scoped_ptr<SolidColorLayerImpl> child =
4703 SolidColorLayerImpl::Create(host_impl_->active_tree(), 2);
4704 child->SetAnchorPoint(gfx::PointF(0.f, 0.f));
4705 child->SetPosition(gfx::PointF(9.f, 9.f));
4706 child->SetBounds(gfx::Size(1, 1));
4707 child->SetContentBounds(gfx::Size(1, 1));
4708 child->SetDrawsContent(true);
4709 root->AddChild(child.PassAs<LayerImpl>());
4710
4660 // Draw a frame. In the first frame, the entire viewport should be damaged. 4711 // Draw a frame. In the first frame, the entire viewport should be damaged.
4661 gfx::Rect full_frame_damage = gfx::Rect(host_impl_->device_viewport_size()); 4712 gfx::Rect full_frame_damage = gfx::Rect(host_impl_->device_viewport_size());
4662 DrawFrameAndTestDamage(full_frame_damage); 4713 DrawFrameAndTestDamage(full_frame_damage);
4663 4714
4664 // The second frame should have no damage, but the quads should still be 4715 // The second frame has damage that doesn't touch the child layer. Its quads
4665 // generated. 4716 // should still be generated.
4717 gfx::Rect small_damage = gfx::Rect(0, 0, 1, 1);
4718 host_impl_->active_tree()->root_layer()->set_update_rect(small_damage);
4719 DrawFrameAndTestDamage(small_damage);
4720
4721 // The third frame should have no damage, so no quads should be generated.
4666 gfx::Rect no_damage; 4722 gfx::Rect no_damage;
4667 DrawFrameAndTestDamage(no_damage); 4723 DrawFrameAndTestDamage(no_damage);
4668 } 4724 }
4669 4725
4670 class FakeMaskLayerImpl : public LayerImpl { 4726 class FakeMaskLayerImpl : public LayerImpl {
4671 public: 4727 public:
4672 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* tree_impl, 4728 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* tree_impl,
4673 int id) { 4729 int id) {
4674 return make_scoped_ptr(new FakeMaskLayerImpl(tree_impl, id)); 4730 return make_scoped_ptr(new FakeMaskLayerImpl(tree_impl, id));
4675 } 4731 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4737 mask_layer->SetAnchorPoint(gfx::PointF()); 4793 mask_layer->SetAnchorPoint(gfx::PointF());
4738 mask_layer->SetDrawsContent(true); 4794 mask_layer->SetDrawsContent(true);
4739 4795
4740 4796
4741 // Check that the tree scaling is correctly taken into account for the mask, 4797 // Check that the tree scaling is correctly taken into account for the mask,
4742 // that should fully map onto the quad. 4798 // that should fully map onto the quad.
4743 float device_scale_factor = 1.f; 4799 float device_scale_factor = 1.f;
4744 host_impl_->SetViewportSize(root_size, root_size); 4800 host_impl_->SetViewportSize(root_size, root_size);
4745 host_impl_->SetDeviceScaleFactor(device_scale_factor); { 4801 host_impl_->SetDeviceScaleFactor(device_scale_factor); {
4746 LayerTreeHostImpl::FrameData frame; 4802 LayerTreeHostImpl::FrameData frame;
4747 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4803 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4748 4804
4749 ASSERT_EQ(1u, frame.render_passes.size()); 4805 ASSERT_EQ(1u, frame.render_passes.size());
4750 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4806 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4751 ASSERT_EQ(DrawQuad::RENDER_PASS, 4807 ASSERT_EQ(DrawQuad::RENDER_PASS,
4752 frame.render_passes[0]->quad_list[0]->material); 4808 frame.render_passes[0]->quad_list[0]->material);
4753 const RenderPassDrawQuad* render_pass_quad = 4809 const RenderPassDrawQuad* render_pass_quad =
4754 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4810 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4755 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 4811 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
4756 render_pass_quad->rect.ToString()); 4812 render_pass_quad->rect.ToString());
4757 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4813 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4758 render_pass_quad->mask_uv_rect.ToString()); 4814 render_pass_quad->mask_uv_rect.ToString());
4759 4815
4760 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4816 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4761 host_impl_->DidDrawAllLayers(frame); 4817 host_impl_->DidDrawAllLayers(frame);
4762 } 4818 }
4763 4819
4764 4820
4765 // Applying a DSF should change the render surface size, but won't affect 4821 // Applying a DSF should change the render surface size, but won't affect
4766 // which part of the mask is used. 4822 // which part of the mask is used.
4767 device_scale_factor = 2.f; 4823 device_scale_factor = 2.f;
4768 gfx::Size device_viewport = 4824 gfx::Size device_viewport =
4769 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor)); 4825 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor));
4770 host_impl_->SetViewportSize(root_size, device_viewport); 4826 host_impl_->SetViewportSize(root_size, device_viewport);
4771 host_impl_->SetDeviceScaleFactor(device_scale_factor); 4827 host_impl_->SetDeviceScaleFactor(device_scale_factor);
4772 host_impl_->active_tree()->set_needs_update_draw_properties(); { 4828 host_impl_->active_tree()->set_needs_update_draw_properties(); {
4773 LayerTreeHostImpl::FrameData frame; 4829 LayerTreeHostImpl::FrameData frame;
4774 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4830 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4775 4831
4776 ASSERT_EQ(1u, frame.render_passes.size()); 4832 ASSERT_EQ(1u, frame.render_passes.size());
4777 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4833 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4778 ASSERT_EQ(DrawQuad::RENDER_PASS, 4834 ASSERT_EQ(DrawQuad::RENDER_PASS,
4779 frame.render_passes[0]->quad_list[0]->material); 4835 frame.render_passes[0]->quad_list[0]->material);
4780 const RenderPassDrawQuad* render_pass_quad = 4836 const RenderPassDrawQuad* render_pass_quad =
4781 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4837 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4782 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), 4838 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
4783 render_pass_quad->rect.ToString()); 4839 render_pass_quad->rect.ToString());
4784 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4840 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4785 render_pass_quad->mask_uv_rect.ToString()); 4841 render_pass_quad->mask_uv_rect.ToString());
4786 4842
4787 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4843 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4788 host_impl_->DidDrawAllLayers(frame); 4844 host_impl_->DidDrawAllLayers(frame);
4789 } 4845 }
4790 4846
4791 4847
4792 // Applying an equivalent content scale on the content layer and the mask 4848 // Applying an equivalent content scale on the content layer and the mask
4793 // should still result in the same part of the mask being used. 4849 // should still result in the same part of the mask being used.
4794 gfx::Size content_bounds = 4850 gfx::Size content_bounds =
4795 gfx::ToRoundedSize(gfx::ScaleSize(scaling_layer_size, 4851 gfx::ToRoundedSize(gfx::ScaleSize(scaling_layer_size,
4796 device_scale_factor)); 4852 device_scale_factor));
4797 content_layer->SetContentBounds(content_bounds); 4853 content_layer->SetContentBounds(content_bounds);
4798 content_layer->SetContentsScale(device_scale_factor, device_scale_factor); 4854 content_layer->SetContentsScale(device_scale_factor, device_scale_factor);
4799 mask_layer->SetContentBounds(content_bounds); 4855 mask_layer->SetContentBounds(content_bounds);
4800 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor); 4856 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor);
4801 host_impl_->active_tree()->set_needs_update_draw_properties(); { 4857 host_impl_->active_tree()->set_needs_update_draw_properties(); {
4802 LayerTreeHostImpl::FrameData frame; 4858 LayerTreeHostImpl::FrameData frame;
4803 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4859 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4804 4860
4805 ASSERT_EQ(1u, frame.render_passes.size()); 4861 ASSERT_EQ(1u, frame.render_passes.size());
4806 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4862 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4807 ASSERT_EQ(DrawQuad::RENDER_PASS, 4863 ASSERT_EQ(DrawQuad::RENDER_PASS,
4808 frame.render_passes[0]->quad_list[0]->material); 4864 frame.render_passes[0]->quad_list[0]->material);
4809 const RenderPassDrawQuad* render_pass_quad = 4865 const RenderPassDrawQuad* render_pass_quad =
4810 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4866 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4811 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), 4867 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(),
4812 render_pass_quad->rect.ToString()); 4868 render_pass_quad->rect.ToString());
4813 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4869 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4856 mask_layer->SetPosition(gfx::PointF()); 4912 mask_layer->SetPosition(gfx::PointF());
4857 mask_layer->SetAnchorPoint(gfx::PointF()); 4913 mask_layer->SetAnchorPoint(gfx::PointF());
4858 mask_layer->SetDrawsContent(true); 4914 mask_layer->SetDrawsContent(true);
4859 4915
4860 4916
4861 // Check that the mask fills the surface. 4917 // Check that the mask fills the surface.
4862 float device_scale_factor = 1.f; 4918 float device_scale_factor = 1.f;
4863 host_impl_->SetViewportSize(root_size, root_size); 4919 host_impl_->SetViewportSize(root_size, root_size);
4864 host_impl_->SetDeviceScaleFactor(device_scale_factor); { 4920 host_impl_->SetDeviceScaleFactor(device_scale_factor); {
4865 LayerTreeHostImpl::FrameData frame; 4921 LayerTreeHostImpl::FrameData frame;
4866 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4922 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4867 4923
4868 ASSERT_EQ(1u, frame.render_passes.size()); 4924 ASSERT_EQ(1u, frame.render_passes.size());
4869 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4925 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4870 ASSERT_EQ(DrawQuad::RENDER_PASS, 4926 ASSERT_EQ(DrawQuad::RENDER_PASS,
4871 frame.render_passes[0]->quad_list[0]->material); 4927 frame.render_passes[0]->quad_list[0]->material);
4872 const RenderPassDrawQuad* render_pass_quad = 4928 const RenderPassDrawQuad* render_pass_quad =
4873 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4929 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4874 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), 4930 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
4875 render_pass_quad->rect.ToString()); 4931 render_pass_quad->rect.ToString());
4876 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4932 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4877 render_pass_quad->mask_uv_rect.ToString()); 4933 render_pass_quad->mask_uv_rect.ToString());
4878 4934
4879 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4935 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4880 host_impl_->DidDrawAllLayers(frame); 4936 host_impl_->DidDrawAllLayers(frame);
4881 } 4937 }
4882 4938
4883 4939
4884 // Applying a DSF should change the render surface size, but won't affect 4940 // Applying a DSF should change the render surface size, but won't affect
4885 // which part of the mask is used. 4941 // which part of the mask is used.
4886 device_scale_factor = 2.f; 4942 device_scale_factor = 2.f;
4887 gfx::Size device_viewport = 4943 gfx::Size device_viewport =
4888 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor)); 4944 gfx::ToFlooredSize(gfx::ScaleSize(root_size, device_scale_factor));
4889 host_impl_->SetViewportSize(root_size, device_viewport); 4945 host_impl_->SetViewportSize(root_size, device_viewport);
4890 host_impl_->SetDeviceScaleFactor(device_scale_factor); 4946 host_impl_->SetDeviceScaleFactor(device_scale_factor);
4891 host_impl_->active_tree()->set_needs_update_draw_properties(); { 4947 host_impl_->active_tree()->set_needs_update_draw_properties(); {
4892 LayerTreeHostImpl::FrameData frame; 4948 LayerTreeHostImpl::FrameData frame;
4893 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4949 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4894 4950
4895 ASSERT_EQ(1u, frame.render_passes.size()); 4951 ASSERT_EQ(1u, frame.render_passes.size());
4896 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4952 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4897 ASSERT_EQ(DrawQuad::RENDER_PASS, 4953 ASSERT_EQ(DrawQuad::RENDER_PASS,
4898 frame.render_passes[0]->quad_list[0]->material); 4954 frame.render_passes[0]->quad_list[0]->material);
4899 const RenderPassDrawQuad* render_pass_quad = 4955 const RenderPassDrawQuad* render_pass_quad =
4900 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4956 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4901 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 4957 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
4902 render_pass_quad->rect.ToString()); 4958 render_pass_quad->rect.ToString());
4903 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4959 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4904 render_pass_quad->mask_uv_rect.ToString()); 4960 render_pass_quad->mask_uv_rect.ToString());
4905 4961
4906 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4962 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4907 host_impl_->DidDrawAllLayers(frame); 4963 host_impl_->DidDrawAllLayers(frame);
4908 } 4964 }
4909 4965
4910 4966
4911 // Applying an equivalent content scale on the content layer and the mask 4967 // Applying an equivalent content scale on the content layer and the mask
4912 // should still result in the same part of the mask being used. 4968 // should still result in the same part of the mask being used.
4913 gfx::Size layer_size_large = 4969 gfx::Size layer_size_large =
4914 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor)); 4970 gfx::ToRoundedSize(gfx::ScaleSize(layer_size, device_scale_factor));
4915 content_layer->SetContentBounds(layer_size_large); 4971 content_layer->SetContentBounds(layer_size_large);
4916 content_layer->SetContentsScale(device_scale_factor, device_scale_factor); 4972 content_layer->SetContentsScale(device_scale_factor, device_scale_factor);
4917 gfx::Size mask_size_large = 4973 gfx::Size mask_size_large =
4918 gfx::ToRoundedSize(gfx::ScaleSize(mask_size, device_scale_factor)); 4974 gfx::ToRoundedSize(gfx::ScaleSize(mask_size, device_scale_factor));
4919 mask_layer->SetContentBounds(mask_size_large); 4975 mask_layer->SetContentBounds(mask_size_large);
4920 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor); 4976 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor);
4921 host_impl_->active_tree()->set_needs_update_draw_properties(); { 4977 host_impl_->active_tree()->set_needs_update_draw_properties(); {
4922 LayerTreeHostImpl::FrameData frame; 4978 LayerTreeHostImpl::FrameData frame;
4923 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 4979 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4924 4980
4925 ASSERT_EQ(1u, frame.render_passes.size()); 4981 ASSERT_EQ(1u, frame.render_passes.size());
4926 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 4982 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4927 ASSERT_EQ(DrawQuad::RENDER_PASS, 4983 ASSERT_EQ(DrawQuad::RENDER_PASS,
4928 frame.render_passes[0]->quad_list[0]->material); 4984 frame.render_passes[0]->quad_list[0]->material);
4929 const RenderPassDrawQuad* render_pass_quad = 4985 const RenderPassDrawQuad* render_pass_quad =
4930 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 4986 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4931 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 4987 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
4932 render_pass_quad->rect.ToString()); 4988 render_pass_quad->rect.ToString());
4933 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 4989 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4934 render_pass_quad->mask_uv_rect.ToString()); 4990 render_pass_quad->mask_uv_rect.ToString());
4935 4991
4936 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 4992 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4937 host_impl_->DidDrawAllLayers(frame); 4993 host_impl_->DidDrawAllLayers(frame);
4938 } 4994 }
4939 4995
4940 // Applying a different contents scale to the mask layer will still result 4996 // Applying a different contents scale to the mask layer will still result
4941 // in the mask covering the owning layer. 4997 // in the mask covering the owning layer.
4942 mask_layer->SetContentBounds(mask_size); 4998 mask_layer->SetContentBounds(mask_size);
4943 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor); 4999 mask_layer->SetContentsScale(device_scale_factor, device_scale_factor);
4944 host_impl_->active_tree()->set_needs_update_draw_properties(); { 5000 host_impl_->active_tree()->set_needs_update_draw_properties(); {
4945 LayerTreeHostImpl::FrameData frame; 5001 LayerTreeHostImpl::FrameData frame;
4946 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); 5002 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
4947 5003
4948 ASSERT_EQ(1u, frame.render_passes.size()); 5004 ASSERT_EQ(1u, frame.render_passes.size());
4949 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size()); 5005 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4950 ASSERT_EQ(DrawQuad::RENDER_PASS, 5006 ASSERT_EQ(DrawQuad::RENDER_PASS,
4951 frame.render_passes[0]->quad_list[0]->material); 5007 frame.render_passes[0]->quad_list[0]->material);
4952 const RenderPassDrawQuad* render_pass_quad = 5008 const RenderPassDrawQuad* render_pass_quad =
4953 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]); 5009 RenderPassDrawQuad::MaterialCast(frame.render_passes[0]->quad_list[0]);
4954 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 5010 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
4955 render_pass_quad->rect.ToString()); 5011 render_pass_quad->rect.ToString());
4956 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), 5012 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
4957 render_pass_quad->mask_uv_rect.ToString()); 5013 render_pass_quad->mask_uv_rect.ToString());
4958 5014
4959 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); 5015 host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
4960 host_impl_->DidDrawAllLayers(frame); 5016 host_impl_->DidDrawAllLayers(frame);
4961 } 5017 }
4962 } 5018 }
4963 5019
4964 } // namespace 5020 } // namespace
4965 } // namespace cc 5021 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698