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

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

Powered by Google App Engine
This is Rietveld 408576698