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

Side by Side Diff: cc/layer_tree_host_impl_unittest.cc

Issue 12648005: cc: Chromify the LayerTreeHostImpl class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compl Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/layer_tree_host_unittest.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/layer_tree_host_impl.h" 5 #include "cc/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 , m_reduceMemoryResult(true) 71 , m_reduceMemoryResult(true)
72 { 72 {
73 media::InitializeMediaLibraryForTesting(); 73 media::InitializeMediaLibraryForTesting();
74 } 74 }
75 75
76 virtual void SetUp() 76 virtual void SetUp()
77 { 77 {
78 LayerTreeSettings settings; 78 LayerTreeSettings settings;
79 settings.minimumOcclusionTrackingSize = gfx::Size(); 79 settings.minimumOcclusionTrackingSize = gfx::Size();
80 80
81 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); 81 m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy);
82 m_hostImpl->initializeRenderer(createOutputSurface()); 82 m_hostImpl->InitializeRenderer(createOutputSurface());
83 m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 83 m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
84 } 84 }
85 85
86 virtual void TearDown() 86 virtual void TearDown()
87 { 87 {
88 } 88 }
89 89
90 virtual void didLoseOutputSurfaceOnImplThread() OVERRIDE { } 90 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { }
91 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE { } 91 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE { }
92 virtual void onVSyncParametersChanged(base::TimeTicks, base::TimeDelta) OVER RIDE { } 92 virtual void OnVSyncParametersChanged(base::TimeTicks, base::TimeDelta) OVER RIDE { }
93 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { m_onCanDrawState ChangedCalled = true; } 93 virtual void OnCanDrawStateChanged(bool canDraw) OVERRIDE { m_onCanDrawState ChangedCalled = true; }
94 virtual void onHasPendingTreeStateChanged(bool hasPendingTree) OVERRIDE { m_ hasPendingTree = hasPendingTree; } 94 virtual void OnHasPendingTreeStateChanged(bool hasPendingTree) OVERRIDE { m_ hasPendingTree = hasPendingTree; }
95 virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = tr ue; } 95 virtual void SetNeedsRedrawOnImplThread() OVERRIDE { m_didRequestRedraw = tr ue; }
96 virtual void didUploadVisibleHighResolutionTileOnImplThread() OVERRIDE { m_d idUploadVisibleHighResolutionTile = true; } 96 virtual void DidUploadVisibleHighResolutionTileOnImplThread() OVERRIDE { m_d idUploadVisibleHighResolutionTile = true; }
97 virtual void setNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = tr ue; } 97 virtual void SetNeedsCommitOnImplThread() OVERRIDE { m_didRequestCommit = tr ue; }
98 virtual void setNeedsManageTilesOnImplThread() OVERRIDE { } 98 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE { }
99 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animatio nEventsVector>, base::Time wallClockTime) OVERRIDE { } 99 virtual void PostAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animatio nEventsVector>, base::Time wallClockTime) OVERRIDE { }
100 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) OVERRIDE { return m_reduceMemoryResult; } 100 virtual bool ReduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) OVERRIDE { return m_reduceMemoryResult; }
101 virtual void reduceWastedContentsTextureMemoryOnImplThread() OVERRIDE { } 101 virtual void ReduceWastedContentsTextureMemoryOnImplThread() OVERRIDE { }
102 virtual void sendManagedMemoryStats() OVERRIDE { } 102 virtual void SendManagedMemoryStats() OVERRIDE { }
103 virtual bool isInsideDraw() OVERRIDE { return false; } 103 virtual bool IsInsideDraw() OVERRIDE { return false; }
104 virtual void renewTreePriority() OVERRIDE { } 104 virtual void RenewTreePriority() OVERRIDE { }
105 105
106 void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult = reduceMemoryResult; } 106 void setReduceMemoryResult(bool reduceMemoryResult) { m_reduceMemoryResult = reduceMemoryResult; }
107 107
108 void createLayerTreeHost(bool partialSwap, scoped_ptr<OutputSurface> outputS urface) 108 void createLayerTreeHost(bool partialSwap, scoped_ptr<OutputSurface> outputS urface)
109 { 109 {
110 LayerTreeSettings settings; 110 LayerTreeSettings settings;
111 settings.minimumOcclusionTrackingSize = gfx::Size(); 111 settings.minimumOcclusionTrackingSize = gfx::Size();
112 settings.partialSwapEnabled = partialSwap; 112 settings.partialSwapEnabled = partialSwap;
113 113
114 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); 114 m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy);
115 115
116 m_hostImpl->initializeRenderer(outputSurface.Pass()); 116 m_hostImpl->InitializeRenderer(outputSurface.Pass());
117 m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 117 m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
118 } 118 }
119 119
120 void setupRootLayerImpl(scoped_ptr<LayerImpl> root) 120 void setupRootLayerImpl(scoped_ptr<LayerImpl> root)
121 { 121 {
122 root->SetAnchorPoint(gfx::PointF(0, 0)); 122 root->SetAnchorPoint(gfx::PointF(0, 0));
123 root->SetPosition(gfx::PointF(0, 0)); 123 root->SetPosition(gfx::PointF(0, 0));
124 root->SetBounds(gfx::Size(10, 10)); 124 root->SetBounds(gfx::Size(10, 10));
125 root->SetContentBounds(gfx::Size(10, 10)); 125 root->SetContentBounds(gfx::Size(10, 10));
126 root->SetDrawsContent(true); 126 root->SetDrawsContent(true);
127 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10); 127 root->draw_properties().visible_content_rect = gfx::Rect(0, 0, 10, 10);
128 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 128 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
129 } 129 }
130 130
131 static void expectClearedScrollDeltasRecursive(LayerImpl* layer) 131 static void expectClearedScrollDeltasRecursive(LayerImpl* layer)
132 { 132 {
133 ASSERT_EQ(layer->scroll_delta(), gfx::Vector2d()); 133 ASSERT_EQ(layer->scroll_delta(), gfx::Vector2d());
134 for (size_t i = 0; i < layer->children().size(); ++i) 134 for (size_t i = 0; i < layer->children().size(); ++i)
135 expectClearedScrollDeltasRecursive(layer->children()[i]); 135 expectClearedScrollDeltasRecursive(layer->children()[i]);
136 } 136 }
137 137
138 static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, cons t gfx::Vector2d& scrollDelta) 138 static void expectContains(const ScrollAndScaleSet& scrollInfo, int id, cons t gfx::Vector2d& scrollDelta)
(...skipping 18 matching lines...) Expand all
157 if (scrollInfo.scrolls[i].layerId != id) 157 if (scrollInfo.scrolls[i].layerId != id)
158 continue; 158 continue;
159 timesEncountered++; 159 timesEncountered++;
160 } 160 }
161 161
162 ASSERT_EQ(0, timesEncountered); 162 ASSERT_EQ(0, timesEncountered);
163 } 163 }
164 164
165 void setupScrollAndContentsLayers(const gfx::Size& contentSize) 165 void setupScrollAndContentsLayers(const gfx::Size& contentSize)
166 { 166 {
167 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 167 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree() , 1);
168 root->SetScrollable(true); 168 root->SetScrollable(true);
169 root->SetScrollOffset(gfx::Vector2d(0, 0)); 169 root->SetScrollOffset(gfx::Vector2d(0, 0));
170 root->SetMaxScrollOffset(gfx::Vector2d(contentSize.width(), contentSize. height())); 170 root->SetMaxScrollOffset(gfx::Vector2d(contentSize.width(), contentSize. height()));
171 root->SetBounds(contentSize); 171 root->SetBounds(contentSize);
172 root->SetContentBounds(contentSize); 172 root->SetContentBounds(contentSize);
173 root->SetPosition(gfx::PointF(0, 0)); 173 root->SetPosition(gfx::PointF(0, 0));
174 root->SetAnchorPoint(gfx::PointF(0, 0)); 174 root->SetAnchorPoint(gfx::PointF(0, 0));
175 175
176 scoped_ptr<LayerImpl> contents = LayerImpl::Create(m_hostImpl->activeTre e(), 2); 176 scoped_ptr<LayerImpl> contents = LayerImpl::Create(m_hostImpl->active_tr ee(), 2);
177 contents->SetDrawsContent(true); 177 contents->SetDrawsContent(true);
178 contents->SetBounds(contentSize); 178 contents->SetBounds(contentSize);
179 contents->SetContentBounds(contentSize); 179 contents->SetContentBounds(contentSize);
180 contents->SetPosition(gfx::PointF(0, 0)); 180 contents->SetPosition(gfx::PointF(0, 0));
181 contents->SetAnchorPoint(gfx::PointF(0, 0)); 181 contents->SetAnchorPoint(gfx::PointF(0, 0));
182 root->AddChild(contents.Pass()); 182 root->AddChild(contents.Pass());
183 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 183 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
184 m_hostImpl->activeTree()->DidBecomeActive(); 184 m_hostImpl->active_tree()->DidBecomeActive();
185 } 185 }
186 186
187 scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size) 187 scoped_ptr<LayerImpl> createScrollableLayer(int id, const gfx::Size& size)
188 { 188 {
189 scoped_ptr<LayerImpl> layer = LayerImpl::Create(m_hostImpl->activeTree() , id); 189 scoped_ptr<LayerImpl> layer = LayerImpl::Create(m_hostImpl->active_tree( ), id);
190 layer->SetScrollable(true); 190 layer->SetScrollable(true);
191 layer->SetDrawsContent(true); 191 layer->SetDrawsContent(true);
192 layer->SetBounds(size); 192 layer->SetBounds(size);
193 layer->SetContentBounds(size); 193 layer->SetContentBounds(size);
194 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height() * 2)); 194 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, size.height() * 2));
195 return layer.Pass(); 195 return layer.Pass();
196 } 196 }
197 197
198 void initializeRendererAndDrawFrame() 198 void initializeRendererAndDrawFrame()
199 { 199 {
200 m_hostImpl->initializeRenderer(createOutputSurface()); 200 m_hostImpl->InitializeRenderer(createOutputSurface());
201 LayerTreeHostImpl::FrameData frame; 201 LayerTreeHostImpl::FrameData frame;
202 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 202 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
203 m_hostImpl->drawLayers(frame); 203 m_hostImpl->DrawLayers(&frame);
204 m_hostImpl->didDrawAllLayers(frame); 204 m_hostImpl->DidDrawAllLayers(frame);
205 } 205 }
206 206
207 void pinchZoomPanViewportForcesCommitRedraw(const float deviceScaleFactor); 207 void pinchZoomPanViewportForcesCommitRedraw(const float deviceScaleFactor);
208 void pinchZoomPanViewportTest(const float deviceScaleFactor); 208 void pinchZoomPanViewportTest(const float deviceScaleFactor);
209 void pinchZoomPanViewportAndScrollTest(const float deviceScaleFactor); 209 void pinchZoomPanViewportAndScrollTest(const float deviceScaleFactor);
210 void pinchZoomPanViewportAndScrollBoundaryTest(const float deviceScaleFactor ); 210 void pinchZoomPanViewportAndScrollBoundaryTest(const float deviceScaleFactor );
211 211
212 protected: 212 protected:
213 virtual scoped_ptr<OutputSurface> createOutputSurface() { return createFakeO utputSurface(); } 213 virtual scoped_ptr<OutputSurface> createOutputSurface() { return createFakeO utputSurface(); }
214 214
215 void drawOneFrame() { 215 void drawOneFrame() {
216 LayerTreeHostImpl::FrameData frameData; 216 LayerTreeHostImpl::FrameData frameData;
217 m_hostImpl->prepareToDraw(frameData); 217 m_hostImpl->PrepareToDraw(&frameData);
218 m_hostImpl->didDrawAllLayers(frameData); 218 m_hostImpl->DidDrawAllLayers(frameData);
219 } 219 }
220 220
221 FakeProxy m_proxy; 221 FakeProxy m_proxy;
222 DebugScopedSetImplThread m_alwaysImplThread; 222 DebugScopedSetImplThread m_alwaysImplThread;
223 DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; 223 DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked;
224 224
225 scoped_ptr<LayerTreeHostImpl> m_hostImpl; 225 scoped_ptr<LayerTreeHostImpl> m_hostImpl;
226 bool m_onCanDrawStateChangedCalled; 226 bool m_onCanDrawStateChangedCalled;
227 bool m_hasPendingTree; 227 bool m_hasPendingTree;
228 bool m_didRequestCommit; 228 bool m_didRequestCommit;
229 bool m_didRequestRedraw; 229 bool m_didRequestRedraw;
230 bool m_didUploadVisibleHighResolutionTile; 230 bool m_didUploadVisibleHighResolutionTile;
231 bool m_reduceMemoryResult; 231 bool m_reduceMemoryResult;
232 }; 232 };
233 233
234 class TestWebGraphicsContext3DMakeCurrentFails : public TestWebGraphicsContext3D { 234 class TestWebGraphicsContext3DMakeCurrentFails : public TestWebGraphicsContext3D {
235 public: 235 public:
236 virtual bool makeContextCurrent() { return false; } 236 virtual bool makeContextCurrent() { return false; }
237 }; 237 };
238 238
239 TEST_F(LayerTreeHostImplTest, notifyIfCanDrawChanged) 239 TEST_F(LayerTreeHostImplTest, notifyIfCanDrawChanged)
240 { 240 {
241 // Note: It is not possible to disable the renderer once it has been set, 241 // Note: It is not possible to disable the renderer once it has been set,
242 // so we do not need to test that disabling the renderer notifies us 242 // so we do not need to test that disabling the renderer notifies us
243 // that canDraw changed. 243 // that canDraw changed.
244 EXPECT_FALSE(m_hostImpl->canDraw()); 244 EXPECT_FALSE(m_hostImpl->CanDraw());
245 m_onCanDrawStateChangedCalled = false; 245 m_onCanDrawStateChangedCalled = false;
246 246
247 setupScrollAndContentsLayers(gfx::Size(100, 100)); 247 setupScrollAndContentsLayers(gfx::Size(100, 100));
248 EXPECT_TRUE(m_hostImpl->canDraw()); 248 EXPECT_TRUE(m_hostImpl->CanDraw());
249 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 249 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
250 m_onCanDrawStateChangedCalled = false; 250 m_onCanDrawStateChangedCalled = false;
251 251
252 // Toggle the root layer to make sure it toggles canDraw 252 // Toggle the root layer to make sure it toggles canDraw
253 m_hostImpl->activeTree()->SetRootLayer(scoped_ptr<LayerImpl>()); 253 m_hostImpl->active_tree()->SetRootLayer(scoped_ptr<LayerImpl>());
254 EXPECT_FALSE(m_hostImpl->canDraw()); 254 EXPECT_FALSE(m_hostImpl->CanDraw());
255 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 255 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
256 m_onCanDrawStateChangedCalled = false; 256 m_onCanDrawStateChangedCalled = false;
257 257
258 setupScrollAndContentsLayers(gfx::Size(100, 100)); 258 setupScrollAndContentsLayers(gfx::Size(100, 100));
259 EXPECT_TRUE(m_hostImpl->canDraw()); 259 EXPECT_TRUE(m_hostImpl->CanDraw());
260 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 260 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
261 m_onCanDrawStateChangedCalled = false; 261 m_onCanDrawStateChangedCalled = false;
262 262
263 // Toggle the device viewport size to make sure it toggles canDraw. 263 // Toggle the device viewport size to make sure it toggles canDraw.
264 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(0, 0)); 264 m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(0, 0));
265 EXPECT_FALSE(m_hostImpl->canDraw()); 265 EXPECT_FALSE(m_hostImpl->CanDraw());
266 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 266 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
267 m_onCanDrawStateChangedCalled = false; 267 m_onCanDrawStateChangedCalled = false;
268 268
269 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); 269 m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
270 EXPECT_TRUE(m_hostImpl->canDraw()); 270 EXPECT_TRUE(m_hostImpl->CanDraw());
271 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 271 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
272 m_onCanDrawStateChangedCalled = false; 272 m_onCanDrawStateChangedCalled = false;
273 273
274 // Toggle contents textures purged without causing any evictions, 274 // Toggle contents textures purged without causing any evictions,
275 // and make sure that it does not change canDraw. 275 // and make sure that it does not change canDraw.
276 setReduceMemoryResult(false); 276 setReduceMemoryResult(false);
277 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( 277 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
278 m_hostImpl->memoryAllocationLimitBytes() - 1)); 278 m_hostImpl->memory_allocation_limit_bytes() - 1));
279 EXPECT_TRUE(m_hostImpl->canDraw()); 279 EXPECT_TRUE(m_hostImpl->CanDraw());
280 EXPECT_FALSE(m_onCanDrawStateChangedCalled); 280 EXPECT_FALSE(m_onCanDrawStateChangedCalled);
281 m_onCanDrawStateChangedCalled = false; 281 m_onCanDrawStateChangedCalled = false;
282 282
283 // Toggle contents textures purged to make sure it toggles canDraw. 283 // Toggle contents textures purged to make sure it toggles canDraw.
284 setReduceMemoryResult(true); 284 setReduceMemoryResult(true);
285 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( 285 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
286 m_hostImpl->memoryAllocationLimitBytes() - 1)); 286 m_hostImpl->memory_allocation_limit_bytes() - 1));
287 EXPECT_FALSE(m_hostImpl->canDraw()); 287 EXPECT_FALSE(m_hostImpl->CanDraw());
288 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 288 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
289 m_onCanDrawStateChangedCalled = false; 289 m_onCanDrawStateChangedCalled = false;
290 290
291 m_hostImpl->activeTree()->ResetContentsTexturesPurged(); 291 m_hostImpl->active_tree()->ResetContentsTexturesPurged();
292 EXPECT_TRUE(m_hostImpl->canDraw()); 292 EXPECT_TRUE(m_hostImpl->CanDraw());
293 EXPECT_TRUE(m_onCanDrawStateChangedCalled); 293 EXPECT_TRUE(m_onCanDrawStateChangedCalled);
294 m_onCanDrawStateChangedCalled = false; 294 m_onCanDrawStateChangedCalled = false;
295 } 295 }
296 296
297 TEST_F(LayerTreeHostImplTest, scrollDeltaNoLayers) 297 TEST_F(LayerTreeHostImplTest, scrollDeltaNoLayers)
298 { 298 {
299 ASSERT_FALSE(m_hostImpl->rootLayer()); 299 ASSERT_FALSE(m_hostImpl->active_tree()->root_layer());
300 300
301 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 301 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
302 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); 302 ASSERT_EQ(scrollInfo->scrolls.size(), 0u);
303 } 303 }
304 304
305 TEST_F(LayerTreeHostImplTest, scrollDeltaTreeButNoChanges) 305 TEST_F(LayerTreeHostImplTest, scrollDeltaTreeButNoChanges)
306 { 306 {
307 { 307 {
308 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 308 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree() , 1);
309 root->AddChild(LayerImpl::Create(m_hostImpl->activeTree(), 2)); 309 root->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 2));
310 root->AddChild(LayerImpl::Create(m_hostImpl->activeTree(), 3)); 310 root->AddChild(LayerImpl::Create(m_hostImpl->active_tree(), 3));
311 root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->activeTree() , 4)); 311 root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->active_tree( ), 4));
312 root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->activeTree() , 5)); 312 root->children()[1]->AddChild(LayerImpl::Create(m_hostImpl->active_tree( ), 5));
313 root->children()[1]->children()[0]->AddChild(LayerImpl::Create(m_hostImp l->activeTree(), 6)); 313 root->children()[1]->children()[0]->AddChild(LayerImpl::Create(m_hostImp l->active_tree(), 6));
314 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 314 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
315 } 315 }
316 LayerImpl* root = m_hostImpl->rootLayer(); 316 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
317 317
318 expectClearedScrollDeltasRecursive(root); 318 expectClearedScrollDeltasRecursive(root);
319 319
320 scoped_ptr<ScrollAndScaleSet> scrollInfo; 320 scoped_ptr<ScrollAndScaleSet> scrollInfo;
321 321
322 scrollInfo = m_hostImpl->processScrollDeltas(); 322 scrollInfo = m_hostImpl->ProcessScrollDeltas();
323 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); 323 ASSERT_EQ(scrollInfo->scrolls.size(), 0u);
324 expectClearedScrollDeltasRecursive(root); 324 expectClearedScrollDeltasRecursive(root);
325 325
326 scrollInfo = m_hostImpl->processScrollDeltas(); 326 scrollInfo = m_hostImpl->ProcessScrollDeltas();
327 ASSERT_EQ(scrollInfo->scrolls.size(), 0u); 327 ASSERT_EQ(scrollInfo->scrolls.size(), 0u);
328 expectClearedScrollDeltasRecursive(root); 328 expectClearedScrollDeltasRecursive(root);
329 } 329 }
330 330
331 TEST_F(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls) 331 TEST_F(LayerTreeHostImplTest, scrollDeltaRepeatedScrolls)
332 { 332 {
333 gfx::Vector2d scrollOffset(20, 30); 333 gfx::Vector2d scrollOffset(20, 30);
334 gfx::Vector2d scrollDelta(11, -15); 334 gfx::Vector2d scrollDelta(11, -15);
335 { 335 {
336 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 336 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree() , 1);
337 root->SetScrollOffset(scrollOffset); 337 root->SetScrollOffset(scrollOffset);
338 root->SetScrollable(true); 338 root->SetScrollable(true);
339 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); 339 root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
340 root->ScrollBy(scrollDelta); 340 root->ScrollBy(scrollDelta);
341 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 341 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
342 } 342 }
343 LayerImpl* root = m_hostImpl->rootLayer(); 343 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
344 344
345 scoped_ptr<ScrollAndScaleSet> scrollInfo; 345 scoped_ptr<ScrollAndScaleSet> scrollInfo;
346 346
347 scrollInfo = m_hostImpl->processScrollDeltas(); 347 scrollInfo = m_hostImpl->ProcessScrollDeltas();
348 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); 348 ASSERT_EQ(scrollInfo->scrolls.size(), 1u);
349 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta); 349 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta);
350 expectContains(*scrollInfo, root->id(), scrollDelta); 350 expectContains(*scrollInfo, root->id(), scrollDelta);
351 351
352 gfx::Vector2d scrollDelta2(-5, 27); 352 gfx::Vector2d scrollDelta2(-5, 27);
353 root->ScrollBy(scrollDelta2); 353 root->ScrollBy(scrollDelta2);
354 scrollInfo = m_hostImpl->processScrollDeltas(); 354 scrollInfo = m_hostImpl->ProcessScrollDeltas();
355 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); 355 ASSERT_EQ(scrollInfo->scrolls.size(), 1u);
356 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2); 356 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2);
357 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2); 357 expectContains(*scrollInfo, root->id(), scrollDelta + scrollDelta2);
358 358
359 root->ScrollBy(gfx::Vector2d()); 359 root->ScrollBy(gfx::Vector2d());
360 scrollInfo = m_hostImpl->processScrollDeltas(); 360 scrollInfo = m_hostImpl->ProcessScrollDeltas();
361 EXPECT_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2); 361 EXPECT_EQ(root->sent_scroll_delta(), scrollDelta + scrollDelta2);
362 } 362 }
363 363
364 TEST_F(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) 364 TEST_F(LayerTreeHostImplTest, scrollRootCallsCommitAndRedraw)
365 { 365 {
366 setupScrollAndContentsLayers(gfx::Size(100, 100)); 366 setupScrollAndContentsLayers(gfx::Size(100, 100));
367 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 367 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
368 initializeRendererAndDrawFrame(); 368 initializeRendererAndDrawFrame();
369 369
370 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 370 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
371 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 371 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
372 m_hostImpl->scrollEnd(); 372 m_hostImpl->ScrollEnd();
373 EXPECT_TRUE(m_didRequestRedraw); 373 EXPECT_TRUE(m_didRequestRedraw);
374 EXPECT_TRUE(m_didRequestCommit); 374 EXPECT_TRUE(m_didRequestCommit);
375 } 375 }
376 376
377 TEST_F(LayerTreeHostImplTest, scrollWithoutRootLayer) 377 TEST_F(LayerTreeHostImplTest, scrollWithoutRootLayer)
378 { 378 {
379 // We should not crash when trying to scroll an empty layer tree. 379 // We should not crash when trying to scroll an empty layer tree.
380 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored); 380 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored);
381 } 381 }
382 382
383 TEST_F(LayerTreeHostImplTest, scrollWithoutRenderer) 383 TEST_F(LayerTreeHostImplTest, scrollWithoutRenderer)
384 { 384 {
385 LayerTreeSettings settings; 385 LayerTreeSettings settings;
386 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); 386 m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy);
387 387
388 // Initialization will fail here. 388 // Initialization will fail here.
389 m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit ::WebGraphicsContext3D>(new TestWebGraphicsContext3DMakeCurrentFails)).PassAs<Ou tputSurface>()); 389 m_hostImpl->InitializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit ::WebGraphicsContext3D>(new TestWebGraphicsContext3DMakeCurrentFails)).PassAs<Ou tputSurface>());
390 m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 390 m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
391 391
392 setupScrollAndContentsLayers(gfx::Size(100, 100)); 392 setupScrollAndContentsLayers(gfx::Size(100, 100));
393 393
394 // We should not crash when trying to scroll after the renderer initializati on fails. 394 // We should not crash when trying to scroll after the renderer initializati on fails.
395 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored); 395 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored);
396 } 396 }
397 397
398 TEST_F(LayerTreeHostImplTest, replaceTreeWhileScrolling) 398 TEST_F(LayerTreeHostImplTest, replaceTreeWhileScrolling)
399 { 399 {
400 const int scrollLayerId = 1; 400 const int scrollLayerId = 1;
401 401
402 setupScrollAndContentsLayers(gfx::Size(100, 100)); 402 setupScrollAndContentsLayers(gfx::Size(100, 100));
403 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 403 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
404 initializeRendererAndDrawFrame(); 404 initializeRendererAndDrawFrame();
405 405
406 // We should not crash if the tree is replaced while we are scrolling. 406 // We should not crash if the tree is replaced while we are scrolling.
407 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 407 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
408 m_hostImpl->activeTree()->DetachLayerTree(); 408 m_hostImpl->active_tree()->DetachLayerTree();
409 409
410 setupScrollAndContentsLayers(gfx::Size(100, 100)); 410 setupScrollAndContentsLayers(gfx::Size(100, 100));
411 411
412 // We should still be scrolling, because the scrolled layer also exists in t he new tree. 412 // We should still be scrolling, because the scrolled layer also exists in t he new tree.
413 gfx::Vector2d scrollDelta(0, 10); 413 gfx::Vector2d scrollDelta(0, 10);
414 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 414 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
415 m_hostImpl->scrollEnd(); 415 m_hostImpl->ScrollEnd();
416 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 416 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
417 expectContains(*scrollInfo, scrollLayerId, scrollDelta); 417 expectContains(*scrollInfo, scrollLayerId, scrollDelta);
418 } 418 }
419 419
420 TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll) 420 TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndScroll)
421 { 421 {
422 setupScrollAndContentsLayers(gfx::Size(100, 100)); 422 setupScrollAndContentsLayers(gfx::Size(100, 100));
423 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 423 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
424 initializeRendererAndDrawFrame(); 424 initializeRendererAndDrawFrame();
425 425
426 // We should be able to scroll even if the root layer loses its render surfa ce after the most 426 // We should be able to scroll even if the root layer loses its render surfa ce after the most
427 // recent render. 427 // recent render.
428 m_hostImpl->rootLayer()->ClearRenderSurface(); 428 m_hostImpl->active_tree()->root_layer()->ClearRenderSurface();
429 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 429 m_hostImpl->active_tree()->set_needs_update_draw_properties();
430 430
431 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 431 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
432 } 432 }
433 433
434 TEST_F(LayerTreeHostImplTest, wheelEventHandlers) 434 TEST_F(LayerTreeHostImplTest, wheelEventHandlers)
435 { 435 {
436 setupScrollAndContentsLayers(gfx::Size(100, 100)); 436 setupScrollAndContentsLayers(gfx::Size(100, 100));
437 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 437 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
438 initializeRendererAndDrawFrame(); 438 initializeRendererAndDrawFrame();
439 LayerImpl* root = m_hostImpl->rootLayer(); 439 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
440 440
441 root->SetHaveWheelEventHandlers(true); 441 root->SetHaveWheelEventHandlers(true);
442 442
443 // With registered event handlers, wheel scrolls have to go to the main thre ad. 443 // With registered event handlers, wheel scrolls have to go to the main thre ad.
444 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread); 444 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread);
445 445
446 // But gesture scrolls can still be handled. 446 // But gesture scrolls can still be handled.
447 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted); 447 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted);
448 } 448 }
449 449
450 TEST_F(LayerTreeHostImplTest, shouldScrollOnMainThread) 450 TEST_F(LayerTreeHostImplTest, shouldScrollOnMainThread)
451 { 451 {
452 setupScrollAndContentsLayers(gfx::Size(100, 100)); 452 setupScrollAndContentsLayers(gfx::Size(100, 100));
453 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 453 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
454 initializeRendererAndDrawFrame(); 454 initializeRendererAndDrawFrame();
455 LayerImpl* root = m_hostImpl->rootLayer(); 455 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
456 456
457 root->SetShouldScrollOnMainThread(true); 457 root->SetShouldScrollOnMainThread(true);
458 458
459 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread); 459 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread);
460 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollOnMainThread); 460 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollOnMainThread);
461 } 461 }
462 462
463 TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionBasic) 463 TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionBasic)
464 { 464 {
465 setupScrollAndContentsLayers(gfx::Size(200, 200)); 465 setupScrollAndContentsLayers(gfx::Size(200, 200));
466 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); 466 m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
467 467
468 LayerImpl* root = m_hostImpl->rootLayer(); 468 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
469 root->SetContentsScale(2, 2); 469 root->SetContentsScale(2, 2);
470 root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); 470 root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
471 471
472 initializeRendererAndDrawFrame(); 472 initializeRendererAndDrawFrame();
473 473
474 // All scroll types inside the non-fast scrollable region should fail. 474 // All scroll types inside the non-fast scrollable region should fail.
475 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh eel), InputHandlerClient::ScrollOnMainThread); 475 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(25, 25), InputHandlerClient::Wh eel), InputHandlerClient::ScrollOnMainThread);
476 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(25, 25), InputHandlerClient::Ge sture), InputHandlerClient::ScrollOnMainThread); 476 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(25, 25), InputHandlerClient::Ge sture), InputHandlerClient::ScrollOnMainThread);
477 477
478 // All scroll types outside this region should succeed. 478 // All scroll types outside this region should succeed.
479 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Wh eel), InputHandlerClient::ScrollStarted); 479 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(75, 75), InputHandlerClient::Wh eel), InputHandlerClient::ScrollStarted);
480 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 480 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
481 m_hostImpl->scrollEnd(); 481 m_hostImpl->ScrollEnd();
482 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(75, 75), InputHandlerClient::Ge sture), InputHandlerClient::ScrollStarted); 482 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(75, 75), InputHandlerClient::Ge sture), InputHandlerClient::ScrollStarted);
483 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 483 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
484 m_hostImpl->scrollEnd(); 484 m_hostImpl->ScrollEnd();
485 } 485 }
486 486
487 TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset) 487 TEST_F(LayerTreeHostImplTest, nonFastScrollableRegionWithOffset)
488 { 488 {
489 setupScrollAndContentsLayers(gfx::Size(200, 200)); 489 setupScrollAndContentsLayers(gfx::Size(200, 200));
490 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); 490 m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
491 491
492 LayerImpl* root = m_hostImpl->rootLayer(); 492 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
493 root->SetContentsScale(2, 2); 493 root->SetContentsScale(2, 2);
494 root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); 494 root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
495 root->SetPosition(gfx::PointF(-25, 0)); 495 root->SetPosition(gfx::PointF(-25, 0));
496 496
497 initializeRendererAndDrawFrame(); 497 initializeRendererAndDrawFrame();
498 498
499 // This point would fall into the non-fast scrollable region except that we' ve moved the layer down by 25 pixels. 499 // This point would fall into the non-fast scrollable region except that we' ve moved the layer down by 25 pixels.
500 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(40, 10), InputHandlerClient::Wh eel), InputHandlerClient::ScrollStarted); 500 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(40, 10), InputHandlerClient::Wh eel), InputHandlerClient::ScrollStarted);
501 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 1)); 501 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 1));
502 m_hostImpl->scrollEnd(); 502 m_hostImpl->ScrollEnd();
503 503
504 // This point is still inside the non-fast region. 504 // This point is still inside the non-fast region.
505 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(10, 10), InputHandlerClient::Wh eel), InputHandlerClient::ScrollOnMainThread); 505 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(10, 10), InputHandlerClient::Wh eel), InputHandlerClient::ScrollOnMainThread);
506 } 506 }
507 507
508 TEST_F(LayerTreeHostImplTest, scrollByReturnsCorrectValue) 508 TEST_F(LayerTreeHostImplTest, scrollByReturnsCorrectValue)
509 { 509 {
510 setupScrollAndContentsLayers(gfx::Size(200, 200)); 510 setupScrollAndContentsLayers(gfx::Size(200, 200));
511 m_hostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); 511 m_hostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
512 512
513 initializeRendererAndDrawFrame(); 513 initializeRendererAndDrawFrame();
514 514
515 EXPECT_EQ(InputHandlerClient::ScrollStarted, 515 EXPECT_EQ(InputHandlerClient::ScrollStarted,
516 m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture)); 516 m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gesture));
517 517
518 // Trying to scroll to the left/top will not succeed. 518 // Trying to scroll to the left/top will not succeed.
519 EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); 519 EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)));
520 EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, -10))); 520 EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)));
521 EXPECT_FALSE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); 521 EXPECT_FALSE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10)));
522 522
523 // Scrolling to the right/bottom will succeed. 523 // Scrolling to the right/bottom will succeed.
524 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(10, 0))); 524 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)));
525 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10))); 525 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)));
526 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(10, 10))); 526 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, 10)));
527 527
528 // Scrolling to left/top will now succeed. 528 // Scrolling to left/top will now succeed.
529 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); 529 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)));
530 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, -10))); 530 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)));
531 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); 531 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10)));
532 532
533 // Scrolling diagonally against an edge will succeed. 533 // Scrolling diagonally against an edge will succeed.
534 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(10, -10))); 534 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(10, -10)));
535 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); 535 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)));
536 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(-10, 10))); 536 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 10)));
537 537
538 // Trying to scroll more than the available space will also succeed. 538 // Trying to scroll more than the available space will also succeed.
539 EXPECT_TRUE(m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(5000, 5000))); 539 EXPECT_TRUE(m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(5000, 5000)));
540 } 540 }
541 541
542 TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndHitTestTouchHandlerRegion ) 542 TEST_F(LayerTreeHostImplTest, clearRootRenderSurfaceAndHitTestTouchHandlerRegion )
543 { 543 {
544 setupScrollAndContentsLayers(gfx::Size(100, 100)); 544 setupScrollAndContentsLayers(gfx::Size(100, 100));
545 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 545 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
546 initializeRendererAndDrawFrame(); 546 initializeRendererAndDrawFrame();
547 547
548 // We should be able to hit test for touch event handlers even if the root l ayer loses 548 // We should be able to hit test for touch event handlers even if the root l ayer loses
549 // its render surface after the most recent render. 549 // its render surface after the most recent render.
550 m_hostImpl->rootLayer()->ClearRenderSurface(); 550 m_hostImpl->active_tree()->root_layer()->ClearRenderSurface();
551 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 551 m_hostImpl->active_tree()->set_needs_update_draw_properties();
552 552
553 EXPECT_EQ(m_hostImpl->haveTouchEventHandlersAt(gfx::Point(0, 0)), false); 553 EXPECT_EQ(m_hostImpl->HaveTouchEventHandlersAt(gfx::Point(0, 0)), false);
554 } 554 }
555 555
556 TEST_F(LayerTreeHostImplTest, implPinchZoom) 556 TEST_F(LayerTreeHostImplTest, implPinchZoom)
557 { 557 {
558 setupScrollAndContentsLayers(gfx::Size(100, 100)); 558 setupScrollAndContentsLayers(gfx::Size(100, 100));
559 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 559 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
560 initializeRendererAndDrawFrame(); 560 initializeRendererAndDrawFrame();
561 561
562 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); 562 LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer();
563 DCHECK(scrollLayer); 563 DCHECK(scrollLayer);
564 564
565 const float minPageScale = 1, maxPageScale = 4; 565 const float minPageScale = 1, maxPageScale = 4;
566 const gfx::Transform identityScaleTransform; 566 const gfx::Transform identityScaleTransform;
567 567
568 // The impl-based pinch zoom should adjust the max scroll position. 568 // The impl-based pinch zoom should adjust the max scroll position.
569 { 569 {
570 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 570 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
571 m_hostImpl->activeTree()->SetPageScaleDelta(1); 571 m_hostImpl->active_tree()->SetPageScaleDelta(1);
572 scrollLayer->SetImplTransform(identityScaleTransform); 572 scrollLayer->SetImplTransform(identityScaleTransform);
573 scrollLayer->SetScrollDelta(gfx::Vector2d()); 573 scrollLayer->SetScrollDelta(gfx::Vector2d());
574 574
575 float pageScaleDelta = 2; 575 float pageScaleDelta = 2;
576 m_hostImpl->pinchGestureBegin(); 576 m_hostImpl->PinchGestureBegin();
577 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); 577 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50));
578 m_hostImpl->pinchGestureEnd(); 578 m_hostImpl->PinchGestureEnd();
579 EXPECT_TRUE(m_didRequestRedraw); 579 EXPECT_TRUE(m_didRequestRedraw);
580 EXPECT_TRUE(m_didRequestCommit); 580 EXPECT_TRUE(m_didRequestCommit);
581 581
582 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 582 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
583 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); 583 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta);
584 584
585 EXPECT_EQ(gfx::Vector2d(75, 75), m_hostImpl->rootLayer()->max_scroll_off set()); 585 EXPECT_EQ(gfx::Vector2d(75, 75), m_hostImpl->active_tree()->root_layer() ->max_scroll_offset());
586 } 586 }
587 587
588 // Scrolling after a pinch gesture should always be in local space. The scr oll deltas do not 588 // Scrolling after a pinch gesture should always be in local space. The scr oll deltas do not
589 // have the page scale factor applied. 589 // have the page scale factor applied.
590 { 590 {
591 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 591 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
592 m_hostImpl->activeTree()->SetPageScaleDelta(1); 592 m_hostImpl->active_tree()->SetPageScaleDelta(1);
593 scrollLayer->SetImplTransform(identityScaleTransform); 593 scrollLayer->SetImplTransform(identityScaleTransform);
594 scrollLayer->SetScrollDelta(gfx::Vector2d()); 594 scrollLayer->SetScrollDelta(gfx::Vector2d());
595 595
596 float pageScaleDelta = 2; 596 float pageScaleDelta = 2;
597 m_hostImpl->pinchGestureBegin(); 597 m_hostImpl->PinchGestureBegin();
598 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); 598 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0));
599 m_hostImpl->pinchGestureEnd(); 599 m_hostImpl->PinchGestureEnd();
600 600
601 gfx::Vector2d scrollDelta(0, 10); 601 gfx::Vector2d scrollDelta(0, 10);
602 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted); 602 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted);
603 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 603 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
604 m_hostImpl->scrollEnd(); 604 m_hostImpl->ScrollEnd();
605 605
606 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 606 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
607 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD elta); 607 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer( )->id(), scrollDelta);
608 } 608 }
609 } 609 }
610 610
611 TEST_F(LayerTreeHostImplTest, pinchGesture) 611 TEST_F(LayerTreeHostImplTest, pinchGesture)
612 { 612 {
613 setupScrollAndContentsLayers(gfx::Size(100, 100)); 613 setupScrollAndContentsLayers(gfx::Size(100, 100));
614 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 614 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
615 initializeRendererAndDrawFrame(); 615 initializeRendererAndDrawFrame();
616 616
617 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); 617 LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer();
618 DCHECK(scrollLayer); 618 DCHECK(scrollLayer);
619 619
620 const float minPageScale = 1; 620 const float minPageScale = 1;
621 const float maxPageScale = 4; 621 const float maxPageScale = 4;
622 const gfx::Transform identityScaleTransform; 622 const gfx::Transform identityScaleTransform;
623 623
624 // Basic pinch zoom in gesture 624 // Basic pinch zoom in gesture
625 { 625 {
626 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 626 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
627 scrollLayer->SetImplTransform(identityScaleTransform); 627 scrollLayer->SetImplTransform(identityScaleTransform);
628 scrollLayer->SetScrollDelta(gfx::Vector2d()); 628 scrollLayer->SetScrollDelta(gfx::Vector2d());
629 629
630 float pageScaleDelta = 2; 630 float pageScaleDelta = 2;
631 m_hostImpl->pinchGestureBegin(); 631 m_hostImpl->PinchGestureBegin();
632 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); 632 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50));
633 m_hostImpl->pinchGestureEnd(); 633 m_hostImpl->PinchGestureEnd();
634 EXPECT_TRUE(m_didRequestRedraw); 634 EXPECT_TRUE(m_didRequestRedraw);
635 EXPECT_TRUE(m_didRequestCommit); 635 EXPECT_TRUE(m_didRequestCommit);
636 636
637 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 637 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
638 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); 638 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta);
639 } 639 }
640 640
641 // Zoom-in clamping 641 // Zoom-in clamping
642 { 642 {
643 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 643 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
644 scrollLayer->SetImplTransform(identityScaleTransform); 644 scrollLayer->SetImplTransform(identityScaleTransform);
645 scrollLayer->SetScrollDelta(gfx::Vector2d()); 645 scrollLayer->SetScrollDelta(gfx::Vector2d());
646 float pageScaleDelta = 10; 646 float pageScaleDelta = 10;
647 647
648 m_hostImpl->pinchGestureBegin(); 648 m_hostImpl->PinchGestureBegin();
649 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50)); 649 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(50, 50));
650 m_hostImpl->pinchGestureEnd(); 650 m_hostImpl->PinchGestureEnd();
651 651
652 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 652 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
653 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale); 653 EXPECT_EQ(scrollInfo->pageScaleDelta, maxPageScale);
654 } 654 }
655 655
656 // Zoom-out clamping 656 // Zoom-out clamping
657 { 657 {
658 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 658 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
659 scrollLayer->SetImplTransform(identityScaleTransform); 659 scrollLayer->SetImplTransform(identityScaleTransform);
660 scrollLayer->SetScrollDelta(gfx::Vector2d()); 660 scrollLayer->SetScrollDelta(gfx::Vector2d());
661 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); 661 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50));
662 662
663 float pageScaleDelta = 0.1f; 663 float pageScaleDelta = 0.1f;
664 m_hostImpl->pinchGestureBegin(); 664 m_hostImpl->PinchGestureBegin();
665 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0)); 665 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(0, 0));
666 m_hostImpl->pinchGestureEnd(); 666 m_hostImpl->PinchGestureEnd();
667 667
668 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 668 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
669 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); 669 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale);
670 670
671 EXPECT_TRUE(scrollInfo->scrolls.empty()); 671 EXPECT_TRUE(scrollInfo->scrolls.empty());
672 } 672 }
673 673
674 // Two-finger panning should not happen based on pinch events only 674 // Two-finger panning should not happen based on pinch events only
675 { 675 {
676 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 676 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
677 scrollLayer->SetImplTransform(identityScaleTransform); 677 scrollLayer->SetImplTransform(identityScaleTransform);
678 scrollLayer->SetScrollDelta(gfx::Vector2d()); 678 scrollLayer->SetScrollDelta(gfx::Vector2d());
679 scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20)); 679 scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20));
680 680
681 float pageScaleDelta = 1; 681 float pageScaleDelta = 1;
682 m_hostImpl->pinchGestureBegin(); 682 m_hostImpl->PinchGestureBegin();
683 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10)); 683 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10));
684 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20)); 684 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20));
685 m_hostImpl->pinchGestureEnd(); 685 m_hostImpl->PinchGestureEnd();
686 686
687 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 687 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
688 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); 688 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta);
689 EXPECT_TRUE(scrollInfo->scrolls.empty()); 689 EXPECT_TRUE(scrollInfo->scrolls.empty());
690 } 690 }
691 691
692 // Two-finger panning should work with interleaved scroll events 692 // Two-finger panning should work with interleaved scroll events
693 { 693 {
694 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 694 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
695 scrollLayer->SetImplTransform(identityScaleTransform); 695 scrollLayer->SetImplTransform(identityScaleTransform);
696 scrollLayer->SetScrollDelta(gfx::Vector2d()); 696 scrollLayer->SetScrollDelta(gfx::Vector2d());
697 scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20)); 697 scrollLayer->SetScrollOffset(gfx::Vector2d(20, 20));
698 698
699 float pageScaleDelta = 1; 699 float pageScaleDelta = 1;
700 m_hostImpl->scrollBegin(gfx::Point(10, 10), InputHandlerClient::Wheel); 700 m_hostImpl->ScrollBegin(gfx::Point(10, 10), InputHandlerClient::Wheel);
701 m_hostImpl->pinchGestureBegin(); 701 m_hostImpl->PinchGestureBegin();
702 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10)); 702 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(10, 10));
703 m_hostImpl->scrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10)); 703 m_hostImpl->ScrollBy(gfx::Point(10, 10), gfx::Vector2d(-10, -10));
704 m_hostImpl->pinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20)); 704 m_hostImpl->PinchGestureUpdate(pageScaleDelta, gfx::Point(20, 20));
705 m_hostImpl->pinchGestureEnd(); 705 m_hostImpl->PinchGestureEnd();
706 m_hostImpl->scrollEnd(); 706 m_hostImpl->ScrollEnd();
707 707
708 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 708 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
709 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta); 709 EXPECT_EQ(scrollInfo->pageScaleDelta, pageScaleDelta);
710 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-10, -10)); 710 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-10, -10));
711 } 711 }
712 } 712 }
713 713
714 TEST_F(LayerTreeHostImplTest, pageScaleAnimation) 714 TEST_F(LayerTreeHostImplTest, pageScaleAnimation)
715 { 715 {
716 setupScrollAndContentsLayers(gfx::Size(100, 100)); 716 setupScrollAndContentsLayers(gfx::Size(100, 100));
717 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 717 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
718 initializeRendererAndDrawFrame(); 718 initializeRendererAndDrawFrame();
719 719
720 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); 720 LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer();
721 DCHECK(scrollLayer); 721 DCHECK(scrollLayer);
722 722
723 const float minPageScale = 0.5; 723 const float minPageScale = 0.5;
724 const float maxPageScale = 4; 724 const float maxPageScale = 4;
725 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS econds(1); 725 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS econds(1);
726 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 726 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
727 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; 727 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2;
728 const base::TimeTicks endTime = startTime + duration; 728 const base::TimeTicks endTime = startTime + duration;
729 const gfx::Transform identityScaleTransform; 729 const gfx::Transform identityScaleTransform;
730 730
731 // Non-anchor zoom-in 731 // Non-anchor zoom-in
732 { 732 {
733 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 733 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
734 scrollLayer->SetImplTransform(identityScaleTransform); 734 scrollLayer->SetImplTransform(identityScaleTransform);
735 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); 735 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50));
736 736
737 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(0, 0), false, 2, start Time, duration); 737 m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(0, 0), false, 2, start Time, duration);
738 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); 738 m_hostImpl->Animate(halfwayThroughAnimation, base::Time());
739 EXPECT_TRUE(m_didRequestRedraw); 739 EXPECT_TRUE(m_didRequestRedraw);
740 m_hostImpl->animate(endTime, base::Time()); 740 m_hostImpl->Animate(endTime, base::Time());
741 EXPECT_TRUE(m_didRequestCommit); 741 EXPECT_TRUE(m_didRequestCommit);
742 742
743 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 743 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
744 EXPECT_EQ(scrollInfo->pageScaleDelta, 2); 744 EXPECT_EQ(scrollInfo->pageScaleDelta, 2);
745 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); 745 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50));
746 } 746 }
747 747
748 // Anchor zoom-out 748 // Anchor zoom-out
749 { 749 {
750 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 750 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
751 scrollLayer->SetImplTransform(identityScaleTransform); 751 scrollLayer->SetImplTransform(identityScaleTransform);
752 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); 752 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50));
753 753
754 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(25, 25), true, minPage Scale, startTime, duration); 754 m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(25, 25), true, minPage Scale, startTime, duration);
755 m_hostImpl->animate(endTime, base::Time()); 755 m_hostImpl->Animate(endTime, base::Time());
756 EXPECT_TRUE(m_didRequestRedraw); 756 EXPECT_TRUE(m_didRequestRedraw);
757 EXPECT_TRUE(m_didRequestCommit); 757 EXPECT_TRUE(m_didRequestCommit);
758 758
759 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 759 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
760 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale); 760 EXPECT_EQ(scrollInfo->pageScaleDelta, minPageScale);
761 // Pushed to (0,0) via clamping against contents layer size. 761 // Pushed to (0,0) via clamping against contents layer size.
762 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50)); 762 expectContains(*scrollInfo, scrollLayer->id(), gfx::Vector2d(-50, -50));
763 } 763 }
764 } 764 }
765 765
766 TEST_F(LayerTreeHostImplTest, pageScaleAnimationNoOp) 766 TEST_F(LayerTreeHostImplTest, pageScaleAnimationNoOp)
767 { 767 {
768 setupScrollAndContentsLayers(gfx::Size(100, 100)); 768 setupScrollAndContentsLayers(gfx::Size(100, 100));
769 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 769 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
770 initializeRendererAndDrawFrame(); 770 initializeRendererAndDrawFrame();
771 771
772 LayerImpl* scrollLayer = m_hostImpl->rootScrollLayer(); 772 LayerImpl* scrollLayer = m_hostImpl->RootScrollLayer();
773 DCHECK(scrollLayer); 773 DCHECK(scrollLayer);
774 774
775 const float minPageScale = 0.5; 775 const float minPageScale = 0.5;
776 const float maxPageScale = 4; 776 const float maxPageScale = 4;
777 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS econds(1); 777 const base::TimeTicks startTime = base::TimeTicks() + base::TimeDelta::FromS econds(1);
778 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); 778 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
779 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2; 779 const base::TimeTicks halfwayThroughAnimation = startTime + duration / 2;
780 const base::TimeTicks endTime = startTime + duration; 780 const base::TimeTicks endTime = startTime + duration;
781 const gfx::Transform identityScaleTransform; 781 const gfx::Transform identityScaleTransform;
782 782
783 // Anchor zoom with unchanged page scale should not change scroll or scale. 783 // Anchor zoom with unchanged page scale should not change scroll or scale.
784 { 784 {
785 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, minPageScale, m axPageScale); 785 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, minPageScale, maxPageScale);
786 scrollLayer->SetImplTransform(identityScaleTransform); 786 scrollLayer->SetImplTransform(identityScaleTransform);
787 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50)); 787 scrollLayer->SetScrollOffset(gfx::Vector2d(50, 50));
788 788
789 m_hostImpl->startPageScaleAnimation(gfx::Vector2d(0, 0), true, 1, startT ime, duration); 789 m_hostImpl->StartPageScaleAnimation(gfx::Vector2d(0, 0), true, 1, startT ime, duration);
790 m_hostImpl->animate(halfwayThroughAnimation, base::Time()); 790 m_hostImpl->Animate(halfwayThroughAnimation, base::Time());
791 EXPECT_TRUE(m_didRequestRedraw); 791 EXPECT_TRUE(m_didRequestRedraw);
792 m_hostImpl->animate(endTime, base::Time()); 792 m_hostImpl->Animate(endTime, base::Time());
793 EXPECT_TRUE(m_didRequestCommit); 793 EXPECT_TRUE(m_didRequestCommit);
794 794
795 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 795 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
796 EXPECT_EQ(scrollInfo->pageScaleDelta, 1); 796 EXPECT_EQ(scrollInfo->pageScaleDelta, 1);
797 expectNone(*scrollInfo, scrollLayer->id()); 797 expectNone(*scrollInfo, scrollLayer->id());
798 } 798 }
799 } 799 }
800 800
801 TEST_F(LayerTreeHostImplTest, compositorFrameMetadata) 801 TEST_F(LayerTreeHostImplTest, compositorFrameMetadata)
802 { 802 {
803 setupScrollAndContentsLayers(gfx::Size(100, 100)); 803 setupScrollAndContentsLayers(gfx::Size(100, 100));
804 m_hostImpl->setViewportSize(gfx::Size(50, 50), gfx::Size(50, 50)); 804 m_hostImpl->SetViewportSize(gfx::Size(50, 50), gfx::Size(50, 50));
805 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1.0f, 0.5f, 4.0f); 805 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1.0f, 0.5f, 4.0f);
806 initializeRendererAndDrawFrame(); 806 initializeRendererAndDrawFrame();
807 807
808 { 808 {
809 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta(); 809 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta();
810 EXPECT_EQ(gfx::Vector2dF(0.0f, 0.0f), metadata.root_scroll_offset); 810 EXPECT_EQ(gfx::Vector2dF(0.0f, 0.0f), metadata.root_scroll_offset);
811 EXPECT_EQ(1.0f, metadata.page_scale_factor); 811 EXPECT_EQ(1.0f, metadata.page_scale_factor);
812 EXPECT_EQ(gfx::SizeF(50.0f, 50.0f), metadata.viewport_size); 812 EXPECT_EQ(gfx::SizeF(50.0f, 50.0f), metadata.viewport_size);
813 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); 813 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size);
814 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 814 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
815 EXPECT_EQ(4.0f, metadata.max_page_scale_factor); 815 EXPECT_EQ(4.0f, metadata.max_page_scale_factor);
816 } 816 }
817 817
818 // Scrolling should update metadata immediately. 818 // Scrolling should update metadata immediately.
819 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 819 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
820 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 820 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
821 { 821 {
822 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta(); 822 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta();
823 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); 823 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset);
824 } 824 }
825 m_hostImpl->scrollEnd(); 825 m_hostImpl->ScrollEnd();
826 826
827 { 827 {
828 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta(); 828 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta();
829 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); 829 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset);
830 } 830 }
831 831
832 // Page scale should update metadata correctly (shrinking only the viewport) . 832 // Page scale should update metadata correctly (shrinking only the viewport) .
833 m_hostImpl->pinchGestureBegin(); 833 m_hostImpl->PinchGestureBegin();
834 m_hostImpl->pinchGestureUpdate(2.0f, gfx::Point(0, 0)); 834 m_hostImpl->PinchGestureUpdate(2.0f, gfx::Point(0, 0));
835 m_hostImpl->pinchGestureEnd(); 835 m_hostImpl->PinchGestureEnd();
836 836
837 { 837 {
838 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta(); 838 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta();
839 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); 839 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset);
840 EXPECT_EQ(2, metadata.page_scale_factor); 840 EXPECT_EQ(2, metadata.page_scale_factor);
841 EXPECT_EQ(gfx::SizeF(25.0f, 25.0f), metadata.viewport_size); 841 EXPECT_EQ(gfx::SizeF(25.0f, 25.0f), metadata.viewport_size);
842 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); 842 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size);
843 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 843 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
844 EXPECT_EQ(4.0f, metadata.max_page_scale_factor); 844 EXPECT_EQ(4.0f, metadata.max_page_scale_factor);
845 } 845 }
846 846
847 // Likewise if set from the main thread. 847 // Likewise if set from the main thread.
848 m_hostImpl->processScrollDeltas(); 848 m_hostImpl->ProcessScrollDeltas();
849 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(4.0f, 0.5f, 4.0f); 849 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(4.0f, 0.5f, 4.0f);
850 m_hostImpl->activeTree()->SetPageScaleDelta(1.0f); 850 m_hostImpl->active_tree()->SetPageScaleDelta(1.0f);
851 { 851 {
852 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta(); 852 CompositorFrameMetadata metadata = m_hostImpl->MakeCompositorFrameMetada ta();
853 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset); 853 EXPECT_EQ(gfx::Vector2dF(0.0f, 10.0f), metadata.root_scroll_offset);
854 EXPECT_EQ(4.0f, metadata.page_scale_factor); 854 EXPECT_EQ(4.0f, metadata.page_scale_factor);
855 EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.viewport_size); 855 EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.viewport_size);
856 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size); 856 EXPECT_EQ(gfx::SizeF(100.0f, 100.0f), metadata.root_layer_size);
857 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); 857 EXPECT_EQ(0.5f, metadata.min_page_scale_factor);
858 EXPECT_EQ(4.0f, metadata.max_page_scale_factor); 858 EXPECT_EQ(4.0f, metadata.max_page_scale_factor);
859 } 859 }
860 } 860 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 902
903 private: 903 private:
904 bool m_didDrawCalled; 904 bool m_didDrawCalled;
905 bool m_willDrawCalled; 905 bool m_willDrawCalled;
906 }; 906 };
907 907
908 TEST_F(LayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer) 908 TEST_F(LayerTreeHostImplTest, didDrawNotCalledOnHiddenLayer)
909 { 909 {
910 // The root layer is always drawn, so run this test on a child layer that 910 // The root layer is always drawn, so run this test on a child layer that
911 // will be masked out by the root layer's bounds. 911 // will be masked out by the root layer's bounds.
912 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 1)); 912 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 1));
913 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa yer()); 913 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active _tree()->root_layer());
914 root->SetMasksToBounds(true); 914 root->SetMasksToBounds(true);
915 915
916 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->activeTree(), 2)); 916 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2));
917 DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[ 0]); 917 DidDrawCheckLayer* layer = static_cast<DidDrawCheckLayer*>(root->children()[ 0]);
918 // Ensure visibleContentRect for layer is empty 918 // Ensure visibleContentRect for layer is empty
919 layer->SetPosition(gfx::PointF(100, 100)); 919 layer->SetPosition(gfx::PointF(100, 100));
920 layer->SetBounds(gfx::Size(10, 10)); 920 layer->SetBounds(gfx::Size(10, 10));
921 layer->SetContentBounds(gfx::Size(10, 10)); 921 layer->SetContentBounds(gfx::Size(10, 10));
922 922
923 LayerTreeHostImpl::FrameData frame; 923 LayerTreeHostImpl::FrameData frame;
924 924
925 EXPECT_FALSE(layer->willDrawCalled()); 925 EXPECT_FALSE(layer->willDrawCalled());
926 EXPECT_FALSE(layer->didDrawCalled()); 926 EXPECT_FALSE(layer->didDrawCalled());
927 927
928 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 928 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
929 m_hostImpl->drawLayers(frame); 929 m_hostImpl->DrawLayers(&frame);
930 m_hostImpl->didDrawAllLayers(frame); 930 m_hostImpl->DidDrawAllLayers(frame);
931 931
932 EXPECT_FALSE(layer->willDrawCalled()); 932 EXPECT_FALSE(layer->willDrawCalled());
933 EXPECT_FALSE(layer->didDrawCalled()); 933 EXPECT_FALSE(layer->didDrawCalled());
934 934
935 EXPECT_TRUE(layer->visible_content_rect().IsEmpty()); 935 EXPECT_TRUE(layer->visible_content_rect().IsEmpty());
936 936
937 // Ensure visibleContentRect for layer layer is not empty 937 // Ensure visibleContentRect for layer layer is not empty
938 layer->SetPosition(gfx::PointF(0, 0)); 938 layer->SetPosition(gfx::PointF(0, 0));
939 939
940 EXPECT_FALSE(layer->willDrawCalled()); 940 EXPECT_FALSE(layer->willDrawCalled());
941 EXPECT_FALSE(layer->didDrawCalled()); 941 EXPECT_FALSE(layer->didDrawCalled());
942 942
943 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 943 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
944 m_hostImpl->drawLayers(frame); 944 m_hostImpl->DrawLayers(&frame);
945 m_hostImpl->didDrawAllLayers(frame); 945 m_hostImpl->DidDrawAllLayers(frame);
946 946
947 EXPECT_TRUE(layer->willDrawCalled()); 947 EXPECT_TRUE(layer->willDrawCalled());
948 EXPECT_TRUE(layer->didDrawCalled()); 948 EXPECT_TRUE(layer->didDrawCalled());
949 949
950 EXPECT_FALSE(layer->visible_content_rect().IsEmpty()); 950 EXPECT_FALSE(layer->visible_content_rect().IsEmpty());
951 } 951 }
952 952
953 TEST_F(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer) 953 TEST_F(LayerTreeHostImplTest, willDrawNotCalledOnOccludedLayer)
954 { 954 {
955 gfx::Size bigSize(1000, 1000); 955 gfx::Size bigSize(1000, 1000);
956 m_hostImpl->setViewportSize(bigSize, bigSize); 956 m_hostImpl->SetViewportSize(bigSize, bigSize);
957 957
958 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 1)); 958 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 1));
959 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa yer()); 959 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active _tree()->root_layer());
960 960
961 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->activeTree(), 2)); 961 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2));
962 DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->chi ldren()[0]); 962 DidDrawCheckLayer* occludedLayer = static_cast<DidDrawCheckLayer*>(root->chi ldren()[0]);
963 963
964 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->activeTree(), 3)); 964 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 3));
965 DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children ()[1]); 965 DidDrawCheckLayer* topLayer = static_cast<DidDrawCheckLayer*>(root->children ()[1]);
966 // This layer covers the occludedLayer above. Make this layer large so it ca n occlude. 966 // This layer covers the occludedLayer above. Make this layer large so it ca n occlude.
967 topLayer->SetBounds(bigSize); 967 topLayer->SetBounds(bigSize);
968 topLayer->SetContentBounds(bigSize); 968 topLayer->SetContentBounds(bigSize);
969 topLayer->SetContentsOpaque(true); 969 topLayer->SetContentsOpaque(true);
970 970
971 LayerTreeHostImpl::FrameData frame; 971 LayerTreeHostImpl::FrameData frame;
972 972
973 EXPECT_FALSE(occludedLayer->willDrawCalled()); 973 EXPECT_FALSE(occludedLayer->willDrawCalled());
974 EXPECT_FALSE(occludedLayer->didDrawCalled()); 974 EXPECT_FALSE(occludedLayer->didDrawCalled());
975 EXPECT_FALSE(topLayer->willDrawCalled()); 975 EXPECT_FALSE(topLayer->willDrawCalled());
976 EXPECT_FALSE(topLayer->didDrawCalled()); 976 EXPECT_FALSE(topLayer->didDrawCalled());
977 977
978 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 978 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
979 m_hostImpl->drawLayers(frame); 979 m_hostImpl->DrawLayers(&frame);
980 m_hostImpl->didDrawAllLayers(frame); 980 m_hostImpl->DidDrawAllLayers(frame);
981 981
982 EXPECT_FALSE(occludedLayer->willDrawCalled()); 982 EXPECT_FALSE(occludedLayer->willDrawCalled());
983 EXPECT_FALSE(occludedLayer->didDrawCalled()); 983 EXPECT_FALSE(occludedLayer->didDrawCalled());
984 EXPECT_TRUE(topLayer->willDrawCalled()); 984 EXPECT_TRUE(topLayer->willDrawCalled());
985 EXPECT_TRUE(topLayer->didDrawCalled()); 985 EXPECT_TRUE(topLayer->didDrawCalled());
986 } 986 }
987 987
988 TEST_F(LayerTreeHostImplTest, didDrawCalledOnAllLayers) 988 TEST_F(LayerTreeHostImplTest, didDrawCalledOnAllLayers)
989 { 989 {
990 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 1)); 990 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 1));
991 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa yer()); 991 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active _tree()->root_layer());
992 992
993 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->activeTree(), 2)); 993 root->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 2));
994 DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children() [0]); 994 DidDrawCheckLayer* layer1 = static_cast<DidDrawCheckLayer*>(root->children() [0]);
995 995
996 layer1->AddChild(DidDrawCheckLayer::Create(m_hostImpl->activeTree(), 3)); 996 layer1->AddChild(DidDrawCheckLayer::Create(m_hostImpl->active_tree(), 3));
997 DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children ()[0]); 997 DidDrawCheckLayer* layer2 = static_cast<DidDrawCheckLayer*>(layer1->children ()[0]);
998 998
999 layer1->SetOpacity(0.3f); 999 layer1->SetOpacity(0.3f);
1000 layer1->SetPreserves3d(false); 1000 layer1->SetPreserves3d(false);
1001 1001
1002 EXPECT_FALSE(root->didDrawCalled()); 1002 EXPECT_FALSE(root->didDrawCalled());
1003 EXPECT_FALSE(layer1->didDrawCalled()); 1003 EXPECT_FALSE(layer1->didDrawCalled());
1004 EXPECT_FALSE(layer2->didDrawCalled()); 1004 EXPECT_FALSE(layer2->didDrawCalled());
1005 1005
1006 LayerTreeHostImpl::FrameData frame; 1006 LayerTreeHostImpl::FrameData frame;
1007 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1007 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1008 m_hostImpl->drawLayers(frame); 1008 m_hostImpl->DrawLayers(&frame);
1009 m_hostImpl->didDrawAllLayers(frame); 1009 m_hostImpl->DidDrawAllLayers(frame);
1010 1010
1011 EXPECT_TRUE(root->didDrawCalled()); 1011 EXPECT_TRUE(root->didDrawCalled());
1012 EXPECT_TRUE(layer1->didDrawCalled()); 1012 EXPECT_TRUE(layer1->didDrawCalled());
1013 EXPECT_TRUE(layer2->didDrawCalled()); 1013 EXPECT_TRUE(layer2->didDrawCalled());
1014 1014
1015 EXPECT_NE(root->render_surface(), layer1->render_surface()); 1015 EXPECT_NE(root->render_surface(), layer1->render_surface());
1016 EXPECT_TRUE(!!layer1->render_surface()); 1016 EXPECT_TRUE(!!layer1->render_surface());
1017 } 1017 }
1018 1018
1019 class MissingTextureAnimatingLayer : public DidDrawCheckLayer { 1019 class MissingTextureAnimatingLayer : public DidDrawCheckLayer {
(...skipping 17 matching lines...) Expand all
1037 pushTileProperties(0, 0, resource, gfx::Rect(), false); 1037 pushTileProperties(0, 0, resource, gfx::Rect(), false);
1038 } 1038 }
1039 if (animating) 1039 if (animating)
1040 addAnimatedTransformToLayer(*this, 10, 3, 0); 1040 addAnimatedTransformToLayer(*this, 10, 3, 0);
1041 } 1041 }
1042 }; 1042 };
1043 1043
1044 TEST_F(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard) 1044 TEST_F(LayerTreeHostImplTest, prepareToDrawFailsWhenAnimationUsesCheckerboard)
1045 { 1045 {
1046 // When the texture is not missing, we draw as usual. 1046 // When the texture is not missing, we draw as usual.
1047 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 1)); 1047 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 1));
1048 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLa yer()); 1048 DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active _tree()->root_layer());
1049 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->activeTree() , 2, false, false, true, m_hostImpl->resourceProvider())); 1049 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree( ), 2, false, false, true, m_hostImpl->resource_provider()));
1050 1050
1051 LayerTreeHostImpl::FrameData frame; 1051 LayerTreeHostImpl::FrameData frame;
1052 1052
1053 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1053 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1054 m_hostImpl->drawLayers(frame); 1054 m_hostImpl->DrawLayers(&frame);
1055 m_hostImpl->didDrawAllLayers(frame); 1055 m_hostImpl->DidDrawAllLayers(frame);
1056 1056
1057 // When a texture is missing and we're not animating, we draw as usual with checkerboarding. 1057 // When a texture is missing and we're not animating, we draw as usual with checkerboarding.
1058 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 3)); 1058 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 3));
1059 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); 1059 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer ());
1060 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->activeTree() , 4, true, false, false, m_hostImpl->resourceProvider())); 1060 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree( ), 4, true, false, false, m_hostImpl->resource_provider()));
1061 1061
1062 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1062 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1063 m_hostImpl->drawLayers(frame); 1063 m_hostImpl->DrawLayers(&frame);
1064 m_hostImpl->didDrawAllLayers(frame); 1064 m_hostImpl->DidDrawAllLayers(frame);
1065 1065
1066 // When a texture is missing and we're animating, we don't want to draw anyt hing. 1066 // When a texture is missing and we're animating, we don't want to draw anyt hing.
1067 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 5)); 1067 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 5));
1068 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); 1068 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer ());
1069 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->activeTree() , 6, true, false, true, m_hostImpl->resourceProvider())); 1069 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree( ), 6, true, false, true, m_hostImpl->resource_provider()));
1070 1070
1071 EXPECT_FALSE(m_hostImpl->prepareToDraw(frame)); 1071 EXPECT_FALSE(m_hostImpl->PrepareToDraw(&frame));
1072 m_hostImpl->drawLayers(frame); 1072 m_hostImpl->DrawLayers(&frame);
1073 m_hostImpl->didDrawAllLayers(frame); 1073 m_hostImpl->DidDrawAllLayers(frame);
1074 1074
1075 // When the layer skips draw and we're animating, we still draw the frame. 1075 // When the layer skips draw and we're animating, we still draw the frame.
1076 m_hostImpl->activeTree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl- >activeTree(), 7)); 1076 m_hostImpl->active_tree()->SetRootLayer(DidDrawCheckLayer::Create(m_hostImpl ->active_tree(), 7));
1077 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->rootLayer()); 1077 root = static_cast<DidDrawCheckLayer*>(m_hostImpl->active_tree()->root_layer ());
1078 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->activeTree() , 8, false, true, true, m_hostImpl->resourceProvider())); 1078 root->AddChild(MissingTextureAnimatingLayer::Create(m_hostImpl->active_tree( ), 8, false, true, true, m_hostImpl->resource_provider()));
1079 1079
1080 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1080 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1081 m_hostImpl->drawLayers(frame); 1081 m_hostImpl->DrawLayers(&frame);
1082 m_hostImpl->didDrawAllLayers(frame); 1082 m_hostImpl->DidDrawAllLayers(frame);
1083 } 1083 }
1084 1084
1085 TEST_F(LayerTreeHostImplTest, scrollRootIgnored) 1085 TEST_F(LayerTreeHostImplTest, scrollRootIgnored)
1086 { 1086 {
1087 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1087 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1088 root->SetScrollable(false); 1088 root->SetScrollable(false);
1089 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1089 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1090 initializeRendererAndDrawFrame(); 1090 initializeRendererAndDrawFrame();
1091 1091
1092 // Scroll event is ignored because layer is not scrollable. 1092 // Scroll event is ignored because layer is not scrollable.
1093 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored); 1093 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored);
1094 EXPECT_FALSE(m_didRequestRedraw); 1094 EXPECT_FALSE(m_didRequestRedraw);
1095 EXPECT_FALSE(m_didRequestCommit); 1095 EXPECT_FALSE(m_didRequestCommit);
1096 } 1096 }
1097 1097
1098 TEST_F(LayerTreeHostImplTest, scrollNonScrollableRootWithTopControls) 1098 TEST_F(LayerTreeHostImplTest, scrollNonScrollableRootWithTopControls)
1099 { 1099 {
1100 LayerTreeSettings settings; 1100 LayerTreeSettings settings;
1101 settings.calculateTopControlsPosition = true; 1101 settings.calculateTopControlsPosition = true;
1102 settings.topControlsHeight = 50; 1102 settings.topControlsHeight = 50;
1103 1103
1104 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); 1104 m_hostImpl = LayerTreeHostImpl::Create(settings, this, &m_proxy);
1105 m_hostImpl->initializeRenderer(createOutputSurface()); 1105 m_hostImpl->InitializeRenderer(createOutputSurface());
1106 m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 1106 m_hostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
1107 1107
1108 gfx::Size layerSize(5, 5); 1108 gfx::Size layerSize(5, 5);
1109 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1109 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1110 root->SetScrollable(true); 1110 root->SetScrollable(true);
1111 root->SetMaxScrollOffset(gfx::Vector2d(layerSize.width(), layerSize.height() )); 1111 root->SetMaxScrollOffset(gfx::Vector2d(layerSize.width(), layerSize.height() ));
1112 root->SetBounds(layerSize); 1112 root->SetBounds(layerSize);
1113 root->SetContentBounds(layerSize); 1113 root->SetContentBounds(layerSize);
1114 root->SetPosition(gfx::PointF(0, 0)); 1114 root->SetPosition(gfx::PointF(0, 0));
1115 root->SetAnchorPoint(gfx::PointF(0, 0)); 1115 root->SetAnchorPoint(gfx::PointF(0, 0));
1116 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1116 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1117 m_hostImpl->activeTree()->FindRootScrollLayer(); 1117 m_hostImpl->active_tree()->FindRootScrollLayer();
1118 initializeRendererAndDrawFrame(); 1118 initializeRendererAndDrawFrame();
1119 1119
1120 EXPECT_EQ(InputHandlerClient::ScrollIgnored, m_hostImpl->scrollBegin(gfx::Po int(0, 0), InputHandlerClient::Gesture)); 1120 EXPECT_EQ(InputHandlerClient::ScrollIgnored, m_hostImpl->ScrollBegin(gfx::Po int(0, 0), InputHandlerClient::Gesture));
1121 1121
1122 m_hostImpl->topControlsManager()->ScrollBegin(); 1122 m_hostImpl->top_controls_manager()->ScrollBegin();
1123 m_hostImpl->topControlsManager()->ScrollBy(gfx::Vector2dF(0, 50)); 1123 m_hostImpl->top_controls_manager()->ScrollBy(gfx::Vector2dF(0, 50));
1124 m_hostImpl->topControlsManager()->ScrollEnd(); 1124 m_hostImpl->top_controls_manager()->ScrollEnd();
1125 EXPECT_EQ(m_hostImpl->topControlsManager()->content_top_offset(), 0.f); 1125 EXPECT_EQ(m_hostImpl->top_controls_manager()->content_top_offset(), 0.f);
1126 1126
1127 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx::Po int(0, 0), InputHandlerClient::Gesture)); 1127 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->ScrollBegin(gfx::Po int(0, 0), InputHandlerClient::Gesture));
1128 } 1128 }
1129 1129
1130 TEST_F(LayerTreeHostImplTest, scrollNonCompositedRoot) 1130 TEST_F(LayerTreeHostImplTest, scrollNonCompositedRoot)
1131 { 1131 {
1132 // Test the configuration where a non-composited root layer is embedded in a 1132 // Test the configuration where a non-composited root layer is embedded in a
1133 // scrollable outer layer. 1133 // scrollable outer layer.
1134 gfx::Size surfaceSize(10, 10); 1134 gfx::Size surfaceSize(10, 10);
1135 1135
1136 scoped_ptr<LayerImpl> contentLayer = LayerImpl::Create(m_hostImpl->activeTre e(), 1); 1136 scoped_ptr<LayerImpl> contentLayer = LayerImpl::Create(m_hostImpl->active_tr ee(), 1);
1137 contentLayer->SetDrawsContent(true); 1137 contentLayer->SetDrawsContent(true);
1138 contentLayer->SetPosition(gfx::PointF(0, 0)); 1138 contentLayer->SetPosition(gfx::PointF(0, 0));
1139 contentLayer->SetAnchorPoint(gfx::PointF(0, 0)); 1139 contentLayer->SetAnchorPoint(gfx::PointF(0, 0));
1140 contentLayer->SetBounds(surfaceSize); 1140 contentLayer->SetBounds(surfaceSize);
1141 contentLayer->SetContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSiz e.height() * 2)); 1141 contentLayer->SetContentBounds(gfx::Size(surfaceSize.width() * 2, surfaceSiz e.height() * 2));
1142 contentLayer->SetContentsScale(2, 2); 1142 contentLayer->SetContentsScale(2, 2);
1143 1143
1144 scoped_ptr<LayerImpl> scrollLayer = LayerImpl::Create(m_hostImpl->activeTree (), 2); 1144 scoped_ptr<LayerImpl> scrollLayer = LayerImpl::Create(m_hostImpl->active_tre e(), 2);
1145 scrollLayer->SetScrollable(true); 1145 scrollLayer->SetScrollable(true);
1146 scrollLayer->SetMaxScrollOffset(gfx::Vector2d(surfaceSize.width(), surfaceSi ze.height())); 1146 scrollLayer->SetMaxScrollOffset(gfx::Vector2d(surfaceSize.width(), surfaceSi ze.height()));
1147 scrollLayer->SetBounds(surfaceSize); 1147 scrollLayer->SetBounds(surfaceSize);
1148 scrollLayer->SetContentBounds(surfaceSize); 1148 scrollLayer->SetContentBounds(surfaceSize);
1149 scrollLayer->SetPosition(gfx::PointF(0, 0)); 1149 scrollLayer->SetPosition(gfx::PointF(0, 0));
1150 scrollLayer->SetAnchorPoint(gfx::PointF(0, 0)); 1150 scrollLayer->SetAnchorPoint(gfx::PointF(0, 0));
1151 scrollLayer->AddChild(contentLayer.Pass()); 1151 scrollLayer->AddChild(contentLayer.Pass());
1152 1152
1153 m_hostImpl->activeTree()->SetRootLayer(scrollLayer.Pass()); 1153 m_hostImpl->active_tree()->SetRootLayer(scrollLayer.Pass());
1154 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1154 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1155 initializeRendererAndDrawFrame(); 1155 initializeRendererAndDrawFrame();
1156 1156
1157 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1157 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1158 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 1158 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
1159 m_hostImpl->scrollEnd(); 1159 m_hostImpl->ScrollEnd();
1160 EXPECT_TRUE(m_didRequestRedraw); 1160 EXPECT_TRUE(m_didRequestRedraw);
1161 EXPECT_TRUE(m_didRequestCommit); 1161 EXPECT_TRUE(m_didRequestCommit);
1162 } 1162 }
1163 1163
1164 TEST_F(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw) 1164 TEST_F(LayerTreeHostImplTest, scrollChildCallsCommitAndRedraw)
1165 { 1165 {
1166 gfx::Size surfaceSize(10, 10); 1166 gfx::Size surfaceSize(10, 10);
1167 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1167 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1168 root->SetBounds(surfaceSize); 1168 root->SetBounds(surfaceSize);
1169 root->SetContentBounds(surfaceSize); 1169 root->SetContentBounds(surfaceSize);
1170 root->AddChild(createScrollableLayer(2, surfaceSize)); 1170 root->AddChild(createScrollableLayer(2, surfaceSize));
1171 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1171 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1172 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1172 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1173 initializeRendererAndDrawFrame(); 1173 initializeRendererAndDrawFrame();
1174 1174
1175 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1175 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1176 m_hostImpl->scrollBy(gfx::Point(), gfx::Vector2d(0, 10)); 1176 m_hostImpl->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10));
1177 m_hostImpl->scrollEnd(); 1177 m_hostImpl->ScrollEnd();
1178 EXPECT_TRUE(m_didRequestRedraw); 1178 EXPECT_TRUE(m_didRequestRedraw);
1179 EXPECT_TRUE(m_didRequestCommit); 1179 EXPECT_TRUE(m_didRequestCommit);
1180 } 1180 }
1181 1181
1182 TEST_F(LayerTreeHostImplTest, scrollMissesChild) 1182 TEST_F(LayerTreeHostImplTest, scrollMissesChild)
1183 { 1183 {
1184 gfx::Size surfaceSize(10, 10); 1184 gfx::Size surfaceSize(10, 10);
1185 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1185 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1186 root->AddChild(createScrollableLayer(2, surfaceSize)); 1186 root->AddChild(createScrollableLayer(2, surfaceSize));
1187 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1187 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1188 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1188 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1189 initializeRendererAndDrawFrame(); 1189 initializeRendererAndDrawFrame();
1190 1190
1191 // Scroll event is ignored because the input coordinate is outside the layer boundaries. 1191 // Scroll event is ignored because the input coordinate is outside the layer boundaries.
1192 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(15, 5), InputHandlerClient::Whe el), InputHandlerClient::ScrollIgnored); 1192 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(15, 5), InputHandlerClient::Whe el), InputHandlerClient::ScrollIgnored);
1193 EXPECT_FALSE(m_didRequestRedraw); 1193 EXPECT_FALSE(m_didRequestRedraw);
1194 EXPECT_FALSE(m_didRequestCommit); 1194 EXPECT_FALSE(m_didRequestCommit);
1195 } 1195 }
1196 1196
1197 TEST_F(LayerTreeHostImplTest, scrollMissesBackfacingChild) 1197 TEST_F(LayerTreeHostImplTest, scrollMissesBackfacingChild)
1198 { 1198 {
1199 gfx::Size surfaceSize(10, 10); 1199 gfx::Size surfaceSize(10, 10);
1200 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1200 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1201 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); 1201 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize);
1202 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1202 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1203 1203
1204 gfx::Transform matrix; 1204 gfx::Transform matrix;
1205 matrix.RotateAboutXAxis(180); 1205 matrix.RotateAboutXAxis(180);
1206 child->SetTransform(matrix); 1206 child->SetTransform(matrix);
1207 child->SetDoubleSided(false); 1207 child->SetDoubleSided(false);
1208 1208
1209 root->AddChild(child.Pass()); 1209 root->AddChild(child.Pass());
1210 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1210 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1211 initializeRendererAndDrawFrame(); 1211 initializeRendererAndDrawFrame();
1212 1212
1213 // Scroll event is ignored because the scrollable layer is not facing the vi ewer and there is 1213 // Scroll event is ignored because the scrollable layer is not facing the vi ewer and there is
1214 // nothing scrollable behind it. 1214 // nothing scrollable behind it.
1215 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored); 1215 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollIgnored);
1216 EXPECT_FALSE(m_didRequestRedraw); 1216 EXPECT_FALSE(m_didRequestRedraw);
1217 EXPECT_FALSE(m_didRequestCommit); 1217 EXPECT_FALSE(m_didRequestCommit);
1218 } 1218 }
1219 1219
1220 TEST_F(LayerTreeHostImplTest, scrollBlockedByContentLayer) 1220 TEST_F(LayerTreeHostImplTest, scrollBlockedByContentLayer)
1221 { 1221 {
1222 gfx::Size surfaceSize(10, 10); 1222 gfx::Size surfaceSize(10, 10);
1223 scoped_ptr<LayerImpl> contentLayer = createScrollableLayer(1, surfaceSize); 1223 scoped_ptr<LayerImpl> contentLayer = createScrollableLayer(1, surfaceSize);
1224 contentLayer->SetShouldScrollOnMainThread(true); 1224 contentLayer->SetShouldScrollOnMainThread(true);
1225 contentLayer->SetScrollable(false); 1225 contentLayer->SetScrollable(false);
1226 1226
1227 scoped_ptr<LayerImpl> scrollLayer = createScrollableLayer(2, surfaceSize); 1227 scoped_ptr<LayerImpl> scrollLayer = createScrollableLayer(2, surfaceSize);
1228 scrollLayer->AddChild(contentLayer.Pass()); 1228 scrollLayer->AddChild(contentLayer.Pass());
1229 1229
1230 m_hostImpl->activeTree()->SetRootLayer(scrollLayer.Pass()); 1230 m_hostImpl->active_tree()->SetRootLayer(scrollLayer.Pass());
1231 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1231 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1232 initializeRendererAndDrawFrame(); 1232 initializeRendererAndDrawFrame();
1233 1233
1234 // Scrolling fails because the content layer is asking to be scrolled on the main thread. 1234 // Scrolling fails because the content layer is asking to be scrolled on the main thread.
1235 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread); 1235 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollOnMainThread);
1236 } 1236 }
1237 1237
1238 TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread) 1238 TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnMainThread)
1239 { 1239 {
1240 gfx::Size surfaceSize(10, 10); 1240 gfx::Size surfaceSize(10, 10);
1241 float pageScale = 2; 1241 float pageScale = 2;
1242 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); 1242 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize);
1243 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1243 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1244 m_hostImpl->activeTree()->DidBecomeActive(); 1244 m_hostImpl->active_tree()->DidBecomeActive();
1245 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1245 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1246 initializeRendererAndDrawFrame(); 1246 initializeRendererAndDrawFrame();
1247 1247
1248 gfx::Vector2d scrollDelta(0, 10); 1248 gfx::Vector2d scrollDelta(0, 10);
1249 gfx::Vector2d expectedScrollDelta(scrollDelta); 1249 gfx::Vector2d expectedScrollDelta(scrollDelta);
1250 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->max_scroll_offset() ); 1250 gfx::Vector2d expectedMaxScroll(m_hostImpl->active_tree()->root_layer()->max _scroll_offset());
1251 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1251 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1252 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1252 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1253 m_hostImpl->scrollEnd(); 1253 m_hostImpl->ScrollEnd();
1254 1254
1255 // Set new page scale from main thread. 1255 // Set new page scale from main thread.
1256 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(pageScale, pageScale, pageScale); 1256 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(pageScale, pageScale, pageScale);
1257 1257
1258 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 1258 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
1259 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr ollDelta); 1259 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), expectedScrollDelta);
1260 1260
1261 // The scroll range should also have been updated. 1261 // The scroll range should also have been updated.
1262 EXPECT_EQ(m_hostImpl->rootLayer()->max_scroll_offset(), expectedMaxScroll); 1262 EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->max_scroll_offset(), expe ctedMaxScroll);
1263 1263
1264 // The page scale delta remains constant because the impl thread did not sca le. 1264 // The page scale delta remains constant because the impl thread did not sca le.
1265 // TODO: If possible, use gfx::Transform() or Skia equality functions. At 1265 // TODO: If possible, use gfx::Transform() or Skia equality functions. At
1266 // the moment we avoid that because skia does exact bit-wise equality 1266 // the moment we avoid that because skia does exact bit-wise equality
1267 // checking that does not consider -0 == +0. 1267 // checking that does not consider -0 == +0.
1268 // http://code.google.com/p/chromium/issues/detail?id=162747 1268 // http://code.google.com/p/chromium/issues/detail?id=162747
1269 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 0, 0)); 1269 EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(0, 0));
1270 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 0, 1)); 1270 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(0, 1));
1271 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 0, 2)); 1271 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(0, 2));
1272 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 0, 3)); 1272 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(0, 3));
1273 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 1, 0)); 1273 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(1, 0));
1274 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 1, 1)); 1274 EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(1, 1));
1275 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 1, 2)); 1275 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(1, 2));
1276 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 1, 3)); 1276 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(1, 3));
1277 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 2, 0)); 1277 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(2, 0));
1278 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 2, 1)); 1278 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(2, 1));
1279 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 2, 2)); 1279 EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(2, 2));
1280 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 2, 3)); 1280 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(2, 3));
1281 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 3, 0)); 1281 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(3, 0));
1282 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 3, 1)); 1282 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(3, 1));
1283 EXPECT_EQ(0.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 3, 2)); 1283 EXPECT_EQ(0.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(3, 2));
1284 EXPECT_EQ(1.0, m_hostImpl->rootLayer()->impl_transform().matrix().getDouble( 3, 3)); 1284 EXPECT_EQ(1.0, m_hostImpl->active_tree()->root_layer()->impl_transform().mat rix().getDouble(3, 3));
1285 } 1285 }
1286 1286
1287 TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread) 1287 TEST_F(LayerTreeHostImplTest, scrollRootAndChangePageScaleOnImplThread)
1288 { 1288 {
1289 gfx::Size surfaceSize(10, 10); 1289 gfx::Size surfaceSize(10, 10);
1290 float pageScale = 2; 1290 float pageScale = 2;
1291 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); 1291 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize);
1292 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1292 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1293 m_hostImpl->activeTree()->DidBecomeActive(); 1293 m_hostImpl->active_tree()->DidBecomeActive();
1294 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1294 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1295 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(1, 1, pageScale); 1295 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(1, 1, pageScale);
1296 initializeRendererAndDrawFrame(); 1296 initializeRendererAndDrawFrame();
1297 1297
1298 gfx::Vector2d scrollDelta(0, 10); 1298 gfx::Vector2d scrollDelta(0, 10);
1299 gfx::Vector2d expectedScrollDelta(scrollDelta); 1299 gfx::Vector2d expectedScrollDelta(scrollDelta);
1300 gfx::Vector2d expectedMaxScroll(m_hostImpl->rootLayer()->max_scroll_offset() ); 1300 gfx::Vector2d expectedMaxScroll(m_hostImpl->active_tree()->root_layer()->max _scroll_offset());
1301 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1301 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1302 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1302 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1303 m_hostImpl->scrollEnd(); 1303 m_hostImpl->ScrollEnd();
1304 1304
1305 // Set new page scale on impl thread by pinching. 1305 // Set new page scale on impl thread by pinching.
1306 m_hostImpl->pinchGestureBegin(); 1306 m_hostImpl->PinchGestureBegin();
1307 m_hostImpl->pinchGestureUpdate(pageScale, gfx::Point()); 1307 m_hostImpl->PinchGestureUpdate(pageScale, gfx::Point());
1308 m_hostImpl->pinchGestureEnd(); 1308 m_hostImpl->PinchGestureEnd();
1309 drawOneFrame(); 1309 drawOneFrame();
1310 1310
1311 // The scroll delta is not scaled because the main thread did not scale. 1311 // The scroll delta is not scaled because the main thread did not scale.
1312 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 1312 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
1313 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expectedScr ollDelta); 1313 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), expectedScrollDelta);
1314 1314
1315 // The scroll range should also have been updated. 1315 // The scroll range should also have been updated.
1316 EXPECT_EQ(m_hostImpl->rootLayer()->max_scroll_offset(), expectedMaxScroll); 1316 EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->max_scroll_offset(), expe ctedMaxScroll);
1317 1317
1318 // The page scale delta should match the new scale on the impl side. 1318 // The page scale delta should match the new scale on the impl side.
1319 gfx::Transform expectedScale; 1319 gfx::Transform expectedScale;
1320 expectedScale.Scale(pageScale, pageScale); 1320 expectedScale.Scale(pageScale, pageScale);
1321 EXPECT_EQ(m_hostImpl->rootLayer()->impl_transform(), expectedScale); 1321 EXPECT_EQ(m_hostImpl->active_tree()->root_layer()->impl_transform(), expecte dScale);
1322 } 1322 }
1323 1323
1324 TEST_F(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly) 1324 TEST_F(LayerTreeHostImplTest, pageScaleDeltaAppliedToRootScrollLayerOnly)
1325 { 1325 {
1326 gfx::Size surfaceSize(10, 10); 1326 gfx::Size surfaceSize(10, 10);
1327 float defaultPageScale = 1; 1327 float defaultPageScale = 1;
1328 gfx::Transform defaultPageScaleMatrix; 1328 gfx::Transform defaultPageScaleMatrix;
1329 1329
1330 float newPageScale = 2; 1330 float newPageScale = 2;
1331 gfx::Transform newPageScaleMatrix; 1331 gfx::Transform newPageScaleMatrix;
1332 newPageScaleMatrix.Scale(newPageScale, newPageScale); 1332 newPageScaleMatrix.Scale(newPageScale, newPageScale);
1333 1333
1334 // Create a normal scrollable root layer and another scrollable child layer. 1334 // Create a normal scrollable root layer and another scrollable child layer.
1335 setupScrollAndContentsLayers(surfaceSize); 1335 setupScrollAndContentsLayers(surfaceSize);
1336 LayerImpl* root = m_hostImpl->rootLayer(); 1336 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
1337 LayerImpl* child = root->children()[0]; 1337 LayerImpl* child = root->children()[0];
1338 1338
1339 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize ); 1339 scoped_ptr<LayerImpl> scrollableChild = createScrollableLayer(3, surfaceSize );
1340 child->AddChild(scrollableChild.Pass()); 1340 child->AddChild(scrollableChild.Pass());
1341 LayerImpl* grandChild = child->children()[0]; 1341 LayerImpl* grandChild = child->children()[0];
1342 1342
1343 // Set new page scale on impl thread by pinching. 1343 // Set new page scale on impl thread by pinching.
1344 m_hostImpl->pinchGestureBegin(); 1344 m_hostImpl->PinchGestureBegin();
1345 m_hostImpl->pinchGestureUpdate(newPageScale, gfx::Point()); 1345 m_hostImpl->PinchGestureUpdate(newPageScale, gfx::Point());
1346 m_hostImpl->pinchGestureEnd(); 1346 m_hostImpl->PinchGestureEnd();
1347 drawOneFrame(); 1347 drawOneFrame();
1348 1348
1349 // The page scale delta should only be applied to the scrollable root layer. 1349 // The page scale delta should only be applied to the scrollable root layer.
1350 EXPECT_EQ(root->impl_transform(), newPageScaleMatrix); 1350 EXPECT_EQ(root->impl_transform(), newPageScaleMatrix);
1351 EXPECT_EQ(child->impl_transform(), defaultPageScaleMatrix); 1351 EXPECT_EQ(child->impl_transform(), defaultPageScaleMatrix);
1352 EXPECT_EQ(grandChild->impl_transform(), defaultPageScaleMatrix); 1352 EXPECT_EQ(grandChild->impl_transform(), defaultPageScaleMatrix);
1353 1353
1354 // Make sure all the layers are drawn with the page scale delta applied, i.e ., the page scale 1354 // Make sure all the layers are drawn with the page scale delta applied, i.e ., the page scale
1355 // delta on the root layer is applied hierarchically. 1355 // delta on the root layer is applied hierarchically.
1356 LayerTreeHostImpl::FrameData frame; 1356 LayerTreeHostImpl::FrameData frame;
1357 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1357 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1358 m_hostImpl->drawLayers(frame); 1358 m_hostImpl->DrawLayers(&frame);
1359 m_hostImpl->didDrawAllLayers(frame); 1359 m_hostImpl->DidDrawAllLayers(frame);
1360 1360
1361 EXPECT_EQ(root->draw_transform().matrix().getDouble(0, 0), newPageScale); 1361 EXPECT_EQ(root->draw_transform().matrix().getDouble(0, 0), newPageScale);
1362 EXPECT_EQ(root->draw_transform().matrix().getDouble(1, 1), newPageScale); 1362 EXPECT_EQ(root->draw_transform().matrix().getDouble(1, 1), newPageScale);
1363 EXPECT_EQ(child->draw_transform().matrix().getDouble(0, 0), newPageScale); 1363 EXPECT_EQ(child->draw_transform().matrix().getDouble(0, 0), newPageScale);
1364 EXPECT_EQ(child->draw_transform().matrix().getDouble(1, 1), newPageScale); 1364 EXPECT_EQ(child->draw_transform().matrix().getDouble(1, 1), newPageScale);
1365 EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(0, 0), newPageScal e); 1365 EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(0, 0), newPageScal e);
1366 EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(1, 1), newPageScal e); 1366 EXPECT_EQ(grandChild->draw_transform().matrix().getDouble(1, 1), newPageScal e);
1367 } 1367 }
1368 1368
1369 TEST_F(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread) 1369 TEST_F(LayerTreeHostImplTest, scrollChildAndChangePageScaleOnMainThread)
1370 { 1370 {
1371 gfx::Size surfaceSize(10, 10); 1371 gfx::Size surfaceSize(10, 10);
1372 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1372 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree(), 1) ;
1373 root->SetBounds(surfaceSize); 1373 root->SetBounds(surfaceSize);
1374 root->SetContentBounds(surfaceSize); 1374 root->SetContentBounds(surfaceSize);
1375 // Also mark the root scrollable so it becomes the root scroll layer. 1375 // Also mark the root scrollable so it becomes the root scroll layer.
1376 root->SetScrollable(true); 1376 root->SetScrollable(true);
1377 int scrollLayerId = 2; 1377 int scrollLayerId = 2;
1378 root->AddChild(createScrollableLayer(scrollLayerId, surfaceSize)); 1378 root->AddChild(createScrollableLayer(scrollLayerId, surfaceSize));
1379 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1379 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1380 m_hostImpl->activeTree()->DidBecomeActive(); 1380 m_hostImpl->active_tree()->DidBecomeActive();
1381 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1381 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1382 initializeRendererAndDrawFrame(); 1382 initializeRendererAndDrawFrame();
1383 1383
1384 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; 1384 LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0];
1385 1385
1386 gfx::Vector2d scrollDelta(0, 10); 1386 gfx::Vector2d scrollDelta(0, 10);
1387 gfx::Vector2d expectedScrollDelta(scrollDelta); 1387 gfx::Vector2d expectedScrollDelta(scrollDelta);
1388 gfx::Vector2d expectedMaxScroll(child->max_scroll_offset()); 1388 gfx::Vector2d expectedMaxScroll(child->max_scroll_offset());
1389 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1389 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1390 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1390 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1391 m_hostImpl->scrollEnd(); 1391 m_hostImpl->ScrollEnd();
1392 1392
1393 float pageScale = 2; 1393 float pageScale = 2;
1394 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(pageScale, 1, pageScal e); 1394 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(pageScale, 1, pageSca le);
1395 1395
1396 drawOneFrame(); 1396 drawOneFrame();
1397 1397
1398 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 1398 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
1399 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta); 1399 expectContains(*scrollInfo.get(), scrollLayerId, expectedScrollDelta);
1400 1400
1401 // The scroll range should not have changed. 1401 // The scroll range should not have changed.
1402 EXPECT_EQ(child->max_scroll_offset(), expectedMaxScroll); 1402 EXPECT_EQ(child->max_scroll_offset(), expectedMaxScroll);
1403 1403
1404 // The page scale delta remains constant because the impl thread did not sca le. 1404 // The page scale delta remains constant because the impl thread did not sca le.
1405 gfx::Transform identityTransform; 1405 gfx::Transform identityTransform;
1406 EXPECT_EQ(child->impl_transform(), gfx::Transform()); 1406 EXPECT_EQ(child->impl_transform(), gfx::Transform());
1407 } 1407 }
1408 1408
1409 TEST_F(LayerTreeHostImplTest, scrollChildBeyondLimit) 1409 TEST_F(LayerTreeHostImplTest, scrollChildBeyondLimit)
1410 { 1410 {
1411 // Scroll a child layer beyond its maximum scroll range and make sure the 1411 // Scroll a child layer beyond its maximum scroll range and make sure the
1412 // parent layer is scrolled on the axis on which the child was unable to 1412 // parent layer is scrolled on the axis on which the child was unable to
1413 // scroll. 1413 // scroll.
1414 gfx::Size surfaceSize(10, 10); 1414 gfx::Size surfaceSize(10, 10);
1415 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); 1415 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize);
1416 1416
1417 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); 1417 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize);
1418 grandChild->SetScrollOffset(gfx::Vector2d(0, 5)); 1418 grandChild->SetScrollOffset(gfx::Vector2d(0, 5));
1419 1419
1420 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); 1420 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize);
1421 child->SetScrollOffset(gfx::Vector2d(3, 0)); 1421 child->SetScrollOffset(gfx::Vector2d(3, 0));
1422 child->AddChild(grandChild.Pass()); 1422 child->AddChild(grandChild.Pass());
1423 1423
1424 root->AddChild(child.Pass()); 1424 root->AddChild(child.Pass());
1425 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1425 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1426 m_hostImpl->activeTree()->DidBecomeActive(); 1426 m_hostImpl->active_tree()->DidBecomeActive();
1427 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1427 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1428 initializeRendererAndDrawFrame(); 1428 initializeRendererAndDrawFrame();
1429 { 1429 {
1430 gfx::Vector2d scrollDelta(-8, -7); 1430 gfx::Vector2d scrollDelta(-8, -7);
1431 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted); 1431 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted);
1432 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1432 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1433 m_hostImpl->scrollEnd(); 1433 m_hostImpl->ScrollEnd();
1434 1434
1435 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 1435 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
1436 1436
1437 // The grand child should have scrolled up to its limit. 1437 // The grand child should have scrolled up to its limit.
1438 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; 1438 LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0 ];
1439 LayerImpl* grandChild = child->children()[0]; 1439 LayerImpl* grandChild = child->children()[0];
1440 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5) ); 1440 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -5) );
1441 1441
1442 // The child should have only scrolled on the other axis. 1442 // The child should have only scrolled on the other axis.
1443 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0)); 1443 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(-3, 0));
1444 } 1444 }
1445 } 1445 }
1446 1446
1447 TEST_F(LayerTreeHostImplTest, scrollWithoutBubbling) 1447 TEST_F(LayerTreeHostImplTest, scrollWithoutBubbling)
1448 { 1448 {
1449 // Scroll a child layer beyond its maximum scroll range and make sure the 1449 // Scroll a child layer beyond its maximum scroll range and make sure the
1450 // the scroll doesn't bubble up to the parent layer. 1450 // the scroll doesn't bubble up to the parent layer.
1451 gfx::Size surfaceSize(10, 10); 1451 gfx::Size surfaceSize(10, 10);
1452 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize); 1452 scoped_ptr<LayerImpl> root = createScrollableLayer(1, surfaceSize);
1453 1453
1454 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize); 1454 scoped_ptr<LayerImpl> grandChild = createScrollableLayer(3, surfaceSize);
1455 grandChild->SetScrollOffset(gfx::Vector2d(0, 2)); 1455 grandChild->SetScrollOffset(gfx::Vector2d(0, 2));
1456 1456
1457 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize); 1457 scoped_ptr<LayerImpl> child = createScrollableLayer(2, surfaceSize);
1458 child->SetScrollOffset(gfx::Vector2d(0, 3)); 1458 child->SetScrollOffset(gfx::Vector2d(0, 3));
1459 child->AddChild(grandChild.Pass()); 1459 child->AddChild(grandChild.Pass());
1460 1460
1461 root->AddChild(child.Pass()); 1461 root->AddChild(child.Pass());
1462 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1462 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1463 m_hostImpl->activeTree()->DidBecomeActive(); 1463 m_hostImpl->active_tree()->DidBecomeActive();
1464 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1464 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1465 initializeRendererAndDrawFrame(); 1465 initializeRendererAndDrawFrame();
1466 { 1466 {
1467 gfx::Vector2d scrollDelta(0, -10); 1467 gfx::Vector2d scrollDelta(0, -10);
1468 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted); 1468 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted);
1469 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1469 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1470 m_hostImpl->scrollEnd(); 1470 m_hostImpl->ScrollEnd();
1471 1471
1472 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 1472 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
1473 1473
1474 // The grand child should have scrolled up to its limit. 1474 // The grand child should have scrolled up to its limit.
1475 LayerImpl* child = m_hostImpl->rootLayer()->children()[0]; 1475 LayerImpl* child = m_hostImpl->active_tree()->root_layer()->children()[0 ];
1476 LayerImpl* grandChild = child->children()[0]; 1476 LayerImpl* grandChild = child->children()[0];
1477 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2) ); 1477 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2) );
1478 1478
1479 // The child should not have scrolled. 1479 // The child should not have scrolled.
1480 expectNone(*scrollInfo.get(), child->id()); 1480 expectNone(*scrollInfo.get(), child->id());
1481 1481
1482 // The next time we scroll we should only scroll the parent. 1482 // The next time we scroll we should only scroll the parent.
1483 scrollDelta = gfx::Vector2d(0, -3); 1483 scrollDelta = gfx::Vector2d(0, -3);
1484 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted); 1484 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted);
1485 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); 1485 EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild);
1486 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1486 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1487 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), child); 1487 EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), child);
1488 m_hostImpl->scrollEnd(); 1488 m_hostImpl->ScrollEnd();
1489 1489
1490 scrollInfo = m_hostImpl->processScrollDeltas(); 1490 scrollInfo = m_hostImpl->ProcessScrollDeltas();
1491 1491
1492 // The child should have scrolled up to its limit. 1492 // The child should have scrolled up to its limit.
1493 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); 1493 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3));
1494 1494
1495 // The grand child should not have scrolled. 1495 // The grand child should not have scrolled.
1496 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2) ); 1496 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, -2) );
1497 1497
1498 // After scrolling the parent, another scroll on the opposite direction 1498 // After scrolling the parent, another scroll on the opposite direction
1499 // should still scroll the child. 1499 // should still scroll the child.
1500 scrollDelta = gfx::Vector2d(0, 7); 1500 scrollDelta = gfx::Vector2d(0, 7);
1501 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted); 1501 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: NonBubblingGesture), InputHandlerClient::ScrollStarted);
1502 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); 1502 EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild);
1503 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1503 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1504 EXPECT_EQ(m_hostImpl->currentlyScrollingLayer(), grandChild); 1504 EXPECT_EQ(m_hostImpl->CurrentlyScrollingLayer(), grandChild);
1505 m_hostImpl->scrollEnd(); 1505 m_hostImpl->ScrollEnd();
1506 1506
1507 scrollInfo = m_hostImpl->processScrollDeltas(); 1507 scrollInfo = m_hostImpl->ProcessScrollDeltas();
1508 1508
1509 // The grand child should have scrolled. 1509 // The grand child should have scrolled.
1510 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 5)) ; 1510 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 5)) ;
1511 1511
1512 // The child should not have scrolled. 1512 // The child should not have scrolled.
1513 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3)); 1513 expectContains(*scrollInfo.get(), child->id(), gfx::Vector2d(0, -3));
1514 1514
1515 1515
1516 // Scrolling should be adjusted from viewport space. 1516 // Scrolling should be adjusted from viewport space.
1517 m_hostImpl->activeTree()->SetPageScaleFactorAndLimits(2, 2, 2); 1517 m_hostImpl->active_tree()->SetPageScaleFactorAndLimits(2, 2, 2);
1518 m_hostImpl->activeTree()->SetPageScaleDelta(1); 1518 m_hostImpl->active_tree()->SetPageScaleDelta(1);
1519 gfx::Transform scaleTransform; 1519 gfx::Transform scaleTransform;
1520 scaleTransform.Scale(2, 2); 1520 scaleTransform.Scale(2, 2);
1521 m_hostImpl->activeTree()->RootLayer()->SetImplTransform(scaleTransform); 1521 m_hostImpl->active_tree()->root_layer()->SetImplTransform(scaleTransform );
1522 1522
1523 scrollDelta = gfx::Vector2d(0, -2); 1523 scrollDelta = gfx::Vector2d(0, -2);
1524 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->scrollBegin(gfx ::Point(1, 1), InputHandlerClient::NonBubblingGesture)); 1524 EXPECT_EQ(InputHandlerClient::ScrollStarted, m_hostImpl->ScrollBegin(gfx ::Point(1, 1), InputHandlerClient::NonBubblingGesture));
1525 EXPECT_EQ(grandChild, m_hostImpl->currentlyScrollingLayer()); 1525 EXPECT_EQ(grandChild, m_hostImpl->CurrentlyScrollingLayer());
1526 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1526 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1527 m_hostImpl->scrollEnd(); 1527 m_hostImpl->ScrollEnd();
1528 1528
1529 scrollInfo = m_hostImpl->processScrollDeltas(); 1529 scrollInfo = m_hostImpl->ProcessScrollDeltas();
1530 1530
1531 // Should have scrolled by half the amount in layer space (5 - 2/2) 1531 // Should have scrolled by half the amount in layer space (5 - 2/2)
1532 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 4)) ; 1532 expectContains(*scrollInfo.get(), grandChild->id(), gfx::Vector2d(0, 4)) ;
1533 } 1533 }
1534 } 1534 }
1535 1535
1536 TEST_F(LayerTreeHostImplTest, scrollEventBubbling) 1536 TEST_F(LayerTreeHostImplTest, scrollEventBubbling)
1537 { 1537 {
1538 // When we try to scroll a non-scrollable child layer, the scroll delta 1538 // When we try to scroll a non-scrollable child layer, the scroll delta
1539 // should be applied to one of its ancestors if possible. 1539 // should be applied to one of its ancestors if possible.
1540 gfx::Size surfaceSize(10, 10); 1540 gfx::Size surfaceSize(10, 10);
1541 gfx::Size contentSize(20, 20); 1541 gfx::Size contentSize(20, 20);
1542 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize); 1542 scoped_ptr<LayerImpl> root = createScrollableLayer(1, contentSize);
1543 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize); 1543 scoped_ptr<LayerImpl> child = createScrollableLayer(2, contentSize);
1544 1544
1545 child->SetScrollable(false); 1545 child->SetScrollable(false);
1546 root->AddChild(child.Pass()); 1546 root->AddChild(child.Pass());
1547 1547
1548 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1548 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1549 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1549 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1550 m_hostImpl->activeTree()->DidBecomeActive(); 1550 m_hostImpl->active_tree()->DidBecomeActive();
1551 initializeRendererAndDrawFrame(); 1551 initializeRendererAndDrawFrame();
1552 { 1552 {
1553 gfx::Vector2d scrollDelta(0, 4); 1553 gfx::Vector2d scrollDelta(0, 4);
1554 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted); 1554 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient:: Wheel), InputHandlerClient::ScrollStarted);
1555 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1555 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1556 m_hostImpl->scrollEnd(); 1556 m_hostImpl->ScrollEnd();
1557 1557
1558 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 1558 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
1559 1559
1560 // Only the root should have scrolled. 1560 // Only the root should have scrolled.
1561 ASSERT_EQ(scrollInfo->scrolls.size(), 1u); 1561 ASSERT_EQ(scrollInfo->scrolls.size(), 1u);
1562 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), scrollD elta); 1562 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer( )->id(), scrollDelta);
1563 } 1563 }
1564 } 1564 }
1565 1565
1566 TEST_F(LayerTreeHostImplTest, scrollBeforeRedraw) 1566 TEST_F(LayerTreeHostImplTest, scrollBeforeRedraw)
1567 { 1567 {
1568 gfx::Size surfaceSize(10, 10); 1568 gfx::Size surfaceSize(10, 10);
1569 m_hostImpl->activeTree()->SetRootLayer(createScrollableLayer(1, surfaceSize) ); 1569 m_hostImpl->active_tree()->SetRootLayer(createScrollableLayer(1, surfaceSize ));
1570 m_hostImpl->activeTree()->DidBecomeActive(); 1570 m_hostImpl->active_tree()->DidBecomeActive();
1571 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1571 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1572 1572
1573 // Draw one frame and then immediately rebuild the layer tree to mimic a tre e synchronization. 1573 // Draw one frame and then immediately rebuild the layer tree to mimic a tre e synchronization.
1574 initializeRendererAndDrawFrame(); 1574 initializeRendererAndDrawFrame();
1575 m_hostImpl->activeTree()->DetachLayerTree(); 1575 m_hostImpl->active_tree()->DetachLayerTree();
1576 m_hostImpl->activeTree()->SetRootLayer(createScrollableLayer(2, surfaceSize) ); 1576 m_hostImpl->active_tree()->SetRootLayer(createScrollableLayer(2, surfaceSize ));
1577 m_hostImpl->activeTree()->DidBecomeActive(); 1577 m_hostImpl->active_tree()->DidBecomeActive();
1578 1578
1579 // Scrolling should still work even though we did not draw yet. 1579 // Scrolling should still work even though we did not draw yet.
1580 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1580 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(5, 5), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1581 } 1581 }
1582 1582
1583 TEST_F(LayerTreeHostImplTest, scrollAxisAlignedRotatedLayer) 1583 TEST_F(LayerTreeHostImplTest, scrollAxisAlignedRotatedLayer)
1584 { 1584 {
1585 setupScrollAndContentsLayers(gfx::Size(100, 100)); 1585 setupScrollAndContentsLayers(gfx::Size(100, 100));
1586 1586
1587 // Rotate the root layer 90 degrees counter-clockwise about its center. 1587 // Rotate the root layer 90 degrees counter-clockwise about its center.
1588 gfx::Transform rotateTransform; 1588 gfx::Transform rotateTransform;
1589 rotateTransform.Rotate(-90); 1589 rotateTransform.Rotate(-90);
1590 m_hostImpl->rootLayer()->SetTransform(rotateTransform); 1590 m_hostImpl->active_tree()->root_layer()->SetTransform(rotateTransform);
1591 1591
1592 gfx::Size surfaceSize(50, 50); 1592 gfx::Size surfaceSize(50, 50);
1593 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1593 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1594 initializeRendererAndDrawFrame(); 1594 initializeRendererAndDrawFrame();
1595 1595
1596 // Scroll to the right in screen coordinates with a gesture. 1596 // Scroll to the right in screen coordinates with a gesture.
1597 gfx::Vector2d gestureScrollDelta(10, 0); 1597 gfx::Vector2d gestureScrollDelta(10, 0);
1598 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted); 1598 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted);
1599 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); 1599 m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta);
1600 m_hostImpl->scrollEnd(); 1600 m_hostImpl->ScrollEnd();
1601 1601
1602 // The layer should have scrolled down in its local coordinates. 1602 // The layer should have scrolled down in its local coordinates.
1603 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 1603 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
1604 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), gfx::Vector 2d(0, gestureScrollDelta.x())); 1604 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), gfx::Vector2d(0, gestureScrollDelta.x()));
1605 1605
1606 // Reset and scroll down with the wheel. 1606 // Reset and scroll down with the wheel.
1607 m_hostImpl->rootLayer()->SetScrollDelta(gfx::Vector2dF()); 1607 m_hostImpl->active_tree()->root_layer()->SetScrollDelta(gfx::Vector2dF());
1608 gfx::Vector2d wheelScrollDelta(0, 10); 1608 gfx::Vector2d wheelScrollDelta(0, 10);
1609 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1609 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1610 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); 1610 m_hostImpl->ScrollBy(gfx::Point(), wheelScrollDelta);
1611 m_hostImpl->scrollEnd(); 1611 m_hostImpl->ScrollEnd();
1612 1612
1613 // The layer should have scrolled down in its local coordinates. 1613 // The layer should have scrolled down in its local coordinates.
1614 scrollInfo = m_hostImpl->processScrollDeltas(); 1614 scrollInfo = m_hostImpl->ProcessScrollDeltas();
1615 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll Delta); 1615 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), wheelScrollDelta);
1616 } 1616 }
1617 1617
1618 TEST_F(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer) 1618 TEST_F(LayerTreeHostImplTest, scrollNonAxisAlignedRotatedLayer)
1619 { 1619 {
1620 setupScrollAndContentsLayers(gfx::Size(100, 100)); 1620 setupScrollAndContentsLayers(gfx::Size(100, 100));
1621 int childLayerId = 3; 1621 int childLayerId = 3;
1622 float childLayerAngle = -20; 1622 float childLayerAngle = -20;
1623 1623
1624 // Create a child layer that is rotated to a non-axis-aligned angle. 1624 // Create a child layer that is rotated to a non-axis-aligned angle.
1625 scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl ->rootLayer()->content_bounds()); 1625 scoped_ptr<LayerImpl> child = createScrollableLayer(childLayerId, m_hostImpl ->active_tree()->root_layer()->content_bounds());
1626 gfx::Transform rotateTransform; 1626 gfx::Transform rotateTransform;
1627 rotateTransform.Translate(-50, -50); 1627 rotateTransform.Translate(-50, -50);
1628 rotateTransform.Rotate(childLayerAngle); 1628 rotateTransform.Rotate(childLayerAngle);
1629 rotateTransform.Translate(50, 50); 1629 rotateTransform.Translate(50, 50);
1630 child->SetTransform(rotateTransform); 1630 child->SetTransform(rotateTransform);
1631 1631
1632 // Only allow vertical scrolling. 1632 // Only allow vertical scrolling.
1633 child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height()) ); 1633 child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height()) );
1634 m_hostImpl->rootLayer()->AddChild(child.Pass()); 1634 m_hostImpl->active_tree()->root_layer()->AddChild(child.Pass());
1635 1635
1636 gfx::Size surfaceSize(50, 50); 1636 gfx::Size surfaceSize(50, 50);
1637 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1637 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1638 initializeRendererAndDrawFrame(); 1638 initializeRendererAndDrawFrame();
1639 1639
1640 { 1640 {
1641 // Scroll down in screen coordinates with a gesture. 1641 // Scroll down in screen coordinates with a gesture.
1642 gfx::Vector2d gestureScrollDelta(0, 10); 1642 gfx::Vector2d gestureScrollDelta(0, 10);
1643 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient:: Gesture), InputHandlerClient::ScrollStarted); 1643 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient:: Gesture), InputHandlerClient::ScrollStarted);
1644 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); 1644 m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta);
1645 m_hostImpl->scrollEnd(); 1645 m_hostImpl->ScrollEnd();
1646 1646
1647 // The child layer should have scrolled down in its local coordinates an amount proportional to 1647 // The child layer should have scrolled down in its local coordinates an amount proportional to
1648 // the angle between it and the input scroll delta. 1648 // the angle between it and the input scroll delta.
1649 gfx::Vector2d expectedScrollDelta(0, gestureScrollDelta.y() * std::cos(M athUtil::Deg2Rad(childLayerAngle))); 1649 gfx::Vector2d expectedScrollDelta(0, gestureScrollDelta.y() * std::cos(M athUtil::Deg2Rad(childLayerAngle)));
1650 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 1650 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
1651 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); 1651 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta);
1652 1652
1653 // The root layer should not have scrolled, because the input delta was close to the layer's 1653 // The root layer should not have scrolled, because the input delta was close to the layer's
1654 // axis of movement. 1654 // axis of movement.
1655 EXPECT_EQ(scrollInfo->scrolls.size(), 1u); 1655 EXPECT_EQ(scrollInfo->scrolls.size(), 1u);
1656 } 1656 }
1657 1657
1658 { 1658 {
1659 // Now reset and scroll the same amount horizontally. 1659 // Now reset and scroll the same amount horizontally.
1660 m_hostImpl->rootLayer()->children()[1]->SetScrollDelta(gfx::Vector2dF()) ; 1660 m_hostImpl->active_tree()->root_layer()->children()[1]->SetScrollDelta(g fx::Vector2dF());
1661 gfx::Vector2d gestureScrollDelta(10, 0); 1661 gfx::Vector2d gestureScrollDelta(10, 0);
1662 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient:: Gesture), InputHandlerClient::ScrollStarted); 1662 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient:: Gesture), InputHandlerClient::ScrollStarted);
1663 m_hostImpl->scrollBy(gfx::Point(), gestureScrollDelta); 1663 m_hostImpl->ScrollBy(gfx::Point(), gestureScrollDelta);
1664 m_hostImpl->scrollEnd(); 1664 m_hostImpl->ScrollEnd();
1665 1665
1666 // The child layer should have scrolled down in its local coordinates an amount proportional to 1666 // The child layer should have scrolled down in its local coordinates an amount proportional to
1667 // the angle between it and the input scroll delta. 1667 // the angle between it and the input scroll delta.
1668 gfx::Vector2d expectedScrollDelta(0, -gestureScrollDelta.x() * std::sin( MathUtil::Deg2Rad(childLayerAngle))); 1668 gfx::Vector2d expectedScrollDelta(0, -gestureScrollDelta.x() * std::sin( MathUtil::Deg2Rad(childLayerAngle)));
1669 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDelt as(); 1669 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDelt as();
1670 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta); 1670 expectContains(*scrollInfo.get(), childLayerId, expectedScrollDelta);
1671 1671
1672 // The root layer should have scrolled more, since the input scroll delt a was mostly 1672 // The root layer should have scrolled more, since the input scroll delt a was mostly
1673 // orthogonal to the child layer's vertical scroll axis. 1673 // orthogonal to the child layer's vertical scroll axis.
1674 gfx::Vector2d expectedRootScrollDelta(gestureScrollDelta.x() * std::pow( std::cos(MathUtil::Deg2Rad(childLayerAngle)), 2), 0); 1674 gfx::Vector2d expectedRootScrollDelta(gestureScrollDelta.x() * std::pow( std::cos(MathUtil::Deg2Rad(childLayerAngle)), 2), 0);
1675 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), expecte dRootScrollDelta); 1675 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer( )->id(), expectedRootScrollDelta);
1676 } 1676 }
1677 } 1677 }
1678 1678
1679 TEST_F(LayerTreeHostImplTest, scrollScaledLayer) 1679 TEST_F(LayerTreeHostImplTest, scrollScaledLayer)
1680 { 1680 {
1681 setupScrollAndContentsLayers(gfx::Size(100, 100)); 1681 setupScrollAndContentsLayers(gfx::Size(100, 100));
1682 1682
1683 // Scale the layer to twice its normal size. 1683 // Scale the layer to twice its normal size.
1684 int scale = 2; 1684 int scale = 2;
1685 gfx::Transform scaleTransform; 1685 gfx::Transform scaleTransform;
1686 scaleTransform.Scale(scale, scale); 1686 scaleTransform.Scale(scale, scale);
1687 m_hostImpl->rootLayer()->SetTransform(scaleTransform); 1687 m_hostImpl->active_tree()->root_layer()->SetTransform(scaleTransform);
1688 1688
1689 gfx::Size surfaceSize(50, 50); 1689 gfx::Size surfaceSize(50, 50);
1690 m_hostImpl->setViewportSize(surfaceSize, surfaceSize); 1690 m_hostImpl->SetViewportSize(surfaceSize, surfaceSize);
1691 initializeRendererAndDrawFrame(); 1691 initializeRendererAndDrawFrame();
1692 1692
1693 // Scroll down in screen coordinates with a gesture. 1693 // Scroll down in screen coordinates with a gesture.
1694 gfx::Vector2d scrollDelta(0, 10); 1694 gfx::Vector2d scrollDelta(0, 10);
1695 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted); 1695 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Gest ure), InputHandlerClient::ScrollStarted);
1696 m_hostImpl->scrollBy(gfx::Point(), scrollDelta); 1696 m_hostImpl->ScrollBy(gfx::Point(), scrollDelta);
1697 m_hostImpl->scrollEnd(); 1697 m_hostImpl->ScrollEnd();
1698 1698
1699 // The layer should have scrolled down in its local coordinates, but half he amount. 1699 // The layer should have scrolled down in its local coordinates, but half he amount.
1700 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas() ; 1700 scoped_ptr<ScrollAndScaleSet> scrollInfo = m_hostImpl->ProcessScrollDeltas() ;
1701 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), gfx::Vector 2d(0, scrollDelta.y() / scale)); 1701 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), gfx::Vector2d(0, scrollDelta.y() / scale));
1702 1702
1703 // Reset and scroll down with the wheel. 1703 // Reset and scroll down with the wheel.
1704 m_hostImpl->rootLayer()->SetScrollDelta(gfx::Vector2dF()); 1704 m_hostImpl->active_tree()->root_layer()->SetScrollDelta(gfx::Vector2dF());
1705 gfx::Vector2d wheelScrollDelta(0, 10); 1705 gfx::Vector2d wheelScrollDelta(0, 10);
1706 EXPECT_EQ(m_hostImpl->scrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted); 1706 EXPECT_EQ(m_hostImpl->ScrollBegin(gfx::Point(0, 0), InputHandlerClient::Whee l), InputHandlerClient::ScrollStarted);
1707 m_hostImpl->scrollBy(gfx::Point(), wheelScrollDelta); 1707 m_hostImpl->ScrollBy(gfx::Point(), wheelScrollDelta);
1708 m_hostImpl->scrollEnd(); 1708 m_hostImpl->ScrollEnd();
1709 1709
1710 // The scale should not have been applied to the scroll delta. 1710 // The scale should not have been applied to the scroll delta.
1711 scrollInfo = m_hostImpl->processScrollDeltas(); 1711 scrollInfo = m_hostImpl->ProcessScrollDeltas();
1712 expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScroll Delta); 1712 expectContains(*scrollInfo.get(), m_hostImpl->active_tree()->root_layer()->i d(), wheelScrollDelta);
1713 } 1713 }
1714 1714
1715 class BlendStateTrackerContext: public TestWebGraphicsContext3D { 1715 class BlendStateTrackerContext: public TestWebGraphicsContext3D {
1716 public: 1716 public:
1717 BlendStateTrackerContext() : m_blend(false) { } 1717 BlendStateTrackerContext() : m_blend(false) { }
1718 1718
1719 virtual void enable(WebKit::WGC3Denum cap) 1719 virtual void enable(WebKit::WGC3Denum cap)
1720 { 1720 {
1721 if (cap == GL_BLEND) 1721 if (cap == GL_BLEND)
1722 m_blend = true; 1722 m_blend = true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 bool m_quadsAppended; 1792 bool m_quadsAppended;
1793 gfx::Rect m_quadRect; 1793 gfx::Rect m_quadRect;
1794 gfx::Rect m_opaqueContentRect; 1794 gfx::Rect m_opaqueContentRect;
1795 gfx::Rect m_quadVisibleRect; 1795 gfx::Rect m_quadVisibleRect;
1796 ResourceProvider::ResourceId m_resourceId; 1796 ResourceProvider::ResourceId m_resourceId;
1797 }; 1797 };
1798 1798
1799 TEST_F(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers) 1799 TEST_F(LayerTreeHostImplTest, blendingOffWhenDrawingOpaqueLayers)
1800 { 1800 {
1801 { 1801 {
1802 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->activeTree(), 1); 1802 scoped_ptr<LayerImpl> root = LayerImpl::Create(m_hostImpl->active_tree() , 1);
1803 root->SetAnchorPoint(gfx::PointF(0, 0)); 1803 root->SetAnchorPoint(gfx::PointF(0, 0));
1804 root->SetBounds(gfx::Size(10, 10)); 1804 root->SetBounds(gfx::Size(10, 10));
1805 root->SetContentBounds(root->bounds()); 1805 root->SetContentBounds(root->bounds());
1806 root->SetDrawsContent(false); 1806 root->SetDrawsContent(false);
1807 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 1807 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
1808 } 1808 }
1809 LayerImpl* root = m_hostImpl->rootLayer(); 1809 LayerImpl* root = m_hostImpl->active_tree()->root_layer();
1810 1810
1811 root->AddChild(BlendStateCheckLayer::Create(m_hostImpl->activeTree(), 2, m_h ostImpl->resourceProvider())); 1811 root->AddChild(BlendStateCheckLayer::Create(m_hostImpl->active_tree(), 2, m_ hostImpl->resource_provider()));
1812 BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->chil dren()[0]); 1812 BlendStateCheckLayer* layer1 = static_cast<BlendStateCheckLayer*>(root->chil dren()[0]);
1813 layer1->SetPosition(gfx::PointF(2, 2)); 1813 layer1->SetPosition(gfx::PointF(2, 2));
1814 1814
1815 LayerTreeHostImpl::FrameData frame; 1815 LayerTreeHostImpl::FrameData frame;
1816 1816
1817 // Opaque layer, drawn without blending. 1817 // Opaque layer, drawn without blending.
1818 layer1->SetContentsOpaque(true); 1818 layer1->SetContentsOpaque(true);
1819 layer1->setExpectation(false, false); 1819 layer1->setExpectation(false, false);
1820 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1820 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1821 m_hostImpl->drawLayers(frame); 1821 m_hostImpl->DrawLayers(&frame);
1822 EXPECT_TRUE(layer1->quadsAppended()); 1822 EXPECT_TRUE(layer1->quadsAppended());
1823 m_hostImpl->didDrawAllLayers(frame); 1823 m_hostImpl->DidDrawAllLayers(frame);
1824 1824
1825 // Layer with translucent content and painting, so drawn with blending. 1825 // Layer with translucent content and painting, so drawn with blending.
1826 layer1->SetContentsOpaque(false); 1826 layer1->SetContentsOpaque(false);
1827 layer1->setExpectation(true, false); 1827 layer1->setExpectation(true, false);
1828 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1828 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1829 m_hostImpl->drawLayers(frame); 1829 m_hostImpl->DrawLayers(&frame);
1830 EXPECT_TRUE(layer1->quadsAppended()); 1830 EXPECT_TRUE(layer1->quadsAppended());
1831 m_hostImpl->didDrawAllLayers(frame); 1831 m_hostImpl->DidDrawAllLayers(frame);
1832 1832
1833 // Layer with translucent opacity, drawn with blending. 1833 // Layer with translucent opacity, drawn with blending.
1834 layer1->SetContentsOpaque(true); 1834 layer1->SetContentsOpaque(true);
1835 layer1->SetOpacity(0.5); 1835 layer1->SetOpacity(0.5);
1836 layer1->setExpectation(true, false); 1836 layer1->setExpectation(true, false);
1837 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1837 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1838 m_hostImpl->drawLayers(frame); 1838 m_hostImpl->DrawLayers(&frame);
1839 EXPECT_TRUE(layer1->quadsAppended()); 1839 EXPECT_TRUE(layer1->quadsAppended());
1840 m_hostImpl->didDrawAllLayers(frame); 1840 m_hostImpl->DidDrawAllLayers(frame);
1841 1841
1842 // Layer with translucent opacity and painting, drawn with blending. 1842 // Layer with translucent opacity and painting, drawn with blending.
1843 layer1->SetContentsOpaque(true); 1843 layer1->SetContentsOpaque(true);
1844 layer1->SetOpacity(0.5); 1844 layer1->SetOpacity(0.5);
1845 layer1->setExpectation(true, false); 1845 layer1->setExpectation(true, false);
1846 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1846 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1847 m_hostImpl->drawLayers(frame); 1847 m_hostImpl->DrawLayers(&frame);
1848 EXPECT_TRUE(layer1->quadsAppended()); 1848 EXPECT_TRUE(layer1->quadsAppended());
1849 m_hostImpl->didDrawAllLayers(frame); 1849 m_hostImpl->DidDrawAllLayers(frame);
1850 1850
1851 layer1->AddChild(BlendStateCheckLayer::Create(m_hostImpl->activeTree(), 3, m _hostImpl->resourceProvider())); 1851 layer1->AddChild(BlendStateCheckLayer::Create(m_hostImpl->active_tree(), 3, m_hostImpl->resource_provider()));
1852 BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>(layer1->ch ildren()[0]); 1852 BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>(layer1->ch ildren()[0]);
1853 layer2->SetPosition(gfx::PointF(4, 4)); 1853 layer2->SetPosition(gfx::PointF(4, 4));
1854 1854
1855 // 2 opaque layers, drawn without blending. 1855 // 2 opaque layers, drawn without blending.
1856 layer1->SetContentsOpaque(true); 1856 layer1->SetContentsOpaque(true);
1857 layer1->SetOpacity(1); 1857 layer1->SetOpacity(1);
1858 layer1->setExpectation(false, false); 1858 layer1->setExpectation(false, false);
1859 layer2->SetContentsOpaque(true); 1859 layer2->SetContentsOpaque(true);
1860 layer2->SetOpacity(1); 1860 layer2->SetOpacity(1);
1861 layer2->setExpectation(false, false); 1861 layer2->setExpectation(false, false);
1862 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1862 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1863 m_hostImpl->drawLayers(frame); 1863 m_hostImpl->DrawLayers(&frame);
1864 EXPECT_TRUE(layer1->quadsAppended()); 1864 EXPECT_TRUE(layer1->quadsAppended());
1865 EXPECT_TRUE(layer2->quadsAppended()); 1865 EXPECT_TRUE(layer2->quadsAppended());
1866 m_hostImpl->didDrawAllLayers(frame); 1866 m_hostImpl->DidDrawAllLayers(frame);
1867 1867
1868 // Parent layer with translucent content, drawn with blending. 1868 // Parent layer with translucent content, drawn with blending.
1869 // Child layer with opaque content, drawn without blending. 1869 // Child layer with opaque content, drawn without blending.
1870 layer1->SetContentsOpaque(false); 1870 layer1->SetContentsOpaque(false);
1871 layer1->setExpectation(true, false); 1871 layer1->setExpectation(true, false);
1872 layer2->setExpectation(false, false); 1872 layer2->setExpectation(false, false);
1873 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1873 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1874 m_hostImpl->drawLayers(frame); 1874 m_hostImpl->DrawLayers(&frame);
1875 EXPECT_TRUE(layer1->quadsAppended()); 1875 EXPECT_TRUE(layer1->quadsAppended());
1876 EXPECT_TRUE(layer2->quadsAppended()); 1876 EXPECT_TRUE(layer2->quadsAppended());
1877 m_hostImpl->didDrawAllLayers(frame); 1877 m_hostImpl->DidDrawAllLayers(frame);
1878 1878
1879 // Parent layer with translucent content but opaque painting, drawn without blending. 1879 // Parent layer with translucent content but opaque painting, drawn without blending.
1880 // Child layer with opaque content, drawn without blending. 1880 // Child layer with opaque content, drawn without blending.
1881 layer1->SetContentsOpaque(true); 1881 layer1->SetContentsOpaque(true);
1882 layer1->setExpectation(false, false); 1882 layer1->setExpectation(false, false);
1883 layer2->setExpectation(false, false); 1883 layer2->setExpectation(false, false);
1884 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1884 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1885 m_hostImpl->drawLayers(frame); 1885 m_hostImpl->DrawLayers(&frame);
1886 EXPECT_TRUE(layer1->quadsAppended()); 1886 EXPECT_TRUE(layer1->quadsAppended());
1887 EXPECT_TRUE(layer2->quadsAppended()); 1887 EXPECT_TRUE(layer2->quadsAppended());
1888 m_hostImpl->didDrawAllLayers(frame); 1888 m_hostImpl->DidDrawAllLayers(frame);
1889 1889
1890 // Parent layer with translucent opacity and opaque content. Since it has a 1890 // Parent layer with translucent opacity and opaque content. Since it has a
1891 // drawing child, it's drawn to a render surface which carries the opacity, 1891 // drawing child, it's drawn to a render surface which carries the opacity,
1892 // so it's itself drawn without blending. 1892 // so it's itself drawn without blending.
1893 // Child layer with opaque content, drawn without blending (parent surface 1893 // Child layer with opaque content, drawn without blending (parent surface
1894 // carries the inherited opacity). 1894 // carries the inherited opacity).
1895 layer1->SetContentsOpaque(true); 1895 layer1->SetContentsOpaque(true);
1896 layer1->SetOpacity(0.5); 1896 layer1->SetOpacity(0.5);
1897 layer1->setExpectation(false, true); 1897 layer1->setExpectation(false, true);
1898 layer2->setExpectation(false, false); 1898 layer2->setExpectation(false, false);
1899 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1899 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1900 m_hostImpl->drawLayers(frame); 1900 m_hostImpl->DrawLayers(&frame);
1901 EXPECT_TRUE(layer1->quadsAppended()); 1901 EXPECT_TRUE(layer1->quadsAppended());
1902 EXPECT_TRUE(layer2->quadsAppended()); 1902 EXPECT_TRUE(layer2->quadsAppended());
1903 m_hostImpl->didDrawAllLayers(frame); 1903 m_hostImpl->DidDrawAllLayers(frame);
1904 1904
1905 // Draw again, but with child non-opaque, to make sure 1905 // Draw again, but with child non-opaque, to make sure
1906 // layer1 not culled. 1906 // layer1 not culled.
1907 layer1->SetContentsOpaque(true); 1907 layer1->SetContentsOpaque(true);
1908 layer1->SetOpacity(1); 1908 layer1->SetOpacity(1);
1909 layer1->setExpectation(false, false); 1909 layer1->setExpectation(false, false);
1910 layer2->SetContentsOpaque(true); 1910 layer2->SetContentsOpaque(true);
1911 layer2->SetOpacity(0.5); 1911 layer2->SetOpacity(0.5);
1912 layer2->setExpectation(true, false); 1912 layer2->setExpectation(true, false);
1913 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1913 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1914 m_hostImpl->drawLayers(frame); 1914 m_hostImpl->DrawLayers(&frame);
1915 EXPECT_TRUE(layer1->quadsAppended()); 1915 EXPECT_TRUE(layer1->quadsAppended());
1916 EXPECT_TRUE(layer2->quadsAppended()); 1916 EXPECT_TRUE(layer2->quadsAppended());
1917 m_hostImpl->didDrawAllLayers(frame); 1917 m_hostImpl->DidDrawAllLayers(frame);
1918 1918
1919 // A second way of making the child non-opaque. 1919 // A second way of making the child non-opaque.
1920 layer1->SetContentsOpaque(true); 1920 layer1->SetContentsOpaque(true);
1921 layer1->SetOpacity(1); 1921 layer1->SetOpacity(1);
1922 layer1->setExpectation(false, false); 1922 layer1->setExpectation(false, false);
1923 layer2->SetContentsOpaque(false); 1923 layer2->SetContentsOpaque(false);
1924 layer2->SetOpacity(1); 1924 layer2->SetOpacity(1);
1925 layer2->setExpectation(true, false); 1925 layer2->setExpectation(true, false);
1926 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1926 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1927 m_hostImpl->drawLayers(frame); 1927 m_hostImpl->DrawLayers(&frame);
1928 EXPECT_TRUE(layer1->quadsAppended()); 1928 EXPECT_TRUE(layer1->quadsAppended());
1929 EXPECT_TRUE(layer2->quadsAppended()); 1929 EXPECT_TRUE(layer2->quadsAppended());
1930 m_hostImpl->didDrawAllLayers(frame); 1930 m_hostImpl->DidDrawAllLayers(frame);
1931 1931
1932 // And when the layer says its not opaque but is painted opaque, it is not b lended. 1932 // And when the layer says its not opaque but is painted opaque, it is not b lended.
1933 layer1->SetContentsOpaque(true); 1933 layer1->SetContentsOpaque(true);
1934 layer1->SetOpacity(1); 1934 layer1->SetOpacity(1);
1935 layer1->setExpectation(false, false); 1935 layer1->setExpectation(false, false);
1936 layer2->SetContentsOpaque(true); 1936 layer2->SetContentsOpaque(true);
1937 layer2->SetOpacity(1); 1937 layer2->SetOpacity(1);
1938 layer2->setExpectation(false, false); 1938 layer2->setExpectation(false, false);
1939 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1939 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1940 m_hostImpl->drawLayers(frame); 1940 m_hostImpl->DrawLayers(&frame);
1941 EXPECT_TRUE(layer1->quadsAppended()); 1941 EXPECT_TRUE(layer1->quadsAppended());
1942 EXPECT_TRUE(layer2->quadsAppended()); 1942 EXPECT_TRUE(layer2->quadsAppended());
1943 m_hostImpl->didDrawAllLayers(frame); 1943 m_hostImpl->DidDrawAllLayers(frame);
1944 1944
1945 // Layer with partially opaque contents, drawn with blending. 1945 // Layer with partially opaque contents, drawn with blending.
1946 layer1->SetContentsOpaque(false); 1946 layer1->SetContentsOpaque(false);
1947 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); 1947 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5));
1948 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 5)); 1948 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 5));
1949 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 1949 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
1950 layer1->setExpectation(true, false); 1950 layer1->setExpectation(true, false);
1951 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1951 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1952 m_hostImpl->drawLayers(frame); 1952 m_hostImpl->DrawLayers(&frame);
1953 EXPECT_TRUE(layer1->quadsAppended()); 1953 EXPECT_TRUE(layer1->quadsAppended());
1954 m_hostImpl->didDrawAllLayers(frame); 1954 m_hostImpl->DidDrawAllLayers(frame);
1955 1955
1956 // Layer with partially opaque contents partially culled, drawn with blendin g. 1956 // Layer with partially opaque contents partially culled, drawn with blendin g.
1957 layer1->SetContentsOpaque(false); 1957 layer1->SetContentsOpaque(false);
1958 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); 1958 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5));
1959 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 2)); 1959 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 5, 2));
1960 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 1960 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
1961 layer1->setExpectation(true, false); 1961 layer1->setExpectation(true, false);
1962 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1962 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1963 m_hostImpl->drawLayers(frame); 1963 m_hostImpl->DrawLayers(&frame);
1964 EXPECT_TRUE(layer1->quadsAppended()); 1964 EXPECT_TRUE(layer1->quadsAppended());
1965 m_hostImpl->didDrawAllLayers(frame); 1965 m_hostImpl->DidDrawAllLayers(frame);
1966 1966
1967 // Layer with partially opaque contents culled, drawn with blending. 1967 // Layer with partially opaque contents culled, drawn with blending.
1968 layer1->SetContentsOpaque(false); 1968 layer1->SetContentsOpaque(false);
1969 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); 1969 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5));
1970 layer1->setQuadVisibleRect(gfx::Rect(7, 5, 3, 5)); 1970 layer1->setQuadVisibleRect(gfx::Rect(7, 5, 3, 5));
1971 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 1971 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
1972 layer1->setExpectation(true, false); 1972 layer1->setExpectation(true, false);
1973 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1973 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1974 m_hostImpl->drawLayers(frame); 1974 m_hostImpl->DrawLayers(&frame);
1975 EXPECT_TRUE(layer1->quadsAppended()); 1975 EXPECT_TRUE(layer1->quadsAppended());
1976 m_hostImpl->didDrawAllLayers(frame); 1976 m_hostImpl->DidDrawAllLayers(frame);
1977 1977
1978 // Layer with partially opaque contents and translucent contents culled, dra wn without blending. 1978 // Layer with partially opaque contents and translucent contents culled, dra wn without blending.
1979 layer1->SetContentsOpaque(false); 1979 layer1->SetContentsOpaque(false);
1980 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5)); 1980 layer1->setQuadRect(gfx::Rect(5, 5, 5, 5));
1981 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); 1981 layer1->setQuadVisibleRect(gfx::Rect(5, 5, 2, 5));
1982 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); 1982 layer1->setOpaqueContentRect(gfx::Rect(5, 5, 2, 5));
1983 layer1->setExpectation(false, false); 1983 layer1->setExpectation(false, false);
1984 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 1984 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
1985 m_hostImpl->drawLayers(frame); 1985 m_hostImpl->DrawLayers(&frame);
1986 EXPECT_TRUE(layer1->quadsAppended()); 1986 EXPECT_TRUE(layer1->quadsAppended());
1987 m_hostImpl->didDrawAllLayers(frame); 1987 m_hostImpl->DidDrawAllLayers(frame);
1988 1988
1989 } 1989 }
1990 1990
1991 TEST_F(LayerTreeHostImplTest, viewportCovered) 1991 TEST_F(LayerTreeHostImplTest, viewportCovered)
1992 { 1992 {
1993 m_hostImpl->initializeRenderer(createOutputSurface()); 1993 m_hostImpl->InitializeRenderer(createOutputSurface());
1994 m_hostImpl->activeTree()->set_background_color(SK_ColorGRAY); 1994 m_hostImpl->active_tree()->set_background_color(SK_ColorGRAY);
1995 1995
1996 gfx::Size viewportSize(1000, 1000); 1996 gfx::Size viewportSize(1000, 1000);
1997 m_hostImpl->setViewportSize(viewportSize, viewportSize); 1997 m_hostImpl->SetViewportSize(viewportSize, viewportSize);
1998 1998
1999 m_hostImpl->activeTree()->SetRootLayer(LayerImpl::Create(m_hostImpl->activeT ree(), 1)); 1999 m_hostImpl->active_tree()->SetRootLayer(LayerImpl::Create(m_hostImpl->active _tree(), 1));
2000 m_hostImpl->rootLayer()->AddChild(BlendStateCheckLayer::Create(m_hostImpl->a ctiveTree(), 2, m_hostImpl->resourceProvider())); 2000 m_hostImpl->active_tree()->root_layer()->AddChild(BlendStateCheckLayer::Crea te(m_hostImpl->active_tree(), 2, m_hostImpl->resource_provider()));
2001 BlendStateCheckLayer* child = static_cast<BlendStateCheckLayer*>(m_hostImpl- >rootLayer()->children()[0]); 2001 BlendStateCheckLayer* child = static_cast<BlendStateCheckLayer*>(m_hostImpl- >active_tree()->root_layer()->children()[0]);
2002 child->setExpectation(false, false); 2002 child->setExpectation(false, false);
2003 child->SetContentsOpaque(true); 2003 child->SetContentsOpaque(true);
2004 2004
2005 // No gutter rects 2005 // No gutter rects
2006 { 2006 {
2007 gfx::Rect layerRect(0, 0, 1000, 1000); 2007 gfx::Rect layerRect(0, 0, 1000, 1000);
2008 child->SetPosition(layerRect.origin()); 2008 child->SetPosition(layerRect.origin());
2009 child->SetBounds(layerRect.size()); 2009 child->SetBounds(layerRect.size());
2010 child->SetContentBounds(layerRect.size()); 2010 child->SetContentBounds(layerRect.size());
2011 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); 2011 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size()));
2012 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); 2012 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size()));
2013 2013
2014 LayerTreeHostImpl::FrameData frame; 2014 LayerTreeHostImpl::FrameData frame;
2015 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2015 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2016 ASSERT_EQ(1u, frame.renderPasses.size()); 2016 ASSERT_EQ(1u, frame.render_passes.size());
2017 2017
2018 size_t numGutterQuads = 0; 2018 size_t numGutterQuads = 0;
2019 for (size_t i = 0; i < frame.renderPasses[0]->quad_list.size(); ++i) 2019 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2020 numGutterQuads += (frame.renderPasses[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; 2020 numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0;
2021 EXPECT_EQ(0u, numGutterQuads); 2021 EXPECT_EQ(0u, numGutterQuads);
2022 EXPECT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 2022 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size());
2023 2023
2024 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quad _list, gfx::Rect(gfx::Point(), viewportSize)); 2024 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->qua d_list, gfx::Rect(gfx::Point(), viewportSize));
2025 m_hostImpl->didDrawAllLayers(frame); 2025 m_hostImpl->DidDrawAllLayers(frame);
2026 } 2026 }
2027 2027
2028 // Empty visible content area (fullscreen gutter rect) 2028 // Empty visible content area (fullscreen gutter rect)
2029 { 2029 {
2030 gfx::Rect layerRect(0, 0, 0, 0); 2030 gfx::Rect layerRect(0, 0, 0, 0);
2031 child->SetPosition(layerRect.origin()); 2031 child->SetPosition(layerRect.origin());
2032 child->SetBounds(layerRect.size()); 2032 child->SetBounds(layerRect.size());
2033 child->SetContentBounds(layerRect.size()); 2033 child->SetContentBounds(layerRect.size());
2034 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); 2034 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size()));
2035 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); 2035 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size()));
2036 2036
2037 LayerTreeHostImpl::FrameData frame; 2037 LayerTreeHostImpl::FrameData frame;
2038 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2038 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2039 ASSERT_EQ(1u, frame.renderPasses.size()); 2039 ASSERT_EQ(1u, frame.render_passes.size());
2040 2040
2041 size_t numGutterQuads = 0; 2041 size_t numGutterQuads = 0;
2042 for (size_t i = 0; i < frame.renderPasses[0]->quad_list.size(); ++i) 2042 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2043 numGutterQuads += (frame.renderPasses[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; 2043 numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0;
2044 EXPECT_EQ(1u, numGutterQuads); 2044 EXPECT_EQ(1u, numGutterQuads);
2045 EXPECT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 2045 EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size());
2046 2046
2047 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quad _list, gfx::Rect(gfx::Point(), viewportSize)); 2047 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->qua d_list, gfx::Rect(gfx::Point(), viewportSize));
2048 m_hostImpl->didDrawAllLayers(frame); 2048 m_hostImpl->DidDrawAllLayers(frame);
2049 } 2049 }
2050 2050
2051 // Content area in middle of clip rect (four surrounding gutter rects) 2051 // Content area in middle of clip rect (four surrounding gutter rects)
2052 { 2052 {
2053 gfx::Rect layerRect(500, 500, 200, 200); 2053 gfx::Rect layerRect(500, 500, 200, 200);
2054 child->SetPosition(layerRect.origin()); 2054 child->SetPosition(layerRect.origin());
2055 child->SetBounds(layerRect.size()); 2055 child->SetBounds(layerRect.size());
2056 child->SetContentBounds(layerRect.size()); 2056 child->SetContentBounds(layerRect.size());
2057 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size())); 2057 child->setQuadRect(gfx::Rect(gfx::Point(), layerRect.size()));
2058 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size())); 2058 child->setQuadVisibleRect(gfx::Rect(gfx::Point(), layerRect.size()));
2059 2059
2060 LayerTreeHostImpl::FrameData frame; 2060 LayerTreeHostImpl::FrameData frame;
2061 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2061 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2062 ASSERT_EQ(1u, frame.renderPasses.size()); 2062 ASSERT_EQ(1u, frame.render_passes.size());
2063 2063
2064 size_t numGutterQuads = 0; 2064 size_t numGutterQuads = 0;
2065 for (size_t i = 0; i < frame.renderPasses[0]->quad_list.size(); ++i) 2065 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i)
2066 numGutterQuads += (frame.renderPasses[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0; 2066 numGutterQuads += (frame.render_passes[0]->quad_list[i]->material == DrawQuad::SOLID_COLOR) ? 1 : 0;
2067 EXPECT_EQ(4u, numGutterQuads); 2067 EXPECT_EQ(4u, numGutterQuads);
2068 EXPECT_EQ(5u, frame.renderPasses[0]->quad_list.size()); 2068 EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size());
2069 2069
2070 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.renderPasses[0]->quad _list, gfx::Rect(gfx::Point(), viewportSize)); 2070 LayerTestCommon::verifyQuadsExactlyCoverRect(frame.render_passes[0]->qua d_list, gfx::Rect(gfx::Point(), viewportSize));
2071 m_hostImpl->didDrawAllLayers(frame); 2071 m_hostImpl->DidDrawAllLayers(frame);
2072 } 2072 }
2073 2073
2074 } 2074 }
2075 2075
2076 2076
2077 class ReshapeTrackerContext: public TestWebGraphicsContext3D { 2077 class ReshapeTrackerContext: public TestWebGraphicsContext3D {
2078 public: 2078 public:
2079 ReshapeTrackerContext() : m_reshapeCalled(false) { } 2079 ReshapeTrackerContext() : m_reshapeCalled(false) { }
2080 2080
2081 virtual void reshape(int width, int height) 2081 virtual void reshape(int width, int height)
(...skipping 14 matching lines...) Expand all
2096 FakeDrawableLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { } 2096 FakeDrawableLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { }
2097 }; 2097 };
2098 2098
2099 // Only reshape when we know we are going to draw. Otherwise, the reshape 2099 // Only reshape when we know we are going to draw. Otherwise, the reshape
2100 // can leave the window at the wrong size if we never draw and the proper 2100 // can leave the window at the wrong size if we never draw and the proper
2101 // viewport size is never set. 2101 // viewport size is never set.
2102 TEST_F(LayerTreeHostImplTest, reshapeNotCalledUntilDraw) 2102 TEST_F(LayerTreeHostImplTest, reshapeNotCalledUntilDraw)
2103 { 2103 {
2104 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).PassAs<OutputSurf ace>(); 2104 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).PassAs<OutputSurf ace>();
2105 ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>( outputSurface->context3d()); 2105 ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>( outputSurface->context3d());
2106 m_hostImpl->initializeRenderer(outputSurface.Pass()); 2106 m_hostImpl->InitializeRenderer(outputSurface.Pass());
2107 2107
2108 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->activ eTree(), 1); 2108 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->activ e_tree(), 1);
2109 root->SetAnchorPoint(gfx::PointF(0, 0)); 2109 root->SetAnchorPoint(gfx::PointF(0, 0));
2110 root->SetBounds(gfx::Size(10, 10)); 2110 root->SetBounds(gfx::Size(10, 10));
2111 root->SetDrawsContent(true); 2111 root->SetDrawsContent(true);
2112 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 2112 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
2113 EXPECT_FALSE(reshapeTracker->reshapeCalled()); 2113 EXPECT_FALSE(reshapeTracker->reshapeCalled());
2114 2114
2115 LayerTreeHostImpl::FrameData frame; 2115 LayerTreeHostImpl::FrameData frame;
2116 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2116 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2117 m_hostImpl->drawLayers(frame); 2117 m_hostImpl->DrawLayers(&frame);
2118 EXPECT_TRUE(reshapeTracker->reshapeCalled()); 2118 EXPECT_TRUE(reshapeTracker->reshapeCalled());
2119 m_hostImpl->didDrawAllLayers(frame); 2119 m_hostImpl->DidDrawAllLayers(frame);
2120 } 2120 }
2121 2121
2122 class PartialSwapTrackerContext : public TestWebGraphicsContext3D { 2122 class PartialSwapTrackerContext : public TestWebGraphicsContext3D {
2123 public: 2123 public:
2124 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) 2124 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height)
2125 { 2125 {
2126 m_partialSwapRect = gfx::Rect(x, y, width, height); 2126 m_partialSwapRect = gfx::Rect(x, y, width, height);
2127 } 2127 }
2128 2128
2129 virtual WebKit::WebString getString(WebKit::WGC3Denum name) 2129 virtual WebKit::WebString getString(WebKit::WGC3Denum name)
(...skipping 14 matching lines...) Expand all
2144 // where it should request to swap only the subBuffer that is damaged. 2144 // where it should request to swap only the subBuffer that is damaged.
2145 TEST_F(LayerTreeHostImplTest, partialSwapReceivesDamageRect) 2145 TEST_F(LayerTreeHostImplTest, partialSwapReceivesDamageRect)
2146 { 2146 {
2147 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).PassAs<Output Surface>(); 2147 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).PassAs<Output Surface>();
2148 PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrack erContext*>(outputSurface->context3d()); 2148 PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrack erContext*>(outputSurface->context3d());
2149 2149
2150 // This test creates its own LayerTreeHostImpl, so 2150 // This test creates its own LayerTreeHostImpl, so
2151 // that we can force partial swap enabled. 2151 // that we can force partial swap enabled.
2152 LayerTreeSettings settings; 2152 LayerTreeSettings settings;
2153 settings.partialSwapEnabled = true; 2153 settings.partialSwapEnabled = true;
2154 scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::create( settings, this, &m_proxy); 2154 scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::Create( settings, this, &m_proxy);
2155 layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); 2155 layerTreeHostImpl->InitializeRenderer(outputSurface.Pass());
2156 layerTreeHostImpl->setViewportSize(gfx::Size(500, 500), gfx::Size(500, 500)) ; 2156 layerTreeHostImpl->SetViewportSize(gfx::Size(500, 500), gfx::Size(500, 500)) ;
2157 2157
2158 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(layerTreeHostImpl ->activeTree(), 1); 2158 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(layerTreeHostImpl ->active_tree(), 1);
2159 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(layerTreeHostImp l->activeTree(), 2); 2159 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(layerTreeHostImp l->active_tree(), 2);
2160 child->SetPosition(gfx::PointF(12, 13)); 2160 child->SetPosition(gfx::PointF(12, 13));
2161 child->SetAnchorPoint(gfx::PointF(0, 0)); 2161 child->SetAnchorPoint(gfx::PointF(0, 0));
2162 child->SetBounds(gfx::Size(14, 15)); 2162 child->SetBounds(gfx::Size(14, 15));
2163 child->SetContentBounds(gfx::Size(14, 15)); 2163 child->SetContentBounds(gfx::Size(14, 15));
2164 child->SetDrawsContent(true); 2164 child->SetDrawsContent(true);
2165 root->SetAnchorPoint(gfx::PointF(0, 0)); 2165 root->SetAnchorPoint(gfx::PointF(0, 0));
2166 root->SetBounds(gfx::Size(500, 500)); 2166 root->SetBounds(gfx::Size(500, 500));
2167 root->SetContentBounds(gfx::Size(500, 500)); 2167 root->SetContentBounds(gfx::Size(500, 500));
2168 root->SetDrawsContent(true); 2168 root->SetDrawsContent(true);
2169 root->AddChild(child.Pass()); 2169 root->AddChild(child.Pass());
2170 layerTreeHostImpl->activeTree()->SetRootLayer(root.Pass()); 2170 layerTreeHostImpl->active_tree()->SetRootLayer(root.Pass());
2171 2171
2172 LayerTreeHostImpl::FrameData frame; 2172 LayerTreeHostImpl::FrameData frame;
2173 2173
2174 // First frame, the entire screen should get swapped. 2174 // First frame, the entire screen should get swapped.
2175 EXPECT_TRUE(layerTreeHostImpl->prepareToDraw(frame)); 2175 EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame));
2176 layerTreeHostImpl->drawLayers(frame); 2176 layerTreeHostImpl->DrawLayers(&frame);
2177 layerTreeHostImpl->didDrawAllLayers(frame); 2177 layerTreeHostImpl->DidDrawAllLayers(frame);
2178 layerTreeHostImpl->swapBuffers(); 2178 layerTreeHostImpl->SwapBuffers();
2179 gfx::Rect actualSwapRect = partialSwapTracker->partialSwapRect(); 2179 gfx::Rect actualSwapRect = partialSwapTracker->partialSwapRect();
2180 gfx::Rect expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(500, 500)); 2180 gfx::Rect expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(500, 500));
2181 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); 2181 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x());
2182 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); 2182 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y());
2183 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); 2183 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width());
2184 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); 2184 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height());
2185 2185
2186 // Second frame, only the damaged area should get swapped. Damage should be the union 2186 // Second frame, only the damaged area should get swapped. Damage should be the union
2187 // of old and new child rects. 2187 // of old and new child rects.
2188 // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(26, 28)); 2188 // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(26, 28));
2189 // expected swap rect: vertically flipped, with origin at bottom left corner . 2189 // expected swap rect: vertically flipped, with origin at bottom left corner .
2190 layerTreeHostImpl->rootLayer()->children()[0]->SetPosition(gfx::PointF(0, 0) ); 2190 layerTreeHostImpl->active_tree()->root_layer()->children()[0]->SetPosition(g fx::PointF(0, 0));
2191 EXPECT_TRUE(layerTreeHostImpl->prepareToDraw(frame)); 2191 EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame));
2192 layerTreeHostImpl->drawLayers(frame); 2192 layerTreeHostImpl->DrawLayers(&frame);
2193 m_hostImpl->didDrawAllLayers(frame); 2193 m_hostImpl->DidDrawAllLayers(frame);
2194 layerTreeHostImpl->swapBuffers(); 2194 layerTreeHostImpl->SwapBuffers();
2195 actualSwapRect = partialSwapTracker->partialSwapRect(); 2195 actualSwapRect = partialSwapTracker->partialSwapRect();
2196 expectedSwapRect = gfx::Rect(gfx::Point(0, 500-28), gfx::Size(26, 28)); 2196 expectedSwapRect = gfx::Rect(gfx::Point(0, 500-28), gfx::Size(26, 28));
2197 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); 2197 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x());
2198 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); 2198 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y());
2199 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); 2199 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width());
2200 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); 2200 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height());
2201 2201
2202 // Make sure that partial swap is constrained to the viewport dimensions 2202 // Make sure that partial swap is constrained to the viewport dimensions
2203 // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(500, 500)); 2203 // expected damage rect: gfx::Rect(gfx::Point(), gfx::Size(500, 500));
2204 // expected swap rect: flipped damage rect, but also clamped to viewport 2204 // expected swap rect: flipped damage rect, but also clamped to viewport
2205 layerTreeHostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); 2205 layerTreeHostImpl->SetViewportSize(gfx::Size(10, 10), gfx::Size(10, 10));
2206 layerTreeHostImpl->rootLayer()->SetOpacity(0.7f); // this will damage everyt hing 2206 layerTreeHostImpl->active_tree()->root_layer()->SetOpacity(0.7f); // this wi ll damage everything
2207 EXPECT_TRUE(layerTreeHostImpl->prepareToDraw(frame)); 2207 EXPECT_TRUE(layerTreeHostImpl->PrepareToDraw(&frame));
2208 layerTreeHostImpl->drawLayers(frame); 2208 layerTreeHostImpl->DrawLayers(&frame);
2209 m_hostImpl->didDrawAllLayers(frame); 2209 m_hostImpl->DidDrawAllLayers(frame);
2210 layerTreeHostImpl->swapBuffers(); 2210 layerTreeHostImpl->SwapBuffers();
2211 actualSwapRect = partialSwapTracker->partialSwapRect(); 2211 actualSwapRect = partialSwapTracker->partialSwapRect();
2212 expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(10, 10)); 2212 expectedSwapRect = gfx::Rect(gfx::Point(), gfx::Size(10, 10));
2213 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x()); 2213 EXPECT_EQ(expectedSwapRect.x(), actualSwapRect.x());
2214 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y()); 2214 EXPECT_EQ(expectedSwapRect.y(), actualSwapRect.y());
2215 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width()); 2215 EXPECT_EQ(expectedSwapRect.width(), actualSwapRect.width());
2216 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height()); 2216 EXPECT_EQ(expectedSwapRect.height(), actualSwapRect.height());
2217 } 2217 }
2218 2218
2219 TEST_F(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface) 2219 TEST_F(LayerTreeHostImplTest, rootLayerDoesntCreateExtraSurface)
2220 { 2220 {
2221 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->activ eTree(), 1); 2221 scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::Create(m_hostImpl->activ e_tree(), 1);
2222 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(m_hostImpl->acti veTree(), 2); 2222 scoped_ptr<LayerImpl> child = FakeDrawableLayerImpl::Create(m_hostImpl->acti ve_tree(), 2);
2223 child->SetAnchorPoint(gfx::PointF(0, 0)); 2223 child->SetAnchorPoint(gfx::PointF(0, 0));
2224 child->SetBounds(gfx::Size(10, 10)); 2224 child->SetBounds(gfx::Size(10, 10));
2225 child->SetContentBounds(gfx::Size(10, 10)); 2225 child->SetContentBounds(gfx::Size(10, 10));
2226 child->SetDrawsContent(true); 2226 child->SetDrawsContent(true);
2227 root->SetAnchorPoint(gfx::PointF(0, 0)); 2227 root->SetAnchorPoint(gfx::PointF(0, 0));
2228 root->SetBounds(gfx::Size(10, 10)); 2228 root->SetBounds(gfx::Size(10, 10));
2229 root->SetContentBounds(gfx::Size(10, 10)); 2229 root->SetContentBounds(gfx::Size(10, 10));
2230 root->SetDrawsContent(true); 2230 root->SetDrawsContent(true);
2231 root->SetOpacity(0.7f); 2231 root->SetOpacity(0.7f);
2232 root->AddChild(child.Pass()); 2232 root->AddChild(child.Pass());
2233 2233
2234 m_hostImpl->activeTree()->SetRootLayer(root.Pass()); 2234 m_hostImpl->active_tree()->SetRootLayer(root.Pass());
2235 2235
2236 LayerTreeHostImpl::FrameData frame; 2236 LayerTreeHostImpl::FrameData frame;
2237 2237
2238 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2238 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2239 EXPECT_EQ(1u, frame.renderSurfaceLayerList->size()); 2239 EXPECT_EQ(1u, frame.render_surface_layer_list->size());
2240 EXPECT_EQ(1u, frame.renderPasses.size()); 2240 EXPECT_EQ(1u, frame.render_passes.size());
2241 m_hostImpl->didDrawAllLayers(frame); 2241 m_hostImpl->DidDrawAllLayers(frame);
2242 } 2242 }
2243 2243
2244 class FakeLayerWithQuads : public LayerImpl { 2244 class FakeLayerWithQuads : public LayerImpl {
2245 public: 2245 public:
2246 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id) { retur n scoped_ptr<LayerImpl>(new FakeLayerWithQuads(treeImpl, id)); } 2246 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* treeImpl, int id) { retur n scoped_ptr<LayerImpl>(new FakeLayerWithQuads(treeImpl, id)); }
2247 2247
2248 virtual void AppendQuads(QuadSink* quadSink, AppendQuadsData* appendQuadsDat a) OVERRIDE 2248 virtual void AppendQuads(QuadSink* quadSink, AppendQuadsData* appendQuadsDat a) OVERRIDE
2249 { 2249 {
2250 SharedQuadState* sharedQuadState = quadSink->useSharedQuadState(CreateSh aredQuadState()); 2250 SharedQuadState* sharedQuadState = quadSink->useSharedQuadState(CreateSh aredQuadState());
2251 2251
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2353 }; 2353 };
2354 2354
2355 TEST_F(LayerTreeHostImplTest, noPartialSwap) 2355 TEST_F(LayerTreeHostImplTest, noPartialSwap)
2356 { 2356 {
2357 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>(); 2357 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>();
2358 MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3 d()); 2358 MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3 d());
2359 MockContextHarness harness(mockContext); 2359 MockContextHarness harness(mockContext);
2360 2360
2361 // Run test case 2361 // Run test case
2362 createLayerTreeHost(false, outputSurface.Pass()); 2362 createLayerTreeHost(false, outputSurface.Pass());
2363 setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->activeTree(), 1)); 2363 setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->active_tree(), 1)) ;
2364 2364
2365 // without partial swap, and no clipping, no scissor is set. 2365 // without partial swap, and no clipping, no scissor is set.
2366 harness.mustDrawSolidQuad(); 2366 harness.mustDrawSolidQuad();
2367 harness.mustSetNoScissor(); 2367 harness.mustSetNoScissor();
2368 { 2368 {
2369 LayerTreeHostImpl::FrameData frame; 2369 LayerTreeHostImpl::FrameData frame;
2370 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2370 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2371 m_hostImpl->drawLayers(frame); 2371 m_hostImpl->DrawLayers(&frame);
2372 m_hostImpl->didDrawAllLayers(frame); 2372 m_hostImpl->DidDrawAllLayers(frame);
2373 } 2373 }
2374 Mock::VerifyAndClearExpectations(&mockContext); 2374 Mock::VerifyAndClearExpectations(&mockContext);
2375 2375
2376 // without partial swap, but a layer does clip its subtree, one scissor is s et. 2376 // without partial swap, but a layer does clip its subtree, one scissor is s et.
2377 m_hostImpl->rootLayer()->SetMasksToBounds(true); 2377 m_hostImpl->active_tree()->root_layer()->SetMasksToBounds(true);
2378 harness.mustDrawSolidQuad(); 2378 harness.mustDrawSolidQuad();
2379 harness.mustSetScissor(0, 0, 10, 10); 2379 harness.mustSetScissor(0, 0, 10, 10);
2380 { 2380 {
2381 LayerTreeHostImpl::FrameData frame; 2381 LayerTreeHostImpl::FrameData frame;
2382 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2382 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2383 m_hostImpl->drawLayers(frame); 2383 m_hostImpl->DrawLayers(&frame);
2384 m_hostImpl->didDrawAllLayers(frame); 2384 m_hostImpl->DidDrawAllLayers(frame);
2385 } 2385 }
2386 Mock::VerifyAndClearExpectations(&mockContext); 2386 Mock::VerifyAndClearExpectations(&mockContext);
2387 } 2387 }
2388 2388
2389 TEST_F(LayerTreeHostImplTest, partialSwap) 2389 TEST_F(LayerTreeHostImplTest, partialSwap)
2390 { 2390 {
2391 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>(); 2391 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>();
2392 MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3 d()); 2392 MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3 d());
2393 MockContextHarness harness(mockContext); 2393 MockContextHarness harness(mockContext);
2394 2394
2395 createLayerTreeHost(true, outputSurface.Pass()); 2395 createLayerTreeHost(true, outputSurface.Pass());
2396 setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->activeTree(), 1)); 2396 setupRootLayerImpl(FakeLayerWithQuads::Create(m_hostImpl->active_tree(), 1)) ;
2397 2397
2398 // The first frame is not a partially-swapped one. 2398 // The first frame is not a partially-swapped one.
2399 harness.mustSetScissor(0, 0, 10, 10); 2399 harness.mustSetScissor(0, 0, 10, 10);
2400 harness.mustDrawSolidQuad(); 2400 harness.mustDrawSolidQuad();
2401 { 2401 {
2402 LayerTreeHostImpl::FrameData frame; 2402 LayerTreeHostImpl::FrameData frame;
2403 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2403 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2404 m_hostImpl->drawLayers(frame); 2404 m_hostImpl->DrawLayers(&frame);
2405 m_hostImpl->didDrawAllLayers(frame); 2405 m_hostImpl->DidDrawAllLayers(frame);
2406 } 2406 }
2407 Mock::VerifyAndClearExpectations(&mockContext); 2407 Mock::VerifyAndClearExpectations(&mockContext);
2408 2408
2409 // Damage a portion of the frame. 2409 // Damage a portion of the frame.
2410 m_hostImpl->rootLayer()->set_update_rect(gfx::Rect(0, 0, 2, 3)); 2410 m_hostImpl->active_tree()->root_layer()->set_update_rect(gfx::Rect(0, 0, 2, 3));
2411 2411
2412 // The second frame will be partially-swapped (the y coordinates are flipped ). 2412 // The second frame will be partially-swapped (the y coordinates are flipped ).
2413 harness.mustSetScissor(0, 7, 2, 3); 2413 harness.mustSetScissor(0, 7, 2, 3);
2414 harness.mustDrawSolidQuad(); 2414 harness.mustDrawSolidQuad();
2415 { 2415 {
2416 LayerTreeHostImpl::FrameData frame; 2416 LayerTreeHostImpl::FrameData frame;
2417 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2417 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2418 m_hostImpl->drawLayers(frame); 2418 m_hostImpl->DrawLayers(&frame);
2419 m_hostImpl->didDrawAllLayers(frame); 2419 m_hostImpl->DidDrawAllLayers(frame);
2420 } 2420 }
2421 Mock::VerifyAndClearExpectations(&mockContext); 2421 Mock::VerifyAndClearExpectations(&mockContext);
2422 } 2422 }
2423 2423
2424 class PartialSwapContext : public TestWebGraphicsContext3D { 2424 class PartialSwapContext : public TestWebGraphicsContext3D {
2425 public: 2425 public:
2426 virtual WebKit::WebString getString(WebKit::WGC3Denum name) 2426 virtual WebKit::WebString getString(WebKit::WGC3Denum name)
2427 { 2427 {
2428 if (name == GL_EXTENSIONS) 2428 if (name == GL_EXTENSIONS)
2429 return WebKit::WebString("GL_CHROMIUM_post_sub_buffer"); 2429 return WebKit::WebString("GL_CHROMIUM_post_sub_buffer");
(...skipping 12 matching lines...) Expand all
2442 *value = 8192; 2442 *value = 8192;
2443 } 2443 }
2444 }; 2444 };
2445 2445
2446 static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, Lay erTreeHostImplClient* client, Proxy* proxy) 2446 static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, Lay erTreeHostImplClient* client, Proxy* proxy)
2447 { 2447 {
2448 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 2448 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
2449 2449
2450 LayerTreeSettings settings; 2450 LayerTreeSettings settings;
2451 settings.partialSwapEnabled = partialSwap; 2451 settings.partialSwapEnabled = partialSwap;
2452 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, client, proxy); 2452 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, client, proxy);
2453 myHostImpl->initializeRenderer(outputSurface.Pass()); 2453 myHostImpl->InitializeRenderer(outputSurface.Pass());
2454 myHostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); 2454 myHostImpl->SetViewportSize(gfx::Size(100, 100), gfx::Size(100, 100));
2455 2455
2456 /* 2456 /*
2457 Layers are created as follows: 2457 Layers are created as follows:
2458 2458
2459 +--------------------+ 2459 +--------------------+
2460 | 1 | 2460 | 1 |
2461 | +-----------+ | 2461 | +-----------+ |
2462 | | 2 | | 2462 | | 2 | |
2463 | | +-------------------+ 2463 | | +-------------------+
2464 | | | 3 | 2464 | | | 3 |
2465 | | +-------------------+ 2465 | | +-------------------+
2466 | | | | 2466 | | | |
2467 | +-----------+ | 2467 | +-----------+ |
2468 | | 2468 | |
2469 | | 2469 | |
2470 +--------------------+ 2470 +--------------------+
2471 2471
2472 Layers 1, 2 have render surfaces 2472 Layers 1, 2 have render surfaces
2473 */ 2473 */
2474 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 2474 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
2475 scoped_ptr<LayerImpl> child = LayerImpl::Create(myHostImpl->activeTree(), 2) ; 2475 scoped_ptr<LayerImpl> child = LayerImpl::Create(myHostImpl->active_tree(), 2 );
2476 scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::Create(myHostImpl->ac tiveTree(), 3); 2476 scoped_ptr<LayerImpl> grandChild = FakeLayerWithQuads::Create(myHostImpl->ac tive_tree(), 3);
2477 2477
2478 gfx::Rect rootRect(0, 0, 100, 100); 2478 gfx::Rect rootRect(0, 0, 100, 100);
2479 gfx::Rect childRect(10, 10, 50, 50); 2479 gfx::Rect childRect(10, 10, 50, 50);
2480 gfx::Rect grandChildRect(5, 5, 150, 150); 2480 gfx::Rect grandChildRect(5, 5, 150, 150);
2481 2481
2482 root->CreateRenderSurface(); 2482 root->CreateRenderSurface();
2483 root->SetAnchorPoint(gfx::PointF(0, 0)); 2483 root->SetAnchorPoint(gfx::PointF(0, 0));
2484 root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y())); 2484 root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y()));
2485 root->SetBounds(gfx::Size(rootRect.width(), rootRect.height())); 2485 root->SetBounds(gfx::Size(rootRect.width(), rootRect.height()));
2486 root->SetContentBounds(root->bounds()); 2486 root->SetContentBounds(root->bounds());
(...skipping 13 matching lines...) Expand all
2500 grandChild->SetAnchorPoint(gfx::PointF(0, 0)); 2500 grandChild->SetAnchorPoint(gfx::PointF(0, 0));
2501 grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y())); 2501 grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y()));
2502 grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.heigh t())); 2502 grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.heigh t()));
2503 grandChild->SetContentBounds(grandChild->bounds()); 2503 grandChild->SetContentBounds(grandChild->bounds());
2504 grandChild->draw_properties().visible_content_rect = grandChildRect; 2504 grandChild->draw_properties().visible_content_rect = grandChildRect;
2505 grandChild->SetDrawsContent(true); 2505 grandChild->SetDrawsContent(true);
2506 2506
2507 child->AddChild(grandChild.Pass()); 2507 child->AddChild(grandChild.Pass());
2508 root->AddChild(child.Pass()); 2508 root->AddChild(child.Pass());
2509 2509
2510 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 2510 myHostImpl->active_tree()->SetRootLayer(root.Pass());
2511 return myHostImpl.Pass(); 2511 return myHostImpl.Pass();
2512 } 2512 }
2513 2513
2514 TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) 2514 TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap)
2515 { 2515 {
2516 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this, &m_proxy); 2516 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this, &m_proxy);
2517 2517
2518 { 2518 {
2519 LayerTreeHostImpl::FrameData frame; 2519 LayerTreeHostImpl::FrameData frame;
2520 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2520 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2521 2521
2522 // Verify all quads have been computed 2522 // Verify all quads have been computed
2523 ASSERT_EQ(2U, frame.renderPasses.size()); 2523 ASSERT_EQ(2U, frame.render_passes.size());
2524 ASSERT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 2524 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size());
2525 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 2525 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size());
2526 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma terial); 2526 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->m aterial);
2527 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 2527 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
2528 2528
2529 myHostImpl->drawLayers(frame); 2529 myHostImpl->DrawLayers(&frame);
2530 myHostImpl->didDrawAllLayers(frame); 2530 myHostImpl->DidDrawAllLayers(frame);
2531 } 2531 }
2532 } 2532 }
2533 2533
2534 TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) 2534 TEST_F(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap)
2535 { 2535 {
2536 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this , &m_proxy); 2536 scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this , &m_proxy);
2537 2537
2538 { 2538 {
2539 LayerTreeHostImpl::FrameData frame; 2539 LayerTreeHostImpl::FrameData frame;
2540 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2540 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2541 2541
2542 // Verify all quads have been computed 2542 // Verify all quads have been computed
2543 ASSERT_EQ(2U, frame.renderPasses.size()); 2543 ASSERT_EQ(2U, frame.render_passes.size());
2544 ASSERT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 2544 ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size());
2545 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 2545 ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size());
2546 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma terial); 2546 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->m aterial);
2547 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 2547 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
2548 2548
2549 myHostImpl->drawLayers(frame); 2549 myHostImpl->DrawLayers(&frame);
2550 myHostImpl->didDrawAllLayers(frame); 2550 myHostImpl->DidDrawAllLayers(frame);
2551 } 2551 }
2552 } 2552 }
2553 2553
2554 // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. 2554 // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use.
2555 class TrackingWebGraphicsContext3D : public TestWebGraphicsContext3D { 2555 class TrackingWebGraphicsContext3D : public TestWebGraphicsContext3D {
2556 public: 2556 public:
2557 TrackingWebGraphicsContext3D() 2557 TrackingWebGraphicsContext3D()
2558 : TestWebGraphicsContext3D() 2558 : TestWebGraphicsContext3D()
2559 , m_numTextures(0) 2559 , m_numTextures(0)
2560 { } 2560 { }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2606 resourceProvider, createResourceId(resourceProvider)).texture_id(); 2606 resourceProvider, createResourceId(resourceProvider)).texture_id();
2607 } 2607 }
2608 2608
2609 TEST_F(LayerTreeHostImplTest, layersFreeTextures) 2609 TEST_F(LayerTreeHostImplTest, layersFreeTextures)
2610 { 2610 {
2611 scoped_ptr<TestWebGraphicsContext3D> context = 2611 scoped_ptr<TestWebGraphicsContext3D> context =
2612 TestWebGraphicsContext3D::Create(); 2612 TestWebGraphicsContext3D::Create();
2613 TestWebGraphicsContext3D* context3d = context.get(); 2613 TestWebGraphicsContext3D* context3d = context.get();
2614 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d( 2614 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(
2615 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); 2615 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
2616 m_hostImpl->initializeRenderer(outputSurface.Pass()); 2616 m_hostImpl->InitializeRenderer(outputSurface.Pass());
2617 2617
2618 scoped_ptr<LayerImpl> rootLayer(LayerImpl::Create(m_hostImpl->activeTree(), 1)); 2618 scoped_ptr<LayerImpl> rootLayer(LayerImpl::Create(m_hostImpl->active_tree(), 1));
2619 rootLayer->SetBounds(gfx::Size(10, 10)); 2619 rootLayer->SetBounds(gfx::Size(10, 10));
2620 rootLayer->SetAnchorPoint(gfx::PointF()); 2620 rootLayer->SetAnchorPoint(gfx::PointF());
2621 2621
2622 scoped_refptr<VideoFrame> softwareFrame(media::VideoFrame::CreateColorFrame( 2622 scoped_refptr<VideoFrame> softwareFrame(media::VideoFrame::CreateColorFrame(
2623 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta())); 2623 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()));
2624 FakeVideoFrameProvider provider; 2624 FakeVideoFrameProvider provider;
2625 provider.set_frame(softwareFrame); 2625 provider.set_frame(softwareFrame);
2626 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::Create(m_hostImpl->a ctiveTree(), 4, &provider); 2626 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::Create(m_hostImpl->a ctive_tree(), 4, &provider);
2627 videoLayer->SetBounds(gfx::Size(10, 10)); 2627 videoLayer->SetBounds(gfx::Size(10, 10));
2628 videoLayer->SetAnchorPoint(gfx::PointF(0, 0)); 2628 videoLayer->SetAnchorPoint(gfx::PointF(0, 0));
2629 videoLayer->SetContentBounds(gfx::Size(10, 10)); 2629 videoLayer->SetContentBounds(gfx::Size(10, 10));
2630 videoLayer->SetDrawsContent(true); 2630 videoLayer->SetDrawsContent(true);
2631 rootLayer->AddChild(videoLayer.PassAs<LayerImpl>()); 2631 rootLayer->AddChild(videoLayer.PassAs<LayerImpl>());
2632 2632
2633 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::Create(m _hostImpl->activeTree(), 5); 2633 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::Create(m _hostImpl->active_tree(), 5);
2634 ioSurfaceLayer->SetBounds(gfx::Size(10, 10)); 2634 ioSurfaceLayer->SetBounds(gfx::Size(10, 10));
2635 ioSurfaceLayer->SetAnchorPoint(gfx::PointF(0, 0)); 2635 ioSurfaceLayer->SetAnchorPoint(gfx::PointF(0, 0));
2636 ioSurfaceLayer->SetContentBounds(gfx::Size(10, 10)); 2636 ioSurfaceLayer->SetContentBounds(gfx::Size(10, 10));
2637 ioSurfaceLayer->SetDrawsContent(true); 2637 ioSurfaceLayer->SetDrawsContent(true);
2638 ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); 2638 ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10));
2639 rootLayer->AddChild(ioSurfaceLayer.PassAs<LayerImpl>()); 2639 rootLayer->AddChild(ioSurfaceLayer.PassAs<LayerImpl>());
2640 2640
2641 m_hostImpl->activeTree()->SetRootLayer(rootLayer.Pass()); 2641 m_hostImpl->active_tree()->SetRootLayer(rootLayer.Pass());
2642 2642
2643 EXPECT_EQ(0u, context3d->NumTextures()); 2643 EXPECT_EQ(0u, context3d->NumTextures());
2644 2644
2645 LayerTreeHostImpl::FrameData frame; 2645 LayerTreeHostImpl::FrameData frame;
2646 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2646 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2647 m_hostImpl->drawLayers(frame); 2647 m_hostImpl->DrawLayers(&frame);
2648 m_hostImpl->didDrawAllLayers(frame); 2648 m_hostImpl->DidDrawAllLayers(frame);
2649 m_hostImpl->swapBuffers(); 2649 m_hostImpl->SwapBuffers();
2650 2650
2651 EXPECT_GT(context3d->NumTextures(), 0u); 2651 EXPECT_GT(context3d->NumTextures(), 0u);
2652 2652
2653 // Kill the layer tree. 2653 // Kill the layer tree.
2654 m_hostImpl->activeTree()->SetRootLayer(LayerImpl::Create(m_hostImpl->activeT ree(), 100)); 2654 m_hostImpl->active_tree()->SetRootLayer(LayerImpl::Create(m_hostImpl->active _tree(), 100));
2655 // There should be no textures left in use after. 2655 // There should be no textures left in use after.
2656 EXPECT_EQ(0u, context3d->NumTextures()); 2656 EXPECT_EQ(0u, context3d->NumTextures());
2657 } 2657 }
2658 2658
2659 class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D { 2659 class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D {
2660 public: 2660 public:
2661 MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); 2661 MOCK_METHOD1(useProgram, void(WebKit::WebGLId program));
2662 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei c ount, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); 2662 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei c ount, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset));
2663 }; 2663 };
2664 2664
2665 TEST_F(LayerTreeHostImplTest, hasTransparentBackground) 2665 TEST_F(LayerTreeHostImplTest, hasTransparentBackground)
2666 { 2666 {
2667 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext)).PassAs <OutputSurface>(); 2667 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext)).PassAs <OutputSurface>();
2668 MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToF illScreenContext*>(outputSurface->context3d()); 2668 MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToF illScreenContext*>(outputSurface->context3d());
2669 2669
2670 // Run test case 2670 // Run test case
2671 createLayerTreeHost(false, outputSurface.Pass()); 2671 createLayerTreeHost(false, outputSurface.Pass());
2672 setupRootLayerImpl(LayerImpl::Create(m_hostImpl->activeTree(), 1)); 2672 setupRootLayerImpl(LayerImpl::Create(m_hostImpl->active_tree(), 1));
2673 m_hostImpl->activeTree()->set_background_color(SK_ColorWHITE); 2673 m_hostImpl->active_tree()->set_background_color(SK_ColorWHITE);
2674 2674
2675 // Verify one quad is drawn when transparent background set is not set. 2675 // Verify one quad is drawn when transparent background set is not set.
2676 m_hostImpl->activeTree()->set_has_transparent_background(false); 2676 m_hostImpl->active_tree()->set_has_transparent_background(false);
2677 EXPECT_CALL(*mockContext, useProgram(_)) 2677 EXPECT_CALL(*mockContext, useProgram(_))
2678 .Times(1); 2678 .Times(1);
2679 EXPECT_CALL(*mockContext, drawElements(_, _, _, _)) 2679 EXPECT_CALL(*mockContext, drawElements(_, _, _, _))
2680 .Times(1); 2680 .Times(1);
2681 LayerTreeHostImpl::FrameData frame; 2681 LayerTreeHostImpl::FrameData frame;
2682 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2682 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2683 m_hostImpl->drawLayers(frame); 2683 m_hostImpl->DrawLayers(&frame);
2684 m_hostImpl->didDrawAllLayers(frame); 2684 m_hostImpl->DidDrawAllLayers(frame);
2685 Mock::VerifyAndClearExpectations(&mockContext); 2685 Mock::VerifyAndClearExpectations(&mockContext);
2686 2686
2687 // Verify no quads are drawn when transparent background is set. 2687 // Verify no quads are drawn when transparent background is set.
2688 m_hostImpl->activeTree()->set_has_transparent_background(true); 2688 m_hostImpl->active_tree()->set_has_transparent_background(true);
2689 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 2689 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
2690 m_hostImpl->drawLayers(frame); 2690 m_hostImpl->DrawLayers(&frame);
2691 m_hostImpl->didDrawAllLayers(frame); 2691 m_hostImpl->DidDrawAllLayers(frame);
2692 Mock::VerifyAndClearExpectations(&mockContext); 2692 Mock::VerifyAndClearExpectations(&mockContext);
2693 } 2693 }
2694 2694
2695 static void addDrawingLayerTo(LayerImpl* parent, int id, const gfx::Rect& layerR ect, LayerImpl** result) 2695 static void addDrawingLayerTo(LayerImpl* parent, int id, const gfx::Rect& layerR ect, LayerImpl** result)
2696 { 2696 {
2697 scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::Create(parent->layer_tree_ impl(), id); 2697 scoped_ptr<LayerImpl> layer = FakeLayerWithQuads::Create(parent->layer_tree_ impl(), id);
2698 LayerImpl* layerPtr = layer.get(); 2698 LayerImpl* layerPtr = layer.get();
2699 layerPtr->SetAnchorPoint(gfx::PointF(0, 0)); 2699 layerPtr->SetAnchorPoint(gfx::PointF(0, 0));
2700 layerPtr->SetPosition(gfx::PointF(layerRect.origin())); 2700 layerPtr->SetPosition(gfx::PointF(layerRect.origin()));
2701 layerPtr->SetBounds(layerRect.size()); 2701 layerPtr->SetBounds(layerRect.size());
2702 layerPtr->SetContentBounds(layerRect.size()); 2702 layerPtr->SetContentBounds(layerRect.size());
2703 layerPtr->SetDrawsContent(true); // only children draw content 2703 layerPtr->SetDrawsContent(true); // only children draw content
2704 layerPtr->SetContentsOpaque(true); 2704 layerPtr->SetContentsOpaque(true);
2705 parent->AddChild(layer.Pass()); 2705 parent->AddChild(layer.Pass());
2706 if (result) 2706 if (result)
2707 *result = layerPtr; 2707 *result = layerPtr;
2708 } 2708 }
2709 2709
2710 static void setupLayersForTextureCaching(LayerTreeHostImpl* layerTreeHostImpl, L ayerImpl*& rootPtr, LayerImpl*& intermediateLayerPtr, LayerImpl*& surfaceLayerPt r, LayerImpl*& childPtr, const gfx::Size& rootSize) 2710 static void setupLayersForTextureCaching(LayerTreeHostImpl* layerTreeHostImpl, L ayerImpl*& rootPtr, LayerImpl*& intermediateLayerPtr, LayerImpl*& surfaceLayerPt r, LayerImpl*& childPtr, const gfx::Size& rootSize)
2711 { 2711 {
2712 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 2712 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
2713 2713
2714 layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); 2714 layerTreeHostImpl->InitializeRenderer(outputSurface.Pass());
2715 layerTreeHostImpl->setViewportSize(rootSize, rootSize); 2715 layerTreeHostImpl->SetViewportSize(rootSize, rootSize);
2716 2716
2717 scoped_ptr<LayerImpl> root = LayerImpl::Create(layerTreeHostImpl->activeTree (), 1); 2717 scoped_ptr<LayerImpl> root = LayerImpl::Create(layerTreeHostImpl->active_tre e(), 1);
2718 rootPtr = root.get(); 2718 rootPtr = root.get();
2719 2719
2720 root->SetAnchorPoint(gfx::PointF(0, 0)); 2720 root->SetAnchorPoint(gfx::PointF(0, 0));
2721 root->SetPosition(gfx::PointF(0, 0)); 2721 root->SetPosition(gfx::PointF(0, 0));
2722 root->SetBounds(rootSize); 2722 root->SetBounds(rootSize);
2723 root->SetContentBounds(rootSize); 2723 root->SetContentBounds(rootSize);
2724 root->SetDrawsContent(true); 2724 root->SetDrawsContent(true);
2725 layerTreeHostImpl->activeTree()->SetRootLayer(root.Pass()); 2725 layerTreeHostImpl->active_tree()->SetRootLayer(root.Pass());
2726 2726
2727 addDrawingLayerTo(rootPtr, 2, gfx::Rect(10, 10, rootSize.width(), rootSize.h eight()), &intermediateLayerPtr); 2727 addDrawingLayerTo(rootPtr, 2, gfx::Rect(10, 10, rootSize.width(), rootSize.h eight()), &intermediateLayerPtr);
2728 intermediateLayerPtr->SetDrawsContent(false); // only children draw content 2728 intermediateLayerPtr->SetDrawsContent(false); // only children draw content
2729 2729
2730 // Surface layer is the layer that changes its opacity 2730 // Surface layer is the layer that changes its opacity
2731 // It will contain other layers that draw content. 2731 // It will contain other layers that draw content.
2732 addDrawingLayerTo(intermediateLayerPtr, 3, gfx::Rect(10, 10, rootSize.width( ), rootSize.height()), &surfaceLayerPtr); 2732 addDrawingLayerTo(intermediateLayerPtr, 3, gfx::Rect(10, 10, rootSize.width( ), rootSize.height()), &surfaceLayerPtr);
2733 surfaceLayerPtr->SetDrawsContent(false); // only children draw content 2733 surfaceLayerPtr->SetDrawsContent(false); // only children draw content
2734 surfaceLayerPtr->SetOpacity(0.5f); 2734 surfaceLayerPtr->SetOpacity(0.5f);
2735 surfaceLayerPtr->SetForceRenderSurface(true); // This will cause it to have a surface 2735 surfaceLayerPtr->SetForceRenderSurface(true); // This will cause it to have a surface
2736 2736
2737 // Child of the surface layer will produce some quads 2737 // Child of the surface layer will produce some quads
2738 addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(5, 5, rootSize.width() - 25, rootSize.height() - 25), &childPtr); 2738 addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(5, 5, rootSize.width() - 25, rootSize.height() - 25), &childPtr);
2739 } 2739 }
2740 2740
2741 class GLRendererWithReleaseTextures : public GLRenderer { 2741 class GLRendererWithReleaseTextures : public GLRenderer {
2742 public: 2742 public:
2743 using GLRenderer::ReleaseRenderPassTextures; 2743 using GLRenderer::ReleaseRenderPassTextures;
2744 }; 2744 };
2745 2745
2746 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusion) 2746 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusion)
2747 { 2747 {
2748 LayerTreeSettings settings; 2748 LayerTreeSettings settings;
2749 settings.minimumOcclusionTrackingSize = gfx::Size(); 2749 settings.minimumOcclusionTrackingSize = gfx::Size();
2750 settings.cacheRenderPassContents = true; 2750 settings.cacheRenderPassContents = true;
2751 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 2751 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
2752 2752
2753 // Layers are structure as follows: 2753 // Layers are structure as follows:
2754 // 2754 //
2755 // R +-- S1 +- L10 (owning) 2755 // R +-- S1 +- L10 (owning)
2756 // | +- L11 2756 // | +- L11
2757 // | +- L12 2757 // | +- L12
2758 // | 2758 // |
2759 // +-- S2 +- L20 (owning) 2759 // +-- S2 +- L20 (owning)
2760 // +- L21 2760 // +- L21
2761 // 2761 //
2762 // Occlusion: 2762 // Occlusion:
2763 // L12 occludes L11 (internal) 2763 // L12 occludes L11 (internal)
2764 // L20 occludes L10 (external) 2764 // L20 occludes L10 (external)
2765 // L21 occludes L20 (internal) 2765 // L21 occludes L20 (internal)
2766 2766
2767 LayerImpl* rootPtr; 2767 LayerImpl* rootPtr;
2768 LayerImpl* layerS1Ptr; 2768 LayerImpl* layerS1Ptr;
2769 LayerImpl* layerS2Ptr; 2769 LayerImpl* layerS2Ptr;
2770 2770
2771 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 2771 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
2772 2772
2773 gfx::Size rootSize(1000, 1000); 2773 gfx::Size rootSize(1000, 1000);
2774 2774
2775 myHostImpl->initializeRenderer(outputSurface.Pass()); 2775 myHostImpl->InitializeRenderer(outputSurface.Pass());
2776 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); 2776 myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height()));
2777 2777
2778 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 2778 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
2779 rootPtr = root.get(); 2779 rootPtr = root.get();
2780 2780
2781 root->SetAnchorPoint(gfx::PointF(0, 0)); 2781 root->SetAnchorPoint(gfx::PointF(0, 0));
2782 root->SetPosition(gfx::PointF(0, 0)); 2782 root->SetPosition(gfx::PointF(0, 0));
2783 root->SetBounds(rootSize); 2783 root->SetBounds(rootSize);
2784 root->SetContentBounds(rootSize); 2784 root->SetContentBounds(rootSize);
2785 root->SetDrawsContent(true); 2785 root->SetDrawsContent(true);
2786 root->SetMasksToBounds(true); 2786 root->SetMasksToBounds(true);
2787 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 2787 myHostImpl->active_tree()->SetRootLayer(root.Pass());
2788 2788
2789 addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr); 2789 addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr);
2790 layerS1Ptr->SetForceRenderSurface(true); 2790 layerS1Ptr->SetForceRenderSurface(true);
2791 2791
2792 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11 2792 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11
2793 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 2793 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12
2794 2794
2795 addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr); 2795 addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr);
2796 layerS2Ptr->SetForceRenderSurface(true); 2796 layerS2Ptr->SetForceRenderSurface(true);
2797 2797
2798 addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 2798 addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21
2799 2799
2800 // Initial draw - must receive all quads 2800 // Initial draw - must receive all quads
2801 { 2801 {
2802 LayerTreeHostImpl::FrameData frame; 2802 LayerTreeHostImpl::FrameData frame;
2803 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2803 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2804 2804
2805 // Must receive 3 render passes. 2805 // Must receive 3 render passes.
2806 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded ); for S2, there is 2 quads. 2806 // For Root, there are 2 quads; for S1, there are 2 quads (1 is occluded ); for S2, there is 2 quads.
2807 ASSERT_EQ(3U, frame.renderPasses.size()); 2807 ASSERT_EQ(3U, frame.render_passes.size());
2808 2808
2809 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 2809 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
2810 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 2810 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
2811 EXPECT_EQ(2U, frame.renderPasses[2]->quad_list.size()); 2811 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
2812 2812
2813 myHostImpl->drawLayers(frame); 2813 myHostImpl->DrawLayers(&frame);
2814 myHostImpl->didDrawAllLayers(frame); 2814 myHostImpl->DidDrawAllLayers(frame);
2815 } 2815 }
2816 2816
2817 // "Unocclude" surface S1 and repeat draw. 2817 // "Unocclude" surface S1 and repeat draw.
2818 // Must remove S2's render pass since it's cached; 2818 // Must remove S2's render pass since it's cached;
2819 // Must keep S1 quads because texture contained external occlusion. 2819 // Must keep S1 quads because texture contained external occlusion.
2820 gfx::Transform transform = layerS2Ptr->transform(); 2820 gfx::Transform transform = layerS2Ptr->transform();
2821 transform.Translate(150, 150); 2821 transform.Translate(150, 150);
2822 layerS2Ptr->SetTransform(transform); 2822 layerS2Ptr->SetTransform(transform);
2823 { 2823 {
2824 LayerTreeHostImpl::FrameData frame; 2824 LayerTreeHostImpl::FrameData frame;
2825 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2825 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2826 2826
2827 // Must receive 2 render passes. 2827 // Must receive 2 render passes.
2828 // For Root, there are 2 quads 2828 // For Root, there are 2 quads
2829 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive. 2829 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive.
2830 // For S2, there is no render pass 2830 // For S2, there is no render pass
2831 ASSERT_EQ(2U, frame.renderPasses.size()); 2831 ASSERT_EQ(2U, frame.render_passes.size());
2832 2832
2833 EXPECT_GT(frame.renderPasses[0]->quad_list.size(), 0U); 2833 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
2834 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 2834 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
2835 2835
2836 myHostImpl->drawLayers(frame); 2836 myHostImpl->DrawLayers(&frame);
2837 myHostImpl->didDrawAllLayers(frame); 2837 myHostImpl->DidDrawAllLayers(frame);
2838 } 2838 }
2839 2839
2840 // "Re-occlude" surface S1 and repeat draw. 2840 // "Re-occlude" surface S1 and repeat draw.
2841 // Must remove S1's render pass since it is now available in full. 2841 // Must remove S1's render pass since it is now available in full.
2842 // S2 has no change so must also be removed. 2842 // S2 has no change so must also be removed.
2843 transform = layerS2Ptr->transform(); 2843 transform = layerS2Ptr->transform();
2844 transform.Translate(-15, -15); 2844 transform.Translate(-15, -15);
2845 layerS2Ptr->SetTransform(transform); 2845 layerS2Ptr->SetTransform(transform);
2846 { 2846 {
2847 LayerTreeHostImpl::FrameData frame; 2847 LayerTreeHostImpl::FrameData frame;
2848 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2848 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2849 2849
2850 // Must receive 1 render pass - for the root. 2850 // Must receive 1 render pass - for the root.
2851 ASSERT_EQ(1U, frame.renderPasses.size()); 2851 ASSERT_EQ(1U, frame.render_passes.size());
2852 2852
2853 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 2853 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
2854 2854
2855 myHostImpl->drawLayers(frame); 2855 myHostImpl->DrawLayers(&frame);
2856 myHostImpl->didDrawAllLayers(frame); 2856 myHostImpl->DidDrawAllLayers(frame);
2857 } 2857 }
2858 2858
2859 } 2859 }
2860 2860
2861 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) 2861 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut)
2862 { 2862 {
2863 LayerTreeSettings settings; 2863 LayerTreeSettings settings;
2864 settings.minimumOcclusionTrackingSize = gfx::Size(); 2864 settings.minimumOcclusionTrackingSize = gfx::Size();
2865 settings.cacheRenderPassContents = true; 2865 settings.cacheRenderPassContents = true;
2866 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 2866 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
2867 2867
2868 // Layers are structure as follows: 2868 // Layers are structure as follows:
2869 // 2869 //
2870 // R +-- S1 +- L10 (owning, non drawing) 2870 // R +-- S1 +- L10 (owning, non drawing)
2871 // | +- L11 (corner, unoccluded) 2871 // | +- L11 (corner, unoccluded)
2872 // | +- L12 (corner, unoccluded) 2872 // | +- L12 (corner, unoccluded)
2873 // | +- L13 (corner, unoccluded) 2873 // | +- L13 (corner, unoccluded)
2874 // | +- L14 (corner, entirely occluded) 2874 // | +- L14 (corner, entirely occluded)
2875 // | 2875 // |
2876 // +-- S2 +- L20 (owning, drawing) 2876 // +-- S2 +- L20 (owning, drawing)
2877 // 2877 //
2878 2878
2879 LayerImpl* rootPtr; 2879 LayerImpl* rootPtr;
2880 LayerImpl* layerS1Ptr; 2880 LayerImpl* layerS1Ptr;
2881 LayerImpl* layerS2Ptr; 2881 LayerImpl* layerS2Ptr;
2882 2882
2883 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 2883 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
2884 2884
2885 gfx::Size rootSize(1000, 1000); 2885 gfx::Size rootSize(1000, 1000);
2886 2886
2887 myHostImpl->initializeRenderer(outputSurface.Pass()); 2887 myHostImpl->InitializeRenderer(outputSurface.Pass());
2888 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); 2888 myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height()));
2889 2889
2890 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 2890 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
2891 rootPtr = root.get(); 2891 rootPtr = root.get();
2892 2892
2893 root->SetAnchorPoint(gfx::PointF(0, 0)); 2893 root->SetAnchorPoint(gfx::PointF(0, 0));
2894 root->SetPosition(gfx::PointF(0, 0)); 2894 root->SetPosition(gfx::PointF(0, 0));
2895 root->SetBounds(rootSize); 2895 root->SetBounds(rootSize);
2896 root->SetContentBounds(rootSize); 2896 root->SetContentBounds(rootSize);
2897 root->SetDrawsContent(true); 2897 root->SetDrawsContent(true);
2898 root->SetMasksToBounds(true); 2898 root->SetMasksToBounds(true);
2899 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 2899 myHostImpl->active_tree()->SetRootLayer(root.Pass());
2900 2900
2901 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 800, 800), &layerS1Ptr); 2901 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 800, 800), &layerS1Ptr);
2902 layerS1Ptr->SetForceRenderSurface(true); 2902 layerS1Ptr->SetForceRenderSurface(true);
2903 layerS1Ptr->SetDrawsContent(false); 2903 layerS1Ptr->SetDrawsContent(false);
2904 2904
2905 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11 2905 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11
2906 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 500, 300, 300), 0); // L12 2906 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 500, 300, 300), 0); // L12
2907 addDrawingLayerTo(layerS1Ptr, 5, gfx::Rect(500, 0, 300, 300), 0); // L13 2907 addDrawingLayerTo(layerS1Ptr, 5, gfx::Rect(500, 0, 300, 300), 0); // L13
2908 addDrawingLayerTo(layerS1Ptr, 6, gfx::Rect(500, 500, 300, 300), 0); // L14 2908 addDrawingLayerTo(layerS1Ptr, 6, gfx::Rect(500, 500, 300, 300), 0); // L14
2909 addDrawingLayerTo(layerS1Ptr, 9, gfx::Rect(500, 500, 300, 300), 0); // L14 2909 addDrawingLayerTo(layerS1Ptr, 9, gfx::Rect(500, 500, 300, 300), 0); // L14
2910 2910
2911 addDrawingLayerTo(rootPtr, 7, gfx::Rect(450, 450, 450, 450), &layerS2Ptr); 2911 addDrawingLayerTo(rootPtr, 7, gfx::Rect(450, 450, 450, 450), &layerS2Ptr);
2912 layerS2Ptr->SetForceRenderSurface(true); 2912 layerS2Ptr->SetForceRenderSurface(true);
2913 2913
2914 // Initial draw - must receive all quads 2914 // Initial draw - must receive all quads
2915 { 2915 {
2916 LayerTreeHostImpl::FrameData frame; 2916 LayerTreeHostImpl::FrameData frame;
2917 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2917 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2918 2918
2919 // Must receive 3 render passes. 2919 // Must receive 3 render passes.
2920 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad. 2920 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad.
2921 ASSERT_EQ(3U, frame.renderPasses.size()); 2921 ASSERT_EQ(3U, frame.render_passes.size());
2922 2922
2923 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 2923 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
2924 2924
2925 // L14 is culled, so only 3 quads. 2925 // L14 is culled, so only 3 quads.
2926 EXPECT_EQ(3U, frame.renderPasses[1]->quad_list.size()); 2926 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size());
2927 EXPECT_EQ(2U, frame.renderPasses[2]->quad_list.size()); 2927 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
2928 2928
2929 myHostImpl->drawLayers(frame); 2929 myHostImpl->DrawLayers(&frame);
2930 myHostImpl->didDrawAllLayers(frame); 2930 myHostImpl->DidDrawAllLayers(frame);
2931 } 2931 }
2932 2932
2933 // "Unocclude" surface S1 and repeat draw. 2933 // "Unocclude" surface S1 and repeat draw.
2934 // Must remove S2's render pass since it's cached; 2934 // Must remove S2's render pass since it's cached;
2935 // Must keep S1 quads because texture contained external occlusion. 2935 // Must keep S1 quads because texture contained external occlusion.
2936 gfx::Transform transform = layerS2Ptr->transform(); 2936 gfx::Transform transform = layerS2Ptr->transform();
2937 transform.Translate(100, 100); 2937 transform.Translate(100, 100);
2938 layerS2Ptr->SetTransform(transform); 2938 layerS2Ptr->SetTransform(transform);
2939 { 2939 {
2940 LayerTreeHostImpl::FrameData frame; 2940 LayerTreeHostImpl::FrameData frame;
2941 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2941 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2942 2942
2943 // Must receive 2 render passes. 2943 // Must receive 2 render passes.
2944 // For Root, there are 2 quads 2944 // For Root, there are 2 quads
2945 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive. 2945 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive.
2946 // For S2, there is no render pass 2946 // For S2, there is no render pass
2947 ASSERT_EQ(2U, frame.renderPasses.size()); 2947 ASSERT_EQ(2U, frame.render_passes.size());
2948 2948
2949 EXPECT_GT(frame.renderPasses[0]->quad_list.size(), 0U); 2949 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
2950 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 2950 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
2951 2951
2952 myHostImpl->drawLayers(frame); 2952 myHostImpl->DrawLayers(&frame);
2953 myHostImpl->didDrawAllLayers(frame); 2953 myHostImpl->DidDrawAllLayers(frame);
2954 } 2954 }
2955 2955
2956 // "Re-occlude" surface S1 and repeat draw. 2956 // "Re-occlude" surface S1 and repeat draw.
2957 // Must remove S1's render pass since it is now available in full. 2957 // Must remove S1's render pass since it is now available in full.
2958 // S2 has no change so must also be removed. 2958 // S2 has no change so must also be removed.
2959 transform = layerS2Ptr->transform(); 2959 transform = layerS2Ptr->transform();
2960 transform.Translate(-15, -15); 2960 transform.Translate(-15, -15);
2961 layerS2Ptr->SetTransform(transform); 2961 layerS2Ptr->SetTransform(transform);
2962 { 2962 {
2963 LayerTreeHostImpl::FrameData frame; 2963 LayerTreeHostImpl::FrameData frame;
2964 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 2964 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
2965 2965
2966 // Must receive 1 render pass - for the root. 2966 // Must receive 1 render pass - for the root.
2967 ASSERT_EQ(1U, frame.renderPasses.size()); 2967 ASSERT_EQ(1U, frame.render_passes.size());
2968 2968
2969 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 2969 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
2970 2970
2971 myHostImpl->drawLayers(frame); 2971 myHostImpl->DrawLayers(&frame);
2972 myHostImpl->didDrawAllLayers(frame); 2972 myHostImpl->DidDrawAllLayers(frame);
2973 } 2973 }
2974 } 2974 }
2975 2975
2976 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) 2976 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal)
2977 { 2977 {
2978 LayerTreeSettings settings; 2978 LayerTreeSettings settings;
2979 settings.minimumOcclusionTrackingSize = gfx::Size(); 2979 settings.minimumOcclusionTrackingSize = gfx::Size();
2980 settings.cacheRenderPassContents = true; 2980 settings.cacheRenderPassContents = true;
2981 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 2981 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
2982 2982
2983 // Layers are structured as follows: 2983 // Layers are structured as follows:
2984 // 2984 //
2985 // R +-- S1 +- L10 (owning, drawing) 2985 // R +-- S1 +- L10 (owning, drawing)
2986 // | +- L11 (corner, occluded by L12) 2986 // | +- L11 (corner, occluded by L12)
2987 // | +- L12 (opposite corner) 2987 // | +- L12 (opposite corner)
2988 // | 2988 // |
2989 // +-- S2 +- L20 (owning, drawing) 2989 // +-- S2 +- L20 (owning, drawing)
2990 // 2990 //
2991 2991
2992 LayerImpl* rootPtr; 2992 LayerImpl* rootPtr;
2993 LayerImpl* layerS1Ptr; 2993 LayerImpl* layerS1Ptr;
2994 LayerImpl* layerS2Ptr; 2994 LayerImpl* layerS2Ptr;
2995 2995
2996 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 2996 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
2997 2997
2998 gfx::Size rootSize(1000, 1000); 2998 gfx::Size rootSize(1000, 1000);
2999 2999
3000 myHostImpl->initializeRenderer(outputSurface.Pass()); 3000 myHostImpl->InitializeRenderer(outputSurface.Pass());
3001 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); 3001 myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height()));
3002 3002
3003 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 3003 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
3004 rootPtr = root.get(); 3004 rootPtr = root.get();
3005 3005
3006 root->SetAnchorPoint(gfx::PointF(0, 0)); 3006 root->SetAnchorPoint(gfx::PointF(0, 0));
3007 root->SetPosition(gfx::PointF(0, 0)); 3007 root->SetPosition(gfx::PointF(0, 0));
3008 root->SetBounds(rootSize); 3008 root->SetBounds(rootSize);
3009 root->SetContentBounds(rootSize); 3009 root->SetContentBounds(rootSize);
3010 root->SetDrawsContent(true); 3010 root->SetDrawsContent(true);
3011 root->SetMasksToBounds(true); 3011 root->SetMasksToBounds(true);
3012 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 3012 myHostImpl->active_tree()->SetRootLayer(root.Pass());
3013 3013
3014 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr); 3014 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr);
3015 layerS1Ptr->SetForceRenderSurface(true); 3015 layerS1Ptr->SetForceRenderSurface(true);
3016 3016
3017 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11 3017 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(0, 0, 300, 300), 0); // L11
3018 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(100, 0, 300, 300), 0); // L12 3018 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(100, 0, 300, 300), 0); // L12
3019 3019
3020 addDrawingLayerTo(rootPtr, 7, gfx::Rect(200, 0, 300, 300), &layerS2Ptr); 3020 addDrawingLayerTo(rootPtr, 7, gfx::Rect(200, 0, 300, 300), &layerS2Ptr);
3021 layerS2Ptr->SetForceRenderSurface(true); 3021 layerS2Ptr->SetForceRenderSurface(true);
3022 3022
3023 // Initial draw - must receive all quads 3023 // Initial draw - must receive all quads
3024 { 3024 {
3025 LayerTreeHostImpl::FrameData frame; 3025 LayerTreeHostImpl::FrameData frame;
3026 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3026 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3027 3027
3028 // Must receive 3 render passes. 3028 // Must receive 3 render passes.
3029 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad. 3029 // For Root, there are 2 quads; for S1, there are 3 quads; for S2, there is 1 quad.
3030 ASSERT_EQ(3U, frame.renderPasses.size()); 3030 ASSERT_EQ(3U, frame.render_passes.size());
3031 3031
3032 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3032 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3033 EXPECT_EQ(3U, frame.renderPasses[1]->quad_list.size()); 3033 EXPECT_EQ(3U, frame.render_passes[1]->quad_list.size());
3034 EXPECT_EQ(2U, frame.renderPasses[2]->quad_list.size()); 3034 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3035 3035
3036 myHostImpl->drawLayers(frame); 3036 myHostImpl->DrawLayers(&frame);
3037 myHostImpl->didDrawAllLayers(frame); 3037 myHostImpl->DidDrawAllLayers(frame);
3038 } 3038 }
3039 3039
3040 // "Unocclude" surface S1 and repeat draw. 3040 // "Unocclude" surface S1 and repeat draw.
3041 // Must remove S2's render pass since it's cached; 3041 // Must remove S2's render pass since it's cached;
3042 // Must keep S1 quads because texture contained external occlusion. 3042 // Must keep S1 quads because texture contained external occlusion.
3043 gfx::Transform transform = layerS2Ptr->transform(); 3043 gfx::Transform transform = layerS2Ptr->transform();
3044 transform.Translate(300, 0); 3044 transform.Translate(300, 0);
3045 layerS2Ptr->SetTransform(transform); 3045 layerS2Ptr->SetTransform(transform);
3046 { 3046 {
3047 LayerTreeHostImpl::FrameData frame; 3047 LayerTreeHostImpl::FrameData frame;
3048 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3048 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3049 3049
3050 // Must receive 2 render passes. 3050 // Must receive 2 render passes.
3051 // For Root, there are 2 quads 3051 // For Root, there are 2 quads
3052 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive. 3052 // For S1, the number of quads depends on what got unoccluded, so not as serted beyond being positive.
3053 // For S2, there is no render pass 3053 // For S2, there is no render pass
3054 ASSERT_EQ(2U, frame.renderPasses.size()); 3054 ASSERT_EQ(2U, frame.render_passes.size());
3055 3055
3056 EXPECT_GT(frame.renderPasses[0]->quad_list.size(), 0U); 3056 EXPECT_GT(frame.render_passes[0]->quad_list.size(), 0U);
3057 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 3057 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3058 3058
3059 myHostImpl->drawLayers(frame); 3059 myHostImpl->DrawLayers(&frame);
3060 myHostImpl->didDrawAllLayers(frame); 3060 myHostImpl->DidDrawAllLayers(frame);
3061 } 3061 }
3062 } 3062 }
3063 3063
3064 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) 3064 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned)
3065 { 3065 {
3066 LayerTreeSettings settings; 3066 LayerTreeSettings settings;
3067 settings.cacheRenderPassContents = true; 3067 settings.cacheRenderPassContents = true;
3068 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 3068 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
3069 3069
3070 // Layers are structured as follows: 3070 // Layers are structured as follows:
3071 // 3071 //
3072 // R +-- S1 +- L10 (rotated, drawing) 3072 // R +-- S1 +- L10 (rotated, drawing)
3073 // +- L11 (occupies half surface) 3073 // +- L11 (occupies half surface)
3074 3074
3075 LayerImpl* rootPtr; 3075 LayerImpl* rootPtr;
3076 LayerImpl* layerS1Ptr; 3076 LayerImpl* layerS1Ptr;
3077 3077
3078 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 3078 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
3079 3079
3080 gfx::Size rootSize(1000, 1000); 3080 gfx::Size rootSize(1000, 1000);
3081 3081
3082 myHostImpl->initializeRenderer(outputSurface.Pass()); 3082 myHostImpl->InitializeRenderer(outputSurface.Pass());
3083 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); 3083 myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height()));
3084 3084
3085 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 3085 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
3086 rootPtr = root.get(); 3086 rootPtr = root.get();
3087 3087
3088 root->SetAnchorPoint(gfx::PointF(0, 0)); 3088 root->SetAnchorPoint(gfx::PointF(0, 0));
3089 root->SetPosition(gfx::PointF(0, 0)); 3089 root->SetPosition(gfx::PointF(0, 0));
3090 root->SetBounds(rootSize); 3090 root->SetBounds(rootSize);
3091 root->SetContentBounds(rootSize); 3091 root->SetContentBounds(rootSize);
3092 root->SetDrawsContent(true); 3092 root->SetDrawsContent(true);
3093 root->SetMasksToBounds(true); 3093 root->SetMasksToBounds(true);
3094 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 3094 myHostImpl->active_tree()->SetRootLayer(root.Pass());
3095 3095
3096 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr); 3096 addDrawingLayerTo(rootPtr, 2, gfx::Rect(0, 0, 400, 400), &layerS1Ptr);
3097 layerS1Ptr->SetForceRenderSurface(true); 3097 layerS1Ptr->SetForceRenderSurface(true);
3098 gfx::Transform transform = layerS1Ptr->transform(); 3098 gfx::Transform transform = layerS1Ptr->transform();
3099 transform.Translate(200, 200); 3099 transform.Translate(200, 200);
3100 transform.Rotate(45); 3100 transform.Rotate(45);
3101 transform.Translate(-200, -200); 3101 transform.Translate(-200, -200);
3102 layerS1Ptr->SetTransform(transform); 3102 layerS1Ptr->SetTransform(transform);
3103 3103
3104 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(200, 0, 200, 400), 0); // L11 3104 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(200, 0, 200, 400), 0); // L11
3105 3105
3106 // Initial draw - must receive all quads 3106 // Initial draw - must receive all quads
3107 { 3107 {
3108 LayerTreeHostImpl::FrameData frame; 3108 LayerTreeHostImpl::FrameData frame;
3109 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3109 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3110 3110
3111 // Must receive 2 render passes. 3111 // Must receive 2 render passes.
3112 ASSERT_EQ(2U, frame.renderPasses.size()); 3112 ASSERT_EQ(2U, frame.render_passes.size());
3113 3113
3114 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 3114 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3115 EXPECT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 3115 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3116 3116
3117 myHostImpl->drawLayers(frame); 3117 myHostImpl->DrawLayers(&frame);
3118 myHostImpl->didDrawAllLayers(frame); 3118 myHostImpl->DidDrawAllLayers(frame);
3119 } 3119 }
3120 3120
3121 // Change opacity and draw. Verify we used cached texture. 3121 // Change opacity and draw. Verify we used cached texture.
3122 layerS1Ptr->SetOpacity(0.2f); 3122 layerS1Ptr->SetOpacity(0.2f);
3123 { 3123 {
3124 LayerTreeHostImpl::FrameData frame; 3124 LayerTreeHostImpl::FrameData frame;
3125 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3125 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3126 3126
3127 // One render pass must be gone due to cached texture. 3127 // One render pass must be gone due to cached texture.
3128 ASSERT_EQ(1U, frame.renderPasses.size()); 3128 ASSERT_EQ(1U, frame.render_passes.size());
3129 3129
3130 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3130 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3131 3131
3132 myHostImpl->drawLayers(frame); 3132 myHostImpl->DrawLayers(&frame);
3133 myHostImpl->didDrawAllLayers(frame); 3133 myHostImpl->DidDrawAllLayers(frame);
3134 } 3134 }
3135 } 3135 }
3136 3136
3137 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) 3137 TEST_F(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap)
3138 { 3138 {
3139 LayerTreeSettings settings; 3139 LayerTreeSettings settings;
3140 settings.minimumOcclusionTrackingSize = gfx::Size(); 3140 settings.minimumOcclusionTrackingSize = gfx::Size();
3141 settings.partialSwapEnabled = true; 3141 settings.partialSwapEnabled = true;
3142 settings.cacheRenderPassContents = true; 3142 settings.cacheRenderPassContents = true;
3143 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 3143 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
3144 3144
3145 // Layers are structure as follows: 3145 // Layers are structure as follows:
3146 // 3146 //
3147 // R +-- S1 +- L10 (owning) 3147 // R +-- S1 +- L10 (owning)
3148 // | +- L11 3148 // | +- L11
3149 // | +- L12 3149 // | +- L12
3150 // | 3150 // |
3151 // +-- S2 +- L20 (owning) 3151 // +-- S2 +- L20 (owning)
3152 // +- L21 3152 // +- L21
3153 // 3153 //
3154 // Occlusion: 3154 // Occlusion:
3155 // L12 occludes L11 (internal) 3155 // L12 occludes L11 (internal)
3156 // L20 occludes L10 (external) 3156 // L20 occludes L10 (external)
3157 // L21 occludes L20 (internal) 3157 // L21 occludes L20 (internal)
3158 3158
3159 LayerImpl* rootPtr; 3159 LayerImpl* rootPtr;
3160 LayerImpl* layerS1Ptr; 3160 LayerImpl* layerS1Ptr;
3161 LayerImpl* layerS2Ptr; 3161 LayerImpl* layerS2Ptr;
3162 3162
3163 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 3163 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
3164 3164
3165 gfx::Size rootSize(1000, 1000); 3165 gfx::Size rootSize(1000, 1000);
3166 3166
3167 myHostImpl->initializeRenderer(outputSurface.Pass()); 3167 myHostImpl->InitializeRenderer(outputSurface.Pass());
3168 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height())); 3168 myHostImpl->SetViewportSize(gfx::Size(rootSize.width(), rootSize.height()), gfx::Size(rootSize.width(), rootSize.height()));
3169 3169
3170 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 3170 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
3171 rootPtr = root.get(); 3171 rootPtr = root.get();
3172 3172
3173 root->SetAnchorPoint(gfx::PointF(0, 0)); 3173 root->SetAnchorPoint(gfx::PointF(0, 0));
3174 root->SetPosition(gfx::PointF(0, 0)); 3174 root->SetPosition(gfx::PointF(0, 0));
3175 root->SetBounds(rootSize); 3175 root->SetBounds(rootSize);
3176 root->SetContentBounds(rootSize); 3176 root->SetContentBounds(rootSize);
3177 root->SetDrawsContent(true); 3177 root->SetDrawsContent(true);
3178 root->SetMasksToBounds(true); 3178 root->SetMasksToBounds(true);
3179 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 3179 myHostImpl->active_tree()->SetRootLayer(root.Pass());
3180 3180
3181 addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr); 3181 addDrawingLayerTo(rootPtr, 2, gfx::Rect(300, 300, 300, 300), &layerS1Ptr);
3182 layerS1Ptr->SetForceRenderSurface(true); 3182 layerS1Ptr->SetForceRenderSurface(true);
3183 3183
3184 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11 3184 addDrawingLayerTo(layerS1Ptr, 3, gfx::Rect(10, 10, 10, 10), 0); // L11
3185 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12 3185 addDrawingLayerTo(layerS1Ptr, 4, gfx::Rect(0, 0, 30, 30), 0); // L12
3186 3186
3187 addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr); 3187 addDrawingLayerTo(rootPtr, 5, gfx::Rect(550, 250, 300, 400), &layerS2Ptr);
3188 layerS2Ptr->SetForceRenderSurface(true); 3188 layerS2Ptr->SetForceRenderSurface(true);
3189 3189
3190 addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21 3190 addDrawingLayerTo(layerS2Ptr, 6, gfx::Rect(20, 20, 5, 5), 0); // L21
3191 3191
3192 // Initial draw - must receive all quads 3192 // Initial draw - must receive all quads
3193 { 3193 {
3194 LayerTreeHostImpl::FrameData frame; 3194 LayerTreeHostImpl::FrameData frame;
3195 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3195 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3196 3196
3197 // Must receive 3 render passes. 3197 // Must receive 3 render passes.
3198 // For Root, there are 2 quads; for S1, there are 2 quads (one is occlud ed); for S2, there is 2 quads. 3198 // For Root, there are 2 quads; for S1, there are 2 quads (one is occlud ed); for S2, there is 2 quads.
3199 ASSERT_EQ(3U, frame.renderPasses.size()); 3199 ASSERT_EQ(3U, frame.render_passes.size());
3200 3200
3201 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 3201 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3202 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 3202 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3203 EXPECT_EQ(2U, frame.renderPasses[2]->quad_list.size()); 3203 EXPECT_EQ(2U, frame.render_passes[2]->quad_list.size());
3204 3204
3205 myHostImpl->drawLayers(frame); 3205 myHostImpl->DrawLayers(&frame);
3206 myHostImpl->didDrawAllLayers(frame); 3206 myHostImpl->DidDrawAllLayers(frame);
3207 } 3207 }
3208 3208
3209 // "Unocclude" surface S1 and repeat draw. 3209 // "Unocclude" surface S1 and repeat draw.
3210 // Must remove S2's render pass since it's cached; 3210 // Must remove S2's render pass since it's cached;
3211 // Must keep S1 quads because texture contained external occlusion. 3211 // Must keep S1 quads because texture contained external occlusion.
3212 gfx::Transform transform = layerS2Ptr->transform(); 3212 gfx::Transform transform = layerS2Ptr->transform();
3213 transform.Translate(150, 150); 3213 transform.Translate(150, 150);
3214 layerS2Ptr->SetTransform(transform); 3214 layerS2Ptr->SetTransform(transform);
3215 { 3215 {
3216 LayerTreeHostImpl::FrameData frame; 3216 LayerTreeHostImpl::FrameData frame;
3217 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3217 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3218 3218
3219 // Must receive 2 render passes. 3219 // Must receive 2 render passes.
3220 // For Root, there are 2 quads. 3220 // For Root, there are 2 quads.
3221 // For S1, there are 2 quads. 3221 // For S1, there are 2 quads.
3222 // For S2, there is no render pass 3222 // For S2, there is no render pass
3223 ASSERT_EQ(2U, frame.renderPasses.size()); 3223 ASSERT_EQ(2U, frame.render_passes.size());
3224 3224
3225 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); 3225 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size());
3226 EXPECT_EQ(2U, frame.renderPasses[1]->quad_list.size()); 3226 EXPECT_EQ(2U, frame.render_passes[1]->quad_list.size());
3227 3227
3228 myHostImpl->drawLayers(frame); 3228 myHostImpl->DrawLayers(&frame);
3229 myHostImpl->didDrawAllLayers(frame); 3229 myHostImpl->DidDrawAllLayers(frame);
3230 } 3230 }
3231 3231
3232 // "Re-occlude" surface S1 and repeat draw. 3232 // "Re-occlude" surface S1 and repeat draw.
3233 // Must remove S1's render pass since it is now available in full. 3233 // Must remove S1's render pass since it is now available in full.
3234 // S2 has no change so must also be removed. 3234 // S2 has no change so must also be removed.
3235 transform = layerS2Ptr->transform(); 3235 transform = layerS2Ptr->transform();
3236 transform.Translate(-15, -15); 3236 transform.Translate(-15, -15);
3237 layerS2Ptr->SetTransform(transform); 3237 layerS2Ptr->SetTransform(transform);
3238 { 3238 {
3239 LayerTreeHostImpl::FrameData frame; 3239 LayerTreeHostImpl::FrameData frame;
3240 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3240 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3241 3241
3242 // Root render pass only. 3242 // Root render pass only.
3243 ASSERT_EQ(1U, frame.renderPasses.size()); 3243 ASSERT_EQ(1U, frame.render_passes.size());
3244 3244
3245 myHostImpl->drawLayers(frame); 3245 myHostImpl->DrawLayers(&frame);
3246 myHostImpl->didDrawAllLayers(frame); 3246 myHostImpl->DidDrawAllLayers(frame);
3247 } 3247 }
3248 } 3248 }
3249 3249
3250 TEST_F(LayerTreeHostImplTest, textureCachingWithScissor) 3250 TEST_F(LayerTreeHostImplTest, textureCachingWithScissor)
3251 { 3251 {
3252 LayerTreeSettings settings; 3252 LayerTreeSettings settings;
3253 settings.minimumOcclusionTrackingSize = gfx::Size(); 3253 settings.minimumOcclusionTrackingSize = gfx::Size();
3254 settings.cacheRenderPassContents = true; 3254 settings.cacheRenderPassContents = true;
3255 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 3255 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
3256 3256
3257 /* 3257 /*
3258 Layers are created as follows: 3258 Layers are created as follows:
3259 3259
3260 +--------------------+ 3260 +--------------------+
3261 | 1 | 3261 | 1 |
3262 | +-----------+ | 3262 | +-----------+ |
3263 | | 2 | | 3263 | | 2 | |
3264 | | +-------------------+ 3264 | | +-------------------+
3265 | | | 3 | 3265 | | | 3 |
3266 | | +-------------------+ 3266 | | +-------------------+
3267 | | | | 3267 | | | |
3268 | +-----------+ | 3268 | +-----------+ |
3269 | | 3269 | |
3270 | | 3270 | |
3271 +--------------------+ 3271 +--------------------+
3272 3272
3273 Layers 1, 2 have render surfaces 3273 Layers 1, 2 have render surfaces
3274 */ 3274 */
3275 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->activeTree(), 1); 3275 scoped_ptr<LayerImpl> root = LayerImpl::Create(myHostImpl->active_tree(), 1) ;
3276 scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::Create(myHostImpl->active Tree(), 2); 3276 scoped_ptr<TiledLayerImpl> child = TiledLayerImpl::Create(myHostImpl->active _tree(), 2);
3277 scoped_ptr<LayerImpl> grandChild = LayerImpl::Create(myHostImpl->activeTree( ), 3); 3277 scoped_ptr<LayerImpl> grandChild = LayerImpl::Create(myHostImpl->active_tree (), 3);
3278 3278
3279 gfx::Rect rootRect(0, 0, 100, 100); 3279 gfx::Rect rootRect(0, 0, 100, 100);
3280 gfx::Rect childRect(10, 10, 50, 50); 3280 gfx::Rect childRect(10, 10, 50, 50);
3281 gfx::Rect grandChildRect(5, 5, 150, 150); 3281 gfx::Rect grandChildRect(5, 5, 150, 150);
3282 3282
3283 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >(); 3283 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped _ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface >();
3284 myHostImpl->initializeRenderer(outputSurface.Pass()); 3284 myHostImpl->InitializeRenderer(outputSurface.Pass());
3285 3285
3286 root->SetAnchorPoint(gfx::PointF(0, 0)); 3286 root->SetAnchorPoint(gfx::PointF(0, 0));
3287 root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y())); 3287 root->SetPosition(gfx::PointF(rootRect.x(), rootRect.y()));
3288 root->SetBounds(gfx::Size(rootRect.width(), rootRect.height())); 3288 root->SetBounds(gfx::Size(rootRect.width(), rootRect.height()));
3289 root->SetContentBounds(root->bounds()); 3289 root->SetContentBounds(root->bounds());
3290 root->SetDrawsContent(true); 3290 root->SetDrawsContent(true);
3291 root->SetMasksToBounds(true); 3291 root->SetMasksToBounds(true);
3292 3292
3293 child->SetAnchorPoint(gfx::PointF(0, 0)); 3293 child->SetAnchorPoint(gfx::PointF(0, 0));
3294 child->SetPosition(gfx::PointF(childRect.x(), childRect.y())); 3294 child->SetPosition(gfx::PointF(childRect.x(), childRect.y()));
(...skipping 12 matching lines...) Expand all
3307 grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y())); 3307 grandChild->SetPosition(gfx::Point(grandChildRect.x(), grandChildRect.y()));
3308 grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.heigh t())); 3308 grandChild->SetBounds(gfx::Size(grandChildRect.width(), grandChildRect.heigh t()));
3309 grandChild->SetContentBounds(grandChild->bounds()); 3309 grandChild->SetContentBounds(grandChild->bounds());
3310 grandChild->SetDrawsContent(true); 3310 grandChild->SetDrawsContent(true);
3311 3311
3312 TiledLayerImpl* childPtr = child.get(); 3312 TiledLayerImpl* childPtr = child.get();
3313 RenderPass::Id childPassId(childPtr->id(), 0); 3313 RenderPass::Id childPassId(childPtr->id(), 0);
3314 3314
3315 child->AddChild(grandChild.Pass()); 3315 child->AddChild(grandChild.Pass());
3316 root->AddChild(child.PassAs<LayerImpl>()); 3316 root->AddChild(child.PassAs<LayerImpl>());
3317 myHostImpl->activeTree()->SetRootLayer(root.Pass()); 3317 myHostImpl->active_tree()->SetRootLayer(root.Pass());
3318 myHostImpl->setViewportSize(rootRect.size(), rootRect.size()); 3318 myHostImpl->SetViewportSize(rootRect.size(), rootRect.size());
3319 3319
3320 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(chil dPassId)); 3320 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(chil dPassId));
3321 3321
3322 { 3322 {
3323 LayerTreeHostImpl::FrameData frame; 3323 LayerTreeHostImpl::FrameData frame;
3324 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3324 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3325 myHostImpl->drawLayers(frame); 3325 myHostImpl->DrawLayers(&frame);
3326 myHostImpl->didDrawAllLayers(frame); 3326 myHostImpl->DidDrawAllLayers(frame);
3327 } 3327 }
3328 3328
3329 // We should have cached textures for surface 2. 3329 // We should have cached textures for surface 2.
3330 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId)); 3330 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId));
3331 3331
3332 { 3332 {
3333 LayerTreeHostImpl::FrameData frame; 3333 LayerTreeHostImpl::FrameData frame;
3334 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3334 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3335 myHostImpl->drawLayers(frame); 3335 myHostImpl->DrawLayers(&frame);
3336 myHostImpl->didDrawAllLayers(frame); 3336 myHostImpl->DidDrawAllLayers(frame);
3337 } 3337 }
3338 3338
3339 // We should still have cached textures for surface 2 after drawing with no damage. 3339 // We should still have cached textures for surface 2 after drawing with no damage.
3340 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId)); 3340 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId));
3341 3341
3342 // Damage a single tile of surface 2. 3342 // Damage a single tile of surface 2.
3343 childPtr->set_update_rect(gfx::Rect(10, 10, 10, 10)); 3343 childPtr->set_update_rect(gfx::Rect(10, 10, 10, 10));
3344 3344
3345 { 3345 {
3346 LayerTreeHostImpl::FrameData frame; 3346 LayerTreeHostImpl::FrameData frame;
3347 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3347 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3348 myHostImpl->drawLayers(frame); 3348 myHostImpl->DrawLayers(&frame);
3349 myHostImpl->didDrawAllLayers(frame); 3349 myHostImpl->DidDrawAllLayers(frame);
3350 } 3350 }
3351 3351
3352 // We should have a cached texture for surface 2 again even though it was da maged. 3352 // We should have a cached texture for surface 2 again even though it was da maged.
3353 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId)); 3353 EXPECT_TRUE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId(child PassId));
3354 } 3354 }
3355 3355
3356 TEST_F(LayerTreeHostImplTest, surfaceTextureCaching) 3356 TEST_F(LayerTreeHostImplTest, surfaceTextureCaching)
3357 { 3357 {
3358 LayerTreeSettings settings; 3358 LayerTreeSettings settings;
3359 settings.minimumOcclusionTrackingSize = gfx::Size(); 3359 settings.minimumOcclusionTrackingSize = gfx::Size();
3360 settings.partialSwapEnabled = true; 3360 settings.partialSwapEnabled = true;
3361 settings.cacheRenderPassContents = true; 3361 settings.cacheRenderPassContents = true;
3362 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 3362 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
3363 3363
3364 LayerImpl* rootPtr; 3364 LayerImpl* rootPtr;
3365 LayerImpl* intermediateLayerPtr; 3365 LayerImpl* intermediateLayerPtr;
3366 LayerImpl* surfaceLayerPtr; 3366 LayerImpl* surfaceLayerPtr;
3367 LayerImpl* childPtr; 3367 LayerImpl* childPtr;
3368 3368
3369 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr , surfaceLayerPtr, childPtr, gfx::Size(100, 100)); 3369 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr , surfaceLayerPtr, childPtr, gfx::Size(100, 100));
3370 3370
3371 { 3371 {
3372 LayerTreeHostImpl::FrameData frame; 3372 LayerTreeHostImpl::FrameData frame;
3373 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3373 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3374 3374
3375 // Must receive two render passes, each with one quad 3375 // Must receive two render passes, each with one quad
3376 ASSERT_EQ(2U, frame.renderPasses.size()); 3376 ASSERT_EQ(2U, frame.render_passes.size());
3377 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3377 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3378 EXPECT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 3378 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3379 3379
3380 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3380 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3381 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3381 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3382 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3382 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3383 ASSERT_TRUE(targetPass); 3383 ASSERT_TRUE(targetPass);
3384 EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); 3384 EXPECT_FALSE(targetPass->damage_rect.IsEmpty());
3385 3385
3386 myHostImpl->drawLayers(frame); 3386 myHostImpl->DrawLayers(&frame);
3387 myHostImpl->didDrawAllLayers(frame); 3387 myHostImpl->DidDrawAllLayers(frame);
3388 } 3388 }
3389 3389
3390 // Draw without any change 3390 // Draw without any change
3391 { 3391 {
3392 LayerTreeHostImpl::FrameData frame; 3392 LayerTreeHostImpl::FrameData frame;
3393 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3393 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3394 3394
3395 // Must receive one render pass, as the other one should be culled 3395 // Must receive one render pass, as the other one should be culled
3396 ASSERT_EQ(1U, frame.renderPasses.size()); 3396 ASSERT_EQ(1U, frame.render_passes.size());
3397 3397
3398 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3398 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3399 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3399 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3400 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3400 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3401 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3401 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3402 3402
3403 myHostImpl->drawLayers(frame); 3403 myHostImpl->DrawLayers(&frame);
3404 myHostImpl->didDrawAllLayers(frame); 3404 myHostImpl->DidDrawAllLayers(frame);
3405 } 3405 }
3406 3406
3407 // Change opacity and draw 3407 // Change opacity and draw
3408 surfaceLayerPtr->SetOpacity(0.6f); 3408 surfaceLayerPtr->SetOpacity(0.6f);
3409 { 3409 {
3410 LayerTreeHostImpl::FrameData frame; 3410 LayerTreeHostImpl::FrameData frame;
3411 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3411 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3412 3412
3413 // Must receive one render pass, as the other one should be culled 3413 // Must receive one render pass, as the other one should be culled
3414 ASSERT_EQ(1U, frame.renderPasses.size()); 3414 ASSERT_EQ(1U, frame.render_passes.size());
3415 3415
3416 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3416 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3417 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3417 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3418 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3418 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3419 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3419 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3420 3420
3421 myHostImpl->drawLayers(frame); 3421 myHostImpl->DrawLayers(&frame);
3422 myHostImpl->didDrawAllLayers(frame); 3422 myHostImpl->DidDrawAllLayers(frame);
3423 } 3423 }
3424 3424
3425 // Change less benign property and draw - should have contents changed flag 3425 // Change less benign property and draw - should have contents changed flag
3426 surfaceLayerPtr->SetStackingOrderChanged(true); 3426 surfaceLayerPtr->SetStackingOrderChanged(true);
3427 { 3427 {
3428 LayerTreeHostImpl::FrameData frame; 3428 LayerTreeHostImpl::FrameData frame;
3429 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3429 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3430 3430
3431 // Must receive two render passes, each with one quad 3431 // Must receive two render passes, each with one quad
3432 ASSERT_EQ(2U, frame.renderPasses.size()); 3432 ASSERT_EQ(2U, frame.render_passes.size());
3433 3433
3434 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3434 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3435 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma terial); 3435 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->m aterial);
3436 3436
3437 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3437 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3438 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3438 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3439 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3439 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3440 ASSERT_TRUE(targetPass); 3440 ASSERT_TRUE(targetPass);
3441 EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); 3441 EXPECT_FALSE(targetPass->damage_rect.IsEmpty());
3442 3442
3443 myHostImpl->drawLayers(frame); 3443 myHostImpl->DrawLayers(&frame);
3444 myHostImpl->didDrawAllLayers(frame); 3444 myHostImpl->DidDrawAllLayers(frame);
3445 } 3445 }
3446 3446
3447 // Change opacity again, and evict the cached surface texture. 3447 // Change opacity again, and evict the cached surface texture.
3448 surfaceLayerPtr->SetOpacity(0.5f); 3448 surfaceLayerPtr->SetOpacity(0.5f);
3449 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->Release RenderPassTextures(); 3449 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->Release RenderPassTextures();
3450 3450
3451 // Change opacity and draw 3451 // Change opacity and draw
3452 surfaceLayerPtr->SetOpacity(0.6f); 3452 surfaceLayerPtr->SetOpacity(0.6f);
3453 { 3453 {
3454 LayerTreeHostImpl::FrameData frame; 3454 LayerTreeHostImpl::FrameData frame;
3455 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3455 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3456 3456
3457 // Must receive two render passes 3457 // Must receive two render passes
3458 ASSERT_EQ(2U, frame.renderPasses.size()); 3458 ASSERT_EQ(2U, frame.render_passes.size());
3459 3459
3460 // Even though not enough properties changed, the entire thing must be 3460 // Even though not enough properties changed, the entire thing must be
3461 // redrawn as we don't have cached textures 3461 // redrawn as we don't have cached textures
3462 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3462 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3463 EXPECT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 3463 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3464 3464
3465 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3465 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3466 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3466 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3467 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3467 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3468 ASSERT_TRUE(targetPass); 3468 ASSERT_TRUE(targetPass);
3469 EXPECT_TRUE(targetPass->damage_rect.IsEmpty()); 3469 EXPECT_TRUE(targetPass->damage_rect.IsEmpty());
3470 3470
3471 // Was our surface evicted? 3471 // Was our surface evicted?
3472 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId( targetPass->id)); 3472 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId( targetPass->id));
3473 3473
3474 myHostImpl->drawLayers(frame); 3474 myHostImpl->DrawLayers(&frame);
3475 myHostImpl->didDrawAllLayers(frame); 3475 myHostImpl->DidDrawAllLayers(frame);
3476 } 3476 }
3477 3477
3478 // Draw without any change, to make sure the state is clear 3478 // Draw without any change, to make sure the state is clear
3479 { 3479 {
3480 LayerTreeHostImpl::FrameData frame; 3480 LayerTreeHostImpl::FrameData frame;
3481 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3481 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3482 3482
3483 // Must receive one render pass, as the other one should be culled 3483 // Must receive one render pass, as the other one should be culled
3484 ASSERT_EQ(1U, frame.renderPasses.size()); 3484 ASSERT_EQ(1U, frame.render_passes.size());
3485 3485
3486 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3486 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3487 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3487 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3488 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3488 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3489 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3489 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3490 3490
3491 myHostImpl->drawLayers(frame); 3491 myHostImpl->DrawLayers(&frame);
3492 myHostImpl->didDrawAllLayers(frame); 3492 myHostImpl->DidDrawAllLayers(frame);
3493 } 3493 }
3494 3494
3495 // Change location of the intermediate layer 3495 // Change location of the intermediate layer
3496 gfx::Transform transform = intermediateLayerPtr->transform(); 3496 gfx::Transform transform = intermediateLayerPtr->transform();
3497 transform.matrix().setDouble(0, 3, 1.0001); 3497 transform.matrix().setDouble(0, 3, 1.0001);
3498 intermediateLayerPtr->SetTransform(transform); 3498 intermediateLayerPtr->SetTransform(transform);
3499 { 3499 {
3500 LayerTreeHostImpl::FrameData frame; 3500 LayerTreeHostImpl::FrameData frame;
3501 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3501 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3502 3502
3503 // Must receive one render pass, as the other one should be culled. 3503 // Must receive one render pass, as the other one should be culled.
3504 ASSERT_EQ(1U, frame.renderPasses.size()); 3504 ASSERT_EQ(1U, frame.render_passes.size());
3505 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3505 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3506 3506
3507 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3507 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3508 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3508 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3509 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3509 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3510 3510
3511 myHostImpl->drawLayers(frame); 3511 myHostImpl->DrawLayers(&frame);
3512 myHostImpl->didDrawAllLayers(frame); 3512 myHostImpl->DidDrawAllLayers(frame);
3513 } 3513 }
3514 } 3514 }
3515 3515
3516 TEST_F(LayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) 3516 TEST_F(LayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap)
3517 { 3517 {
3518 LayerTreeSettings settings; 3518 LayerTreeSettings settings;
3519 settings.minimumOcclusionTrackingSize = gfx::Size(); 3519 settings.minimumOcclusionTrackingSize = gfx::Size();
3520 settings.cacheRenderPassContents = true; 3520 settings.cacheRenderPassContents = true;
3521 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting s, this, &m_proxy); 3521 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::Create(setting s, this, &m_proxy);
3522 3522
3523 LayerImpl* rootPtr; 3523 LayerImpl* rootPtr;
3524 LayerImpl* intermediateLayerPtr; 3524 LayerImpl* intermediateLayerPtr;
3525 LayerImpl* surfaceLayerPtr; 3525 LayerImpl* surfaceLayerPtr;
3526 LayerImpl* childPtr; 3526 LayerImpl* childPtr;
3527 3527
3528 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr , surfaceLayerPtr, childPtr, gfx::Size(100, 100)); 3528 setupLayersForTextureCaching(myHostImpl.get(), rootPtr, intermediateLayerPtr , surfaceLayerPtr, childPtr, gfx::Size(100, 100));
3529 3529
3530 { 3530 {
3531 LayerTreeHostImpl::FrameData frame; 3531 LayerTreeHostImpl::FrameData frame;
3532 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3532 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3533 3533
3534 // Must receive two render passes, each with one quad 3534 // Must receive two render passes, each with one quad
3535 ASSERT_EQ(2U, frame.renderPasses.size()); 3535 ASSERT_EQ(2U, frame.render_passes.size());
3536 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3536 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3537 EXPECT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 3537 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3538 3538
3539 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3539 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3540 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3540 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3541 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3541 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3542 EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); 3542 EXPECT_FALSE(targetPass->damage_rect.IsEmpty());
3543 3543
3544 EXPECT_FALSE(frame.renderPasses[0]->damage_rect.IsEmpty()); 3544 EXPECT_FALSE(frame.render_passes[0]->damage_rect.IsEmpty());
3545 EXPECT_FALSE(frame.renderPasses[1]->damage_rect.IsEmpty()); 3545 EXPECT_FALSE(frame.render_passes[1]->damage_rect.IsEmpty());
3546 3546
3547 EXPECT_FALSE(frame.renderPasses[0]->has_occlusion_from_outside_target_su rface); 3547 EXPECT_FALSE(frame.render_passes[0]->has_occlusion_from_outside_target_s urface);
3548 EXPECT_FALSE(frame.renderPasses[1]->has_occlusion_from_outside_target_su rface); 3548 EXPECT_FALSE(frame.render_passes[1]->has_occlusion_from_outside_target_s urface);
3549 3549
3550 myHostImpl->drawLayers(frame); 3550 myHostImpl->DrawLayers(&frame);
3551 myHostImpl->didDrawAllLayers(frame); 3551 myHostImpl->DidDrawAllLayers(frame);
3552 } 3552 }
3553 3553
3554 // Draw without any change 3554 // Draw without any change
3555 { 3555 {
3556 LayerTreeHostImpl::FrameData frame; 3556 LayerTreeHostImpl::FrameData frame;
3557 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3557 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3558 3558
3559 // Even though there was no change, we set the damage to entire viewport . 3559 // Even though there was no change, we set the damage to entire viewport .
3560 // One of the passes should be culled as a result, since contents didn't change 3560 // One of the passes should be culled as a result, since contents didn't change
3561 // and we have cached texture. 3561 // and we have cached texture.
3562 ASSERT_EQ(1U, frame.renderPasses.size()); 3562 ASSERT_EQ(1U, frame.render_passes.size());
3563 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3563 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3564 3564
3565 EXPECT_TRUE(frame.renderPasses[0]->damage_rect.IsEmpty()); 3565 EXPECT_TRUE(frame.render_passes[0]->damage_rect.IsEmpty());
3566 3566
3567 myHostImpl->drawLayers(frame); 3567 myHostImpl->DrawLayers(&frame);
3568 myHostImpl->didDrawAllLayers(frame); 3568 myHostImpl->DidDrawAllLayers(frame);
3569 } 3569 }
3570 3570
3571 // Change opacity and draw 3571 // Change opacity and draw
3572 surfaceLayerPtr->SetOpacity(0.6f); 3572 surfaceLayerPtr->SetOpacity(0.6f);
3573 { 3573 {
3574 LayerTreeHostImpl::FrameData frame; 3574 LayerTreeHostImpl::FrameData frame;
3575 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3575 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3576 3576
3577 // Must receive one render pass, as the other one should be culled 3577 // Must receive one render pass, as the other one should be culled
3578 ASSERT_EQ(1U, frame.renderPasses.size()); 3578 ASSERT_EQ(1U, frame.render_passes.size());
3579 3579
3580 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3580 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3581 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3581 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3582 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3582 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3583 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3583 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3584 3584
3585 myHostImpl->drawLayers(frame); 3585 myHostImpl->DrawLayers(&frame);
3586 myHostImpl->didDrawAllLayers(frame); 3586 myHostImpl->DidDrawAllLayers(frame);
3587 } 3587 }
3588 3588
3589 // Change less benign property and draw - should have contents changed flag 3589 // Change less benign property and draw - should have contents changed flag
3590 surfaceLayerPtr->SetStackingOrderChanged(true); 3590 surfaceLayerPtr->SetStackingOrderChanged(true);
3591 { 3591 {
3592 LayerTreeHostImpl::FrameData frame; 3592 LayerTreeHostImpl::FrameData frame;
3593 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3593 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3594 3594
3595 // Must receive two render passes, each with one quad 3595 // Must receive two render passes, each with one quad
3596 ASSERT_EQ(2U, frame.renderPasses.size()); 3596 ASSERT_EQ(2U, frame.render_passes.size());
3597 3597
3598 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3598 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3599 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma terial); 3599 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.render_passes[0]->quad_list[0]->m aterial);
3600 3600
3601 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3601 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3602 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3602 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3603 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3603 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3604 ASSERT_TRUE(targetPass); 3604 ASSERT_TRUE(targetPass);
3605 EXPECT_FALSE(targetPass->damage_rect.IsEmpty()); 3605 EXPECT_FALSE(targetPass->damage_rect.IsEmpty());
3606 3606
3607 myHostImpl->drawLayers(frame); 3607 myHostImpl->DrawLayers(&frame);
3608 myHostImpl->didDrawAllLayers(frame); 3608 myHostImpl->DidDrawAllLayers(frame);
3609 } 3609 }
3610 3610
3611 // Change opacity again, and evict the cached surface texture. 3611 // Change opacity again, and evict the cached surface texture.
3612 surfaceLayerPtr->SetOpacity(0.5f); 3612 surfaceLayerPtr->SetOpacity(0.5f);
3613 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->Release RenderPassTextures(); 3613 static_cast<GLRendererWithReleaseTextures*>(myHostImpl->renderer())->Release RenderPassTextures();
3614 3614
3615 // Change opacity and draw 3615 // Change opacity and draw
3616 surfaceLayerPtr->SetOpacity(0.6f); 3616 surfaceLayerPtr->SetOpacity(0.6f);
3617 { 3617 {
3618 LayerTreeHostImpl::FrameData frame; 3618 LayerTreeHostImpl::FrameData frame;
3619 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3619 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3620 3620
3621 // Must receive two render passes 3621 // Must receive two render passes
3622 ASSERT_EQ(2U, frame.renderPasses.size()); 3622 ASSERT_EQ(2U, frame.render_passes.size());
3623 3623
3624 // Even though not enough properties changed, the entire thing must be 3624 // Even though not enough properties changed, the entire thing must be
3625 // redrawn as we don't have cached textures 3625 // redrawn as we don't have cached textures
3626 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3626 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3627 EXPECT_EQ(1U, frame.renderPasses[1]->quad_list.size()); 3627 EXPECT_EQ(1U, frame.render_passes[1]->quad_list.size());
3628 3628
3629 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma terial); 3629 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[1]->quad_list[0]->m aterial);
3630 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[1]->quad_list[0]); 3630 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[1]->quad_list[0]);
3631 RenderPass* targetPass = frame.renderPassesById[quad->render_pass_id]; 3631 RenderPass* targetPass = frame.render_passes_by_id[quad->render_pass_id] ;
3632 ASSERT_TRUE(targetPass); 3632 ASSERT_TRUE(targetPass);
3633 EXPECT_TRUE(targetPass->damage_rect.IsEmpty()); 3633 EXPECT_TRUE(targetPass->damage_rect.IsEmpty());
3634 3634
3635 // Was our surface evicted? 3635 // Was our surface evicted?
3636 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId( targetPass->id)); 3636 EXPECT_FALSE(myHostImpl->renderer()->HaveCachedResourcesForRenderPassId( targetPass->id));
3637 3637
3638 myHostImpl->drawLayers(frame); 3638 myHostImpl->DrawLayers(&frame);
3639 myHostImpl->didDrawAllLayers(frame); 3639 myHostImpl->DidDrawAllLayers(frame);
3640 } 3640 }
3641 3641
3642 // Draw without any change, to make sure the state is clear 3642 // Draw without any change, to make sure the state is clear
3643 { 3643 {
3644 LayerTreeHostImpl::FrameData frame; 3644 LayerTreeHostImpl::FrameData frame;
3645 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3645 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3646 3646
3647 // Even though there was no change, we set the damage to entire viewport . 3647 // Even though there was no change, we set the damage to entire viewport .
3648 // One of the passes should be culled as a result, since contents didn't change 3648 // One of the passes should be culled as a result, since contents didn't change
3649 // and we have cached texture. 3649 // and we have cached texture.
3650 ASSERT_EQ(1U, frame.renderPasses.size()); 3650 ASSERT_EQ(1U, frame.render_passes.size());
3651 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3651 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3652 3652
3653 myHostImpl->drawLayers(frame); 3653 myHostImpl->DrawLayers(&frame);
3654 myHostImpl->didDrawAllLayers(frame); 3654 myHostImpl->DidDrawAllLayers(frame);
3655 } 3655 }
3656 3656
3657 // Change location of the intermediate layer 3657 // Change location of the intermediate layer
3658 gfx::Transform transform = intermediateLayerPtr->transform(); 3658 gfx::Transform transform = intermediateLayerPtr->transform();
3659 transform.matrix().setDouble(0, 3, 1.0001); 3659 transform.matrix().setDouble(0, 3, 1.0001);
3660 intermediateLayerPtr->SetTransform(transform); 3660 intermediateLayerPtr->SetTransform(transform);
3661 { 3661 {
3662 LayerTreeHostImpl::FrameData frame; 3662 LayerTreeHostImpl::FrameData frame;
3663 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); 3663 EXPECT_TRUE(myHostImpl->PrepareToDraw(&frame));
3664 3664
3665 // Must receive one render pass, as the other one should be culled. 3665 // Must receive one render pass, as the other one should be culled.
3666 ASSERT_EQ(1U, frame.renderPasses.size()); 3666 ASSERT_EQ(1U, frame.render_passes.size());
3667 EXPECT_EQ(1U, frame.renderPasses[0]->quad_list.size()); 3667 EXPECT_EQ(1U, frame.render_passes[0]->quad_list.size());
3668 3668
3669 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 3669 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
3670 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. renderPasses[0]->quad_list[0]); 3670 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame. render_passes[0]->quad_list[0]);
3671 EXPECT_TRUE(frame.renderPassesById.find(quad->render_pass_id) == frame.r enderPassesById.end()); 3671 EXPECT_TRUE(frame.render_passes_by_id.find(quad->render_pass_id) == fram e.render_passes_by_id.end());
3672 3672
3673 myHostImpl->drawLayers(frame); 3673 myHostImpl->DrawLayers(&frame);
3674 myHostImpl->didDrawAllLayers(frame); 3674 myHostImpl->DidDrawAllLayers(frame);
3675 } 3675 }
3676 } 3676 }
3677 3677
3678 TEST_F(LayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit) 3678 TEST_F(LayerTreeHostImplTest, releaseContentsTextureShouldTriggerCommit)
3679 { 3679 {
3680 setReduceMemoryResult(false); 3680 setReduceMemoryResult(false);
3681 3681
3682 // Even if changing the memory limit didn't result in anything being 3682 // Even if changing the memory limit didn't result in anything being
3683 // evicted, we need to re-commit because the new value may result in us 3683 // evicted, we need to re-commit because the new value may result in us
3684 // drawing something different than before. 3684 // drawing something different than before.
3685 setReduceMemoryResult(false); 3685 setReduceMemoryResult(false);
3686 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( 3686 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
3687 m_hostImpl->memoryAllocationLimitBytes() - 1)); 3687 m_hostImpl->memory_allocation_limit_bytes() - 1));
3688 EXPECT_TRUE(m_didRequestCommit); 3688 EXPECT_TRUE(m_didRequestCommit);
3689 m_didRequestCommit = false; 3689 m_didRequestCommit = false;
3690 3690
3691 // Especially if changing the memory limit caused evictions, we need 3691 // Especially if changing the memory limit caused evictions, we need
3692 // to re-commit. 3692 // to re-commit.
3693 setReduceMemoryResult(true); 3693 setReduceMemoryResult(true);
3694 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( 3694 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
3695 m_hostImpl->memoryAllocationLimitBytes() - 1)); 3695 m_hostImpl->memory_allocation_limit_bytes() - 1));
3696 EXPECT_TRUE(m_didRequestCommit); 3696 EXPECT_TRUE(m_didRequestCommit);
3697 m_didRequestCommit = false; 3697 m_didRequestCommit = false;
3698 3698
3699 // But if we set it to the same value that it was before, we shouldn't 3699 // But if we set it to the same value that it was before, we shouldn't
3700 // re-commit. 3700 // re-commit.
3701 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy( 3701 m_hostImpl->SetManagedMemoryPolicy(ManagedMemoryPolicy(
3702 m_hostImpl->memoryAllocationLimitBytes())); 3702 m_hostImpl->memory_allocation_limit_bytes()));
3703 EXPECT_FALSE(m_didRequestCommit); 3703 EXPECT_FALSE(m_didRequestCommit);
3704 } 3704 }
3705 3705
3706 struct RenderPassRemovalTestData : public LayerTreeHostImpl::FrameData { 3706 struct RenderPassRemovalTestData : public LayerTreeHostImpl::FrameData {
3707 ScopedPtrHashMap<RenderPass::Id, TestRenderPass> renderPassCache; 3707 ScopedPtrHashMap<RenderPass::Id, TestRenderPass> renderPassCache;
3708 scoped_ptr<SharedQuadState> sharedQuadState; 3708 scoped_ptr<SharedQuadState> sharedQuadState;
3709 }; 3709 };
3710 3710
3711 class TestRenderer : public GLRenderer, public RendererClient { 3711 class TestRenderer : public GLRenderer, public RendererClient {
3712 public: 3712 public:
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 testData.renderPassCache.add(newRenderPassId, pass.Pass()); 3823 testData.renderPassCache.add(newRenderPassId, pass.Pass());
3824 } 3824 }
3825 3825
3826 gfx::Rect quadRect = gfx::Rect(0, 0, 1, 1); 3826 gfx::Rect quadRect = gfx::Rect(0, 0, 1, 1);
3827 gfx::Rect contentsChangedRect = contentsChanged ? quadRect : gfx ::Rect(); 3827 gfx::Rect contentsChangedRect = contentsChanged ? quadRect : gfx ::Rect();
3828 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create (); 3828 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create ();
3829 quad->SetNew(testData.sharedQuadState.get(), quadRect, newRender PassId, isReplica, 1, contentsChangedRect, gfx::RectF(0, 0, 1, 1), WebKit::WebFi lterOperations(), skia::RefPtr<SkImageFilter>(), WebKit::WebFilterOperations()); 3829 quad->SetNew(testData.sharedQuadState.get(), quadRect, newRender PassId, isReplica, 1, contentsChangedRect, gfx::RectF(0, 0, 1, 1), WebKit::WebFi lterOperations(), skia::RefPtr<SkImageFilter>(), WebKit::WebFilterOperations());
3830 renderPass->AppendQuad(quad.PassAs<DrawQuad>()); 3830 renderPass->AppendQuad(quad.PassAs<DrawQuad>());
3831 } 3831 }
3832 } 3832 }
3833 testData.renderPassesById[renderPassId] = renderPass.get(); 3833 testData.render_passes_by_id[renderPassId] = renderPass.get();
3834 testData.renderPasses.insert(testData.renderPasses.begin(), renderPass.P assAs<RenderPass>()); 3834 testData.render_passes.insert(testData.render_passes.begin(), renderPass .PassAs<RenderPass>());
3835 if (*currentChar) 3835 if (*currentChar)
3836 currentChar++; 3836 currentChar++;
3837 } 3837 }
3838 } 3838 }
3839 3839
3840 void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buf fer) 3840 void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buf fer)
3841 { 3841 {
3842 char* pos = buffer; 3842 char* pos = buffer;
3843 for (RenderPassList::const_reverse_iterator it = testData.renderPasses.rbegi n(); it != testData.renderPasses.rend(); ++it) { 3843 for (RenderPassList::const_reverse_iterator it = testData.render_passes.rbeg in(); it != testData.render_passes.rend(); ++it) {
3844 const RenderPass* currentPass = *it; 3844 const RenderPass* currentPass = *it;
3845 *pos = currentPass->id.layer_id; 3845 *pos = currentPass->id.layer_id;
3846 pos++; 3846 pos++;
3847 *pos = currentPass->id.index; 3847 *pos = currentPass->id.index;
3848 pos++; 3848 pos++;
3849 3849
3850 QuadList::const_iterator quadListIterator = currentPass->quad_list.begin (); 3850 QuadList::const_iterator quadListIterator = currentPass->quad_list.begin ();
3851 while (quadListIterator != currentPass->quad_list.end()) { 3851 while (quadListIterator != currentPass->quad_list.end()) {
3852 DrawQuad* currentQuad = *quadListIterator; 3852 DrawQuad* currentQuad = *quadListIterator;
3853 switch (currentQuad->material) { 3853 switch (currentQuad->material) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 scoped_ptr<OutputSurface> outputSurface(createOutputSurface()); 4028 scoped_ptr<OutputSurface> outputSurface(createOutputSurface());
4029 ASSERT_TRUE(outputSurface->context3d()); 4029 ASSERT_TRUE(outputSurface->context3d());
4030 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(outpu tSurface.get())); 4030 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::Create(outpu tSurface.get()));
4031 4031
4032 scoped_ptr<TestRenderer> renderer(TestRenderer::Create(resourceProvider.get( ), outputSurface.get(), &m_proxy)); 4032 scoped_ptr<TestRenderer> renderer(TestRenderer::Create(resourceProvider.get( ), outputSurface.get(), &m_proxy));
4033 4033
4034 int testCaseIndex = 0; 4034 int testCaseIndex = 0;
4035 while (removeRenderPassesCases[testCaseIndex].name) { 4035 while (removeRenderPassesCases[testCaseIndex].name) {
4036 RenderPassRemovalTestData testData; 4036 RenderPassRemovalTestData testData;
4037 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS cript, testData, renderer.get()); 4037 configureRenderPassTestData(removeRenderPassesCases[testCaseIndex].initS cript, testData, renderer.get());
4038 LayerTreeHostImpl::removeRenderPasses(LayerTreeHostImpl::CullRenderPasse sWithCachedTextures(*renderer), testData); 4038 LayerTreeHostImpl::RemoveRenderPasses(LayerTreeHostImpl::CullRenderPasse sWithCachedTextures(*renderer), &testData);
4039 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat a); 4039 verifyRenderPassTestData(removeRenderPassesCases[testCaseIndex], testDat a);
4040 testCaseIndex++; 4040 testCaseIndex++;
4041 } 4041 }
4042 } 4042 }
4043 4043
4044 class LayerTreeHostImplTestWithDelegatingRenderer : public LayerTreeHostImplTest { 4044 class LayerTreeHostImplTestWithDelegatingRenderer : public LayerTreeHostImplTest {
4045 protected: 4045 protected:
4046 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE 4046 virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE
4047 { 4047 {
4048 // Creates an output surface with a parent to use a delegating renderer. 4048 // Creates an output surface with a parent to use a delegating renderer.
4049 WebKit::WebGraphicsContext3D::Attributes attrs; 4049 WebKit::WebGraphicsContext3D::Attributes attrs;
4050 return FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::C reate(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); 4050 return FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::C reate(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>();
4051 } 4051 }
4052 4052
4053 void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) { 4053 void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) {
4054 LayerTreeHostImpl::FrameData frame; 4054 LayerTreeHostImpl::FrameData frame;
4055 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4055 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4056 ASSERT_EQ(1u, frame.renderPasses.size()); 4056 ASSERT_EQ(1u, frame.render_passes.size());
4057 4057
4058 // Verify the damage rect for the root render pass. 4058 // Verify the damage rect for the root render pass.
4059 const RenderPass* rootRenderPass = frame.renderPasses.back(); 4059 const RenderPass* rootRenderPass = frame.render_passes.back();
4060 EXPECT_RECT_EQ(expectedDamage, rootRenderPass->damage_rect); 4060 EXPECT_RECT_EQ(expectedDamage, rootRenderPass->damage_rect);
4061 4061
4062 // Verify the root layer's quad is generated and not being culled. 4062 // Verify the root layer's quad is generated and not being culled.
4063 ASSERT_EQ(1u, rootRenderPass->quad_list.size()); 4063 ASSERT_EQ(1u, rootRenderPass->quad_list.size());
4064 gfx::Rect expectedVisibleRect(m_hostImpl->rootLayer()->content_bounds()) ; 4064 gfx::Rect expectedVisibleRect(m_hostImpl->active_tree()->root_layer()->c ontent_bounds());
4065 EXPECT_RECT_EQ(expectedVisibleRect, rootRenderPass->quad_list[0]->visibl e_rect); 4065 EXPECT_RECT_EQ(expectedVisibleRect, rootRenderPass->quad_list[0]->visibl e_rect);
4066 4066
4067 m_hostImpl->drawLayers(frame); 4067 m_hostImpl->DrawLayers(&frame);
4068 m_hostImpl->didDrawAllLayers(frame); 4068 m_hostImpl->DidDrawAllLayers(frame);
4069 } 4069 }
4070 }; 4070 };
4071 4071
4072 TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) 4072 TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect)
4073 { 4073 {
4074 scoped_ptr<SolidColorLayerImpl> root = SolidColorLayerImpl::Create(m_hostImp l->activeTree(), 1); 4074 scoped_ptr<SolidColorLayerImpl> root = SolidColorLayerImpl::Create(m_hostImp l->active_tree(), 1);
4075 root->SetAnchorPoint(gfx::PointF(0.f, 0.f)); 4075 root->SetAnchorPoint(gfx::PointF(0.f, 0.f));
4076 root->SetPosition(gfx::PointF(0.f, 0.f)); 4076 root->SetPosition(gfx::PointF(0.f, 0.f));
4077 root->SetBounds(gfx::Size(10, 10)); 4077 root->SetBounds(gfx::Size(10, 10));
4078 root->SetContentBounds(gfx::Size(10, 10)); 4078 root->SetContentBounds(gfx::Size(10, 10));
4079 root->SetDrawsContent(true); 4079 root->SetDrawsContent(true);
4080 m_hostImpl->activeTree()->SetRootLayer(root.PassAs<LayerImpl>()); 4080 m_hostImpl->active_tree()->SetRootLayer(root.PassAs<LayerImpl>());
4081 4081
4082 // Draw a frame. In the first frame, the entire viewport should be damaged. 4082 // Draw a frame. In the first frame, the entire viewport should be damaged.
4083 gfx::Rect fullFrameDamage = gfx::Rect(m_hostImpl->DeviceViewportSize()); 4083 gfx::Rect fullFrameDamage = gfx::Rect(m_hostImpl->device_viewport_size());
4084 drawFrameAndTestDamage(fullFrameDamage); 4084 drawFrameAndTestDamage(fullFrameDamage);
4085 4085
4086 // The second frame should have no damage, but the quads should still be gen erated. 4086 // The second frame should have no damage, but the quads should still be gen erated.
4087 gfx::Rect noDamage = gfx::Rect(); 4087 gfx::Rect noDamage = gfx::Rect();
4088 drawFrameAndTestDamage(noDamage); 4088 drawFrameAndTestDamage(noDamage);
4089 } 4089 }
4090 4090
4091 class FakeMaskLayerImpl : public LayerImpl { 4091 class FakeMaskLayerImpl : public LayerImpl {
4092 public: 4092 public:
4093 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* treeImpl, int id) 4093 static scoped_ptr<FakeMaskLayerImpl> Create(LayerTreeImpl* treeImpl, int id)
4094 { 4094 {
4095 return make_scoped_ptr(new FakeMaskLayerImpl(treeImpl, id)); 4095 return make_scoped_ptr(new FakeMaskLayerImpl(treeImpl, id));
4096 } 4096 }
4097 4097
4098 virtual ResourceProvider::ResourceId ContentsResourceId() const OVERRIDE { r eturn 0; } 4098 virtual ResourceProvider::ResourceId ContentsResourceId() const OVERRIDE { r eturn 0; }
4099 4099
4100 private: 4100 private:
4101 FakeMaskLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { } 4101 FakeMaskLayerImpl(LayerTreeImpl* treeImpl, int id) : LayerImpl(treeImpl, id) { }
4102 }; 4102 };
4103 4103
4104 TEST_F(LayerTreeHostImplTest, maskLayerWithScaling) 4104 TEST_F(LayerTreeHostImplTest, maskLayerWithScaling)
4105 { 4105 {
4106 // Root 4106 // Root
4107 // | 4107 // |
4108 // +-- Scaling Layer (adds a 2x scale) 4108 // +-- Scaling Layer (adds a 2x scale)
4109 // | 4109 // |
4110 // +-- Content Layer 4110 // +-- Content Layer
4111 // +--Mask 4111 // +--Mask
4112 scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->activeTree( ), 1); 4112 scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->active_tree (), 1);
4113 LayerImpl* root = scopedRoot.get(); 4113 LayerImpl* root = scopedRoot.get();
4114 m_hostImpl->activeTree()->SetRootLayer(scopedRoot.Pass()); 4114 m_hostImpl->active_tree()->SetRootLayer(scopedRoot.Pass());
4115 4115
4116 scoped_ptr<LayerImpl> scopedScalingLayer = LayerImpl::Create(m_hostImpl->act iveTree(), 2); 4116 scoped_ptr<LayerImpl> scopedScalingLayer = LayerImpl::Create(m_hostImpl->act ive_tree(), 2);
4117 LayerImpl* scalingLayer = scopedScalingLayer.get(); 4117 LayerImpl* scalingLayer = scopedScalingLayer.get();
4118 root->AddChild(scopedScalingLayer.Pass()); 4118 root->AddChild(scopedScalingLayer.Pass());
4119 4119
4120 scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->act iveTree(), 3); 4120 scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->act ive_tree(), 3);
4121 LayerImpl* contentLayer = scopedContentLayer.get(); 4121 LayerImpl* contentLayer = scopedContentLayer.get();
4122 scalingLayer->AddChild(scopedContentLayer.Pass()); 4122 scalingLayer->AddChild(scopedContentLayer.Pass());
4123 4123
4124 scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_ hostImpl->activeTree(), 4); 4124 scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_ hostImpl->active_tree(), 4);
4125 FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get(); 4125 FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get();
4126 contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>()); 4126 contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>());
4127 4127
4128 gfx::Size rootSize(100, 100); 4128 gfx::Size rootSize(100, 100);
4129 root->SetBounds(rootSize); 4129 root->SetBounds(rootSize);
4130 root->SetContentBounds(rootSize); 4130 root->SetContentBounds(rootSize);
4131 root->SetPosition(gfx::PointF()); 4131 root->SetPosition(gfx::PointF());
4132 root->SetAnchorPoint(gfx::PointF()); 4132 root->SetAnchorPoint(gfx::PointF());
4133 4133
4134 gfx::Size scalingLayerSize(50, 50); 4134 gfx::Size scalingLayerSize(50, 50);
(...skipping 14 matching lines...) Expand all
4149 maskLayer->SetBounds(scalingLayerSize); 4149 maskLayer->SetBounds(scalingLayerSize);
4150 maskLayer->SetContentBounds(scalingLayerSize); 4150 maskLayer->SetContentBounds(scalingLayerSize);
4151 maskLayer->SetPosition(gfx::PointF()); 4151 maskLayer->SetPosition(gfx::PointF());
4152 maskLayer->SetAnchorPoint(gfx::PointF()); 4152 maskLayer->SetAnchorPoint(gfx::PointF());
4153 maskLayer->SetDrawsContent(true); 4153 maskLayer->SetDrawsContent(true);
4154 4154
4155 4155
4156 // Check that the tree scaling is correctly taken into account for the mask, 4156 // Check that the tree scaling is correctly taken into account for the mask,
4157 // that should fully map onto the quad. 4157 // that should fully map onto the quad.
4158 float deviceScaleFactor = 1.f; 4158 float deviceScaleFactor = 1.f;
4159 m_hostImpl->setViewportSize(rootSize, rootSize); 4159 m_hostImpl->SetViewportSize(rootSize, rootSize);
4160 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); 4160 m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor);
4161 { 4161 {
4162 LayerTreeHostImpl::FrameData frame; 4162 LayerTreeHostImpl::FrameData frame;
4163 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4163 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4164 4164
4165 ASSERT_EQ(1u, frame.renderPasses.size()); 4165 ASSERT_EQ(1u, frame.render_passes.size());
4166 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4166 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4167 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4167 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4168 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4168 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4169 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring()); 4169 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring());
4170 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4170 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4171 4171
4172 m_hostImpl->drawLayers(frame); 4172 m_hostImpl->DrawLayers(&frame);
4173 m_hostImpl->didDrawAllLayers(frame); 4173 m_hostImpl->DidDrawAllLayers(frame);
4174 } 4174 }
4175 4175
4176 4176
4177 // Applying a DSF should change the render surface size, but won't affect 4177 // Applying a DSF should change the render surface size, but won't affect
4178 // which part of the mask is used. 4178 // which part of the mask is used.
4179 deviceScaleFactor = 2.f; 4179 deviceScaleFactor = 2.f;
4180 gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceS caleFactor))); 4180 gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceS caleFactor)));
4181 m_hostImpl->setViewportSize(rootSize, deviceViewport); 4181 m_hostImpl->SetViewportSize(rootSize, deviceViewport);
4182 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); 4182 m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor);
4183 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 4183 m_hostImpl->active_tree()->set_needs_update_draw_properties();
4184 { 4184 {
4185 LayerTreeHostImpl::FrameData frame; 4185 LayerTreeHostImpl::FrameData frame;
4186 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4186 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4187 4187
4188 ASSERT_EQ(1u, frame.renderPasses.size()); 4188 ASSERT_EQ(1u, frame.render_passes.size());
4189 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4189 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4190 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4190 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4191 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4191 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4192 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToS tring()); 4192 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToS tring());
4193 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4193 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4194 4194
4195 m_hostImpl->drawLayers(frame); 4195 m_hostImpl->DrawLayers(&frame);
4196 m_hostImpl->didDrawAllLayers(frame); 4196 m_hostImpl->DidDrawAllLayers(frame);
4197 } 4197 }
4198 4198
4199 4199
4200 // Applying an equivalent content scale on the content layer and the mask 4200 // Applying an equivalent content scale on the content layer and the mask
4201 // should still result in the same part of the mask being used. 4201 // should still result in the same part of the mask being used.
4202 gfx::Size contentsBounds(gfx::ToRoundedSize(gfx::ScaleSize(scalingLayerSize, deviceScaleFactor))); 4202 gfx::Size contentsBounds(gfx::ToRoundedSize(gfx::ScaleSize(scalingLayerSize, deviceScaleFactor)));
4203 contentLayer->SetContentBounds(contentsBounds); 4203 contentLayer->SetContentBounds(contentsBounds);
4204 contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); 4204 contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor);
4205 maskLayer->SetContentBounds(contentsBounds); 4205 maskLayer->SetContentBounds(contentsBounds);
4206 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); 4206 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor);
4207 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 4207 m_hostImpl->active_tree()->set_needs_update_draw_properties();
4208 { 4208 {
4209 LayerTreeHostImpl::FrameData frame; 4209 LayerTreeHostImpl::FrameData frame;
4210 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4210 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4211 4211
4212 ASSERT_EQ(1u, frame.renderPasses.size()); 4212 ASSERT_EQ(1u, frame.render_passes.size());
4213 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4213 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4214 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4214 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4215 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4215 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4216 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToS tring()); 4216 EXPECT_EQ(gfx::Rect(0, 0, 200, 200).ToString(), renderPassQuad->rect.ToS tring());
4217 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4217 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4218 4218
4219 m_hostImpl->drawLayers(frame); 4219 m_hostImpl->DrawLayers(&frame);
4220 m_hostImpl->didDrawAllLayers(frame); 4220 m_hostImpl->DidDrawAllLayers(frame);
4221 } 4221 }
4222 } 4222 }
4223 4223
4224 TEST_F(LayerTreeHostImplTest, maskLayerWithDifferentBounds) 4224 TEST_F(LayerTreeHostImplTest, maskLayerWithDifferentBounds)
4225 { 4225 {
4226 // The mask layer has bounds 100x100 but is attached to a layer with bounds 50x50. 4226 // The mask layer has bounds 100x100 but is attached to a layer with bounds 50x50.
4227 4227
4228 scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->activeTree( ), 1); 4228 scoped_ptr<LayerImpl> scopedRoot = LayerImpl::Create(m_hostImpl->active_tree (), 1);
4229 LayerImpl* root = scopedRoot.get(); 4229 LayerImpl* root = scopedRoot.get();
4230 m_hostImpl->activeTree()->SetRootLayer(scopedRoot.Pass()); 4230 m_hostImpl->active_tree()->SetRootLayer(scopedRoot.Pass());
4231 4231
4232 scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->act iveTree(), 3); 4232 scoped_ptr<LayerImpl> scopedContentLayer = LayerImpl::Create(m_hostImpl->act ive_tree(), 3);
4233 LayerImpl* contentLayer = scopedContentLayer.get(); 4233 LayerImpl* contentLayer = scopedContentLayer.get();
4234 root->AddChild(scopedContentLayer.Pass()); 4234 root->AddChild(scopedContentLayer.Pass());
4235 4235
4236 scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_ hostImpl->activeTree(), 4); 4236 scoped_ptr<FakeMaskLayerImpl> scopedMaskLayer = FakeMaskLayerImpl::Create(m_ hostImpl->active_tree(), 4);
4237 FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get(); 4237 FakeMaskLayerImpl* maskLayer = scopedMaskLayer.get();
4238 contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>()); 4238 contentLayer->SetMaskLayer(scopedMaskLayer.PassAs<LayerImpl>());
4239 4239
4240 gfx::Size rootSize(100, 100); 4240 gfx::Size rootSize(100, 100);
4241 root->SetBounds(rootSize); 4241 root->SetBounds(rootSize);
4242 root->SetContentBounds(rootSize); 4242 root->SetContentBounds(rootSize);
4243 root->SetPosition(gfx::PointF()); 4243 root->SetPosition(gfx::PointF());
4244 root->SetAnchorPoint(gfx::PointF()); 4244 root->SetAnchorPoint(gfx::PointF());
4245 4245
4246 gfx::Size layerSize(50, 50); 4246 gfx::Size layerSize(50, 50);
4247 contentLayer->SetBounds(layerSize); 4247 contentLayer->SetBounds(layerSize);
4248 contentLayer->SetContentBounds(layerSize); 4248 contentLayer->SetContentBounds(layerSize);
4249 contentLayer->SetPosition(gfx::PointF()); 4249 contentLayer->SetPosition(gfx::PointF());
4250 contentLayer->SetAnchorPoint(gfx::PointF()); 4250 contentLayer->SetAnchorPoint(gfx::PointF());
4251 contentLayer->SetDrawsContent(true); 4251 contentLayer->SetDrawsContent(true);
4252 4252
4253 gfx::Size maskSize(100, 100); 4253 gfx::Size maskSize(100, 100);
4254 maskLayer->SetBounds(maskSize); 4254 maskLayer->SetBounds(maskSize);
4255 maskLayer->SetContentBounds(maskSize); 4255 maskLayer->SetContentBounds(maskSize);
4256 maskLayer->SetPosition(gfx::PointF()); 4256 maskLayer->SetPosition(gfx::PointF());
4257 maskLayer->SetAnchorPoint(gfx::PointF()); 4257 maskLayer->SetAnchorPoint(gfx::PointF());
4258 maskLayer->SetDrawsContent(true); 4258 maskLayer->SetDrawsContent(true);
4259 4259
4260 4260
4261 // Check that the mask fills the surface. 4261 // Check that the mask fills the surface.
4262 float deviceScaleFactor = 1.f; 4262 float deviceScaleFactor = 1.f;
4263 m_hostImpl->setViewportSize(rootSize, rootSize); 4263 m_hostImpl->SetViewportSize(rootSize, rootSize);
4264 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); 4264 m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor);
4265 { 4265 {
4266 LayerTreeHostImpl::FrameData frame; 4266 LayerTreeHostImpl::FrameData frame;
4267 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4267 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4268 4268
4269 ASSERT_EQ(1u, frame.renderPasses.size()); 4269 ASSERT_EQ(1u, frame.render_passes.size());
4270 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4270 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4271 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4271 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4272 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4272 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4273 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), renderPassQuad->rect.ToStr ing()); 4273 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), renderPassQuad->rect.ToStr ing());
4274 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4274 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4275 4275
4276 m_hostImpl->drawLayers(frame); 4276 m_hostImpl->DrawLayers(&frame);
4277 m_hostImpl->didDrawAllLayers(frame); 4277 m_hostImpl->DidDrawAllLayers(frame);
4278 } 4278 }
4279 4279
4280 4280
4281 // Applying a DSF should change the render surface size, but won't affect 4281 // Applying a DSF should change the render surface size, but won't affect
4282 // which part of the mask is used. 4282 // which part of the mask is used.
4283 deviceScaleFactor = 2.f; 4283 deviceScaleFactor = 2.f;
4284 gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceS caleFactor))); 4284 gfx::Size deviceViewport(gfx::ToFlooredSize(gfx::ScaleSize(rootSize, deviceS caleFactor)));
4285 m_hostImpl->setViewportSize(rootSize, deviceViewport); 4285 m_hostImpl->SetViewportSize(rootSize, deviceViewport);
4286 m_hostImpl->setDeviceScaleFactor(deviceScaleFactor); 4286 m_hostImpl->SetDeviceScaleFactor(deviceScaleFactor);
4287 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 4287 m_hostImpl->active_tree()->set_needs_update_draw_properties();
4288 { 4288 {
4289 LayerTreeHostImpl::FrameData frame; 4289 LayerTreeHostImpl::FrameData frame;
4290 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4290 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4291 4291
4292 ASSERT_EQ(1u, frame.renderPasses.size()); 4292 ASSERT_EQ(1u, frame.render_passes.size());
4293 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4293 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4294 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4294 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4295 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4295 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4296 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring()); 4296 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring());
4297 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4297 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4298 4298
4299 m_hostImpl->drawLayers(frame); 4299 m_hostImpl->DrawLayers(&frame);
4300 m_hostImpl->didDrawAllLayers(frame); 4300 m_hostImpl->DidDrawAllLayers(frame);
4301 } 4301 }
4302 4302
4303 4303
4304 // Applying an equivalent content scale on the content layer and the mask 4304 // Applying an equivalent content scale on the content layer and the mask
4305 // should still result in the same part of the mask being used. 4305 // should still result in the same part of the mask being used.
4306 gfx::Size layerSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(layerSize, device ScaleFactor))); 4306 gfx::Size layerSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(layerSize, device ScaleFactor)));
4307 contentLayer->SetContentBounds(layerSizeLarge); 4307 contentLayer->SetContentBounds(layerSizeLarge);
4308 contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); 4308 contentLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor);
4309 gfx::Size maskSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(maskSize, deviceSc aleFactor))); 4309 gfx::Size maskSizeLarge(gfx::ToRoundedSize(gfx::ScaleSize(maskSize, deviceSc aleFactor)));
4310 maskLayer->SetContentBounds(maskSizeLarge); 4310 maskLayer->SetContentBounds(maskSizeLarge);
4311 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); 4311 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor);
4312 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 4312 m_hostImpl->active_tree()->set_needs_update_draw_properties();
4313 { 4313 {
4314 LayerTreeHostImpl::FrameData frame; 4314 LayerTreeHostImpl::FrameData frame;
4315 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4315 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4316 4316
4317 ASSERT_EQ(1u, frame.renderPasses.size()); 4317 ASSERT_EQ(1u, frame.render_passes.size());
4318 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4318 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4319 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4319 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4320 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4320 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4321 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring()); 4321 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring());
4322 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4322 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4323 4323
4324 m_hostImpl->drawLayers(frame); 4324 m_hostImpl->DrawLayers(&frame);
4325 m_hostImpl->didDrawAllLayers(frame); 4325 m_hostImpl->DidDrawAllLayers(frame);
4326 } 4326 }
4327 4327
4328 // Applying a different contents scale to the mask layer will still result 4328 // Applying a different contents scale to the mask layer will still result
4329 // in the mask covering the owning layer. 4329 // in the mask covering the owning layer.
4330 maskLayer->SetContentBounds(maskSize); 4330 maskLayer->SetContentBounds(maskSize);
4331 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor); 4331 maskLayer->SetContentsScale(deviceScaleFactor, deviceScaleFactor);
4332 m_hostImpl->activeTree()->set_needs_update_draw_properties(); 4332 m_hostImpl->active_tree()->set_needs_update_draw_properties();
4333 { 4333 {
4334 LayerTreeHostImpl::FrameData frame; 4334 LayerTreeHostImpl::FrameData frame;
4335 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); 4335 EXPECT_TRUE(m_hostImpl->PrepareToDraw(&frame));
4336 4336
4337 ASSERT_EQ(1u, frame.renderPasses.size()); 4337 ASSERT_EQ(1u, frame.render_passes.size());
4338 ASSERT_EQ(1u, frame.renderPasses[0]->quad_list.size()); 4338 ASSERT_EQ(1u, frame.render_passes[0]->quad_list.size());
4339 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[0]->quad_list[0]->ma terial); 4339 ASSERT_EQ(DrawQuad::RENDER_PASS, frame.render_passes[0]->quad_list[0]->m aterial);
4340 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.renderPasses[0]->quad_list[0]); 4340 const RenderPassDrawQuad* renderPassQuad = RenderPassDrawQuad::MaterialC ast(frame.render_passes[0]->quad_list[0]);
4341 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring()); 4341 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), renderPassQuad->rect.ToS tring());
4342 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString()); 4342 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), renderPassQuad->mas k_uv_rect.ToString());
4343 4343
4344 m_hostImpl->drawLayers(frame); 4344 m_hostImpl->DrawLayers(&frame);
4345 m_hostImpl->didDrawAllLayers(frame); 4345 m_hostImpl->DidDrawAllLayers(frame);
4346 } 4346 }
4347 } 4347 }
4348 4348
4349 } // namespace 4349 } // namespace
4350 } // namespace cc 4350 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl.cc ('k') | cc/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698