4a2fd31a9344a62d1f036a760a82843d27025cd8
[WebKit-https.git] / Source / WebKit / chromium / tests / CCLayerTreeHostTest.cpp
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include "config.h"
26
27 #include "cc/CCLayerTreeHost.h"
28
29 #include "AnimationIdVendor.h"
30 #include "CCOcclusionTrackerTestCommon.h"
31 #include "CCThreadedTest.h"
32 #include "ContentLayerChromium.h"
33 #include "GraphicsContext3DPrivate.h"
34 #include "cc/CCGraphicsContext.h"
35 #include "cc/CCLayerTreeHostImpl.h"
36 #include "cc/CCSettings.h"
37 #include "cc/CCTextureUpdater.h"
38 #include "cc/CCTimingFunction.h"
39 #include "platform/WebThread.h"
40 #include <gmock/gmock.h>
41 #include <gtest/gtest.h>
42 #include <public/Platform.h>
43 #include <wtf/MainThread.h>
44 #include <wtf/OwnArrayPtr.h>
45
46 using namespace WebCore;
47 using namespace WebKit;
48 using namespace WebKitTests;
49 using namespace WTF;
50
51 #define EXPECT_EQ_RECT(a, b) \
52     EXPECT_EQ(a.x(), b.x()); \
53     EXPECT_EQ(a.y(), b.y()); \
54     EXPECT_EQ(a.width(), b.width()); \
55     EXPECT_EQ(a.height(), b.height());
56
57 namespace {
58
59 class CCLayerTreeHostTest : public CCThreadedTest { };
60 class CCLayerTreeHostTestThreadOnly : public CCThreadedTestThreadOnly { };
61
62 // Shortlived layerTreeHosts shouldn't die.
63 class CCLayerTreeHostTestShortlived1 : public CCLayerTreeHostTest {
64 public:
65     CCLayerTreeHostTestShortlived1() { }
66
67     virtual void beginTest()
68     {
69         // Kill the layerTreeHost immediately.
70         m_layerTreeHost->setRootLayer(0);
71         m_layerTreeHost.clear();
72
73         endTest();
74     }
75
76     virtual void afterTest()
77     {
78     }
79 };
80
81 // Shortlived layerTreeHosts shouldn't die with a commit in flight.
82 class CCLayerTreeHostTestShortlived2 : public CCLayerTreeHostTest {
83 public:
84     CCLayerTreeHostTestShortlived2() { }
85
86     virtual void beginTest()
87     {
88         postSetNeedsCommitToMainThread();
89
90         // Kill the layerTreeHost immediately.
91         m_layerTreeHost->setRootLayer(0);
92         m_layerTreeHost.clear();
93
94         endTest();
95     }
96
97     virtual void afterTest()
98     {
99     }
100 };
101
102 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestShortlived2)
103
104 // Shortlived layerTreeHosts shouldn't die with a redraw in flight.
105 class CCLayerTreeHostTestShortlived3 : public CCLayerTreeHostTest {
106 public:
107     CCLayerTreeHostTestShortlived3() { }
108
109     virtual void beginTest()
110     {
111         postSetNeedsRedrawToMainThread();
112
113         // Kill the layerTreeHost immediately.
114         m_layerTreeHost->setRootLayer(0);
115         m_layerTreeHost.clear();
116
117         endTest();
118     }
119
120     virtual void afterTest()
121     {
122     }
123 };
124
125 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestShortlived3)
126
127 // Test interleaving of redraws and commits
128 class CCLayerTreeHostTestCommitingWithContinuousRedraw : public CCLayerTreeHostTestThreadOnly {
129 public:
130     CCLayerTreeHostTestCommitingWithContinuousRedraw()
131         : m_numCompleteCommits(0)
132         , m_numDraws(0)
133     {
134     }
135
136     virtual void beginTest()
137     {
138         postSetNeedsCommitToMainThread();
139     }
140
141     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
142     {
143         m_numCompleteCommits++;
144         if (m_numCompleteCommits == 2)
145             endTest();
146     }
147
148     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*)
149     {
150         if (m_numDraws == 1)
151           postSetNeedsCommitToMainThread();
152         m_numDraws++;
153         postSetNeedsRedrawToMainThread();
154     }
155
156     virtual void afterTest()
157     {
158     }
159
160 private:
161     int m_numCompleteCommits;
162     int m_numDraws;
163 };
164
165 TEST_F(CCLayerTreeHostTestCommitingWithContinuousRedraw, runMultiThread)
166 {
167     runTestThreaded();
168 }
169
170 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
171 // draw with frame 0.
172 class CCLayerTreeHostTestSetNeedsCommit1 : public CCLayerTreeHostTestThreadOnly {
173 public:
174     CCLayerTreeHostTestSetNeedsCommit1()
175         : m_numCommits(0)
176         , m_numDraws(0)
177     {
178     }
179
180     virtual void beginTest()
181     {
182         postSetNeedsCommitToMainThread();
183         postSetNeedsCommitToMainThread();
184     }
185
186     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
187     {
188         m_numDraws++;
189         if (!impl->sourceFrameNumber())
190             endTest();
191     }
192
193     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
194     {
195         m_numCommits++;
196     }
197
198     virtual void afterTest()
199     {
200         EXPECT_GE(1, m_numCommits);
201         EXPECT_GE(1, m_numDraws);
202     }
203
204 private:
205     int m_numCommits;
206     int m_numDraws;
207 };
208
209 TEST_F(CCLayerTreeHostTestSetNeedsCommit1, DISABLED_runMultiThread)
210 {
211     runTestThreaded();
212 }
213
214 // A setNeedsCommit should lead to 1 commit. Issuing a second commit after that
215 // first committed frame draws should lead to another commit.
216 class CCLayerTreeHostTestSetNeedsCommit2 : public CCLayerTreeHostTestThreadOnly {
217 public:
218     CCLayerTreeHostTestSetNeedsCommit2()
219         : m_numCommits(0)
220         , m_numDraws(0)
221     {
222     }
223
224     virtual void beginTest()
225     {
226         postSetNeedsCommitToMainThread();
227     }
228
229     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
230     {
231         if (!impl->sourceFrameNumber())
232             postSetNeedsCommitToMainThread();
233         else if (impl->sourceFrameNumber() == 1)
234             endTest();
235     }
236
237     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
238     {
239         m_numCommits++;
240     }
241
242     virtual void afterTest()
243     {
244         EXPECT_EQ(2, m_numCommits);
245         EXPECT_GE(2, m_numDraws);
246     }
247
248 private:
249     int m_numCommits;
250     int m_numDraws;
251 };
252
253 #if OS(WINDOWS)
254 // http://webkit.org/b/74623
255 TEST_F(CCLayerTreeHostTestSetNeedsCommit2, FLAKY_runMultiThread)
256 #else
257 TEST_F(CCLayerTreeHostTestSetNeedsCommit2, runMultiThread)
258 #endif
259 {
260     runTestThreaded();
261 }
262
263 // 1 setNeedsRedraw after the first commit has completed should lead to 1
264 // additional draw.
265 class CCLayerTreeHostTestSetNeedsRedraw : public CCLayerTreeHostTestThreadOnly {
266 public:
267     CCLayerTreeHostTestSetNeedsRedraw()
268         : m_numCommits(0)
269         , m_numDraws(0)
270     {
271     }
272
273     virtual void beginTest()
274     {
275         postSetNeedsCommitToMainThread();
276     }
277
278     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
279     {
280         EXPECT_EQ(0, impl->sourceFrameNumber());
281         if (!m_numDraws)
282             postSetNeedsRedrawToMainThread(); // Redraw again to verify that the second redraw doesn't commit.
283         else
284             endTest();
285         m_numDraws++;
286     }
287
288     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
289     {
290         EXPECT_EQ(0, m_numDraws);
291         m_numCommits++;
292     }
293
294     virtual void afterTest()
295     {
296         EXPECT_GE(2, m_numDraws);
297         EXPECT_EQ(1, m_numCommits);
298     }
299
300 private:
301     int m_numCommits;
302     int m_numDraws;
303 };
304
305 TEST_F(CCLayerTreeHostTestSetNeedsRedraw, runMultiThread)
306 {
307     runTestThreaded();
308 }
309
310 // If the layerTreeHost says it can't draw, then we should not try to draw.
311 class CCLayerTreeHostTestCanDrawBlocksDrawing : public CCLayerTreeHostTestThreadOnly {
312 public:
313     CCLayerTreeHostTestCanDrawBlocksDrawing()
314         : m_numCommits(0)
315     {
316     }
317
318     virtual void beginTest()
319     {
320         postSetNeedsCommitToMainThread();
321     }
322
323     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
324     {
325         // Only the initial draw should bring us here.
326         EXPECT_TRUE(impl->canDraw());
327         EXPECT_EQ(0, impl->sourceFrameNumber());
328     }
329
330     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
331     {
332         if (m_numCommits >= 1) {
333             // After the first commit, we should not be able to draw.
334             EXPECT_FALSE(impl->canDraw());
335         }
336     }
337
338     virtual void didCommit()
339     {
340         m_numCommits++;
341         if (m_numCommits == 1) {
342             // Make the viewport empty so the host says it can't draw.
343             m_layerTreeHost->setViewportSize(IntSize(0, 0));
344
345             OwnArrayPtr<char> pixels(adoptArrayPtr(new char[4]));
346             m_layerTreeHost->compositeAndReadback(static_cast<void*>(pixels.get()), IntRect(0, 0, 1, 1));
347         } else if (m_numCommits == 2) {
348             m_layerTreeHost->setNeedsRedraw();
349             m_layerTreeHost->setNeedsCommit();
350         } else
351             endTest();
352     }
353
354     virtual void afterTest()
355     {
356     }
357
358 private:
359     int m_numCommits;
360 };
361
362 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestCanDrawBlocksDrawing)
363
364 // beginLayerWrite should prevent draws from executing until a commit occurs
365 class CCLayerTreeHostTestWriteLayersRedraw : public CCLayerTreeHostTestThreadOnly {
366 public:
367     CCLayerTreeHostTestWriteLayersRedraw()
368         : m_numCommits(0)
369         , m_numDraws(0)
370     {
371     }
372
373     virtual void beginTest()
374     {
375         postAcquireLayerTextures();
376         postSetNeedsRedrawToMainThread(); // should be inhibited without blocking
377         postSetNeedsCommitToMainThread();
378     }
379
380     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
381     {
382         m_numDraws++;
383         EXPECT_EQ(m_numDraws, m_numCommits);
384     }
385
386     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
387     {
388         m_numCommits++;
389         endTest();
390     }
391
392     virtual void afterTest()
393     {
394         EXPECT_EQ(1, m_numCommits);
395     }
396
397 private:
398     int m_numCommits;
399     int m_numDraws;
400 };
401
402 TEST_F(CCLayerTreeHostTestWriteLayersRedraw, runMultiThread)
403 {
404     runTestThreaded();
405 }
406
407 // Verify that when resuming visibility, requesting layer write permission
408 // will not deadlock the main thread even though there are not yet any
409 // scheduled redraws. This behavior is critical for reliably surviving tab
410 // switching. There are no failure conditions to this test, it just passes
411 // by not timing out.
412 class CCLayerTreeHostTestWriteLayersAfterVisible : public CCLayerTreeHostTestThreadOnly {
413 public:
414     CCLayerTreeHostTestWriteLayersAfterVisible()
415         : m_numCommits(0)
416     {
417     }
418
419     virtual void beginTest()
420     {
421         postSetNeedsCommitToMainThread();
422     }
423
424     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
425     {
426         m_numCommits++;
427         if (m_numCommits == 2)
428             endTest();
429         else {
430             postSetVisibleToMainThread(false);
431             postSetVisibleToMainThread(true);
432             postAcquireLayerTextures();
433             postSetNeedsCommitToMainThread();
434         }
435     }
436
437     virtual void afterTest()
438     {
439     }
440
441 private:
442     int m_numCommits;
443 };
444
445 TEST_F(CCLayerTreeHostTestWriteLayersAfterVisible, runMultiThread)
446 {
447     runTestThreaded();
448 }
449
450 // A compositeAndReadback while invisible should force a normal commit without assertion.
451 class CCLayerTreeHostTestCompositeAndReadbackWhileInvisible : public CCLayerTreeHostTestThreadOnly {
452 public:
453     CCLayerTreeHostTestCompositeAndReadbackWhileInvisible()
454         : m_numCommits(0)
455     {
456     }
457
458     virtual void beginTest()
459     {
460     }
461
462     virtual void didCommitAndDrawFrame()
463     {
464         m_numCommits++;
465         if (m_numCommits == 1) {
466             m_layerTreeHost->setVisible(false);
467             m_layerTreeHost->setNeedsCommit();
468             m_layerTreeHost->setNeedsCommit();
469             OwnArrayPtr<char> pixels(adoptArrayPtr(new char[4]));
470             m_layerTreeHost->compositeAndReadback(static_cast<void*>(pixels.get()), IntRect(0, 0, 1, 1));
471         } else
472             endTest();
473
474     }
475
476     virtual void afterTest()
477     {
478     }
479
480 private:
481     int m_numCommits;
482 };
483
484 TEST_F(CCLayerTreeHostTestCompositeAndReadbackWhileInvisible, runMultiThread)
485 {
486     runTestThreaded();
487 }
488
489
490 // Trigger a frame with setNeedsCommit. Then, inside the resulting animate
491 // callback, requet another frame using setNeedsAnimate. End the test when
492 // animate gets called yet-again, indicating that the proxy is correctly
493 // handling the case where setNeedsAnimate() is called inside the begin frame
494 // flow.
495 class CCLayerTreeHostTestSetNeedsAnimateInsideAnimationCallback : public CCLayerTreeHostTestThreadOnly {
496 public:
497     CCLayerTreeHostTestSetNeedsAnimateInsideAnimationCallback()
498         : m_numAnimates(0)
499     {
500     }
501
502     virtual void beginTest()
503     {
504         postSetNeedsAnimateToMainThread();
505     }
506
507     virtual void updateAnimations(double)
508     {
509         if (!m_numAnimates) {
510             m_layerTreeHost->setNeedsAnimate();
511             m_numAnimates++;
512             return;
513         }
514         endTest();
515     }
516
517     virtual void afterTest()
518     {
519     }
520
521 private:
522     int m_numAnimates;
523 };
524
525 TEST_F(CCLayerTreeHostTestSetNeedsAnimateInsideAnimationCallback, runMultiThread)
526 {
527     runTestThreaded();
528 }
529
530 // Add a layer animation and confirm that CCLayerTreeHostImpl::animateLayers does get
531 // called and continues to get called.
532 class CCLayerTreeHostTestAddAnimation : public CCLayerTreeHostTestThreadOnly {
533 public:
534     CCLayerTreeHostTestAddAnimation()
535         : m_numAnimates(0)
536         , m_receivedAnimationStartedNotification(false)
537         , m_startTime(0)
538         , m_firstMonotonicTime(0)
539     {
540     }
541
542     virtual void beginTest()
543     {
544         postAddInstantAnimationToMainThread();
545     }
546
547     virtual void animateLayers(CCLayerTreeHostImpl* layerTreeHostImpl, double monotonicTime)
548     {
549         if (!m_numAnimates) {
550             // The animation had zero duration so layerTreeHostImpl should no
551             // longer need to animate its layers.
552             EXPECT_FALSE(layerTreeHostImpl->needsAnimateLayers());
553             m_numAnimates++;
554             m_firstMonotonicTime = monotonicTime;
555             return;
556         }
557         EXPECT_LT(0, m_startTime);
558         EXPECT_LT(0, m_firstMonotonicTime);
559         EXPECT_NE(m_startTime, m_firstMonotonicTime);
560         EXPECT_TRUE(m_receivedAnimationStartedNotification);
561         endTest();
562     }
563
564     virtual void notifyAnimationStarted(double wallClockTime)
565     {
566         m_receivedAnimationStartedNotification = true;
567         m_startTime = wallClockTime;
568     }
569
570     virtual void afterTest()
571     {
572     }
573
574 private:
575     int m_numAnimates;
576     bool m_receivedAnimationStartedNotification;
577     double m_startTime;
578     double m_firstMonotonicTime;
579 };
580
581 TEST_F(CCLayerTreeHostTestAddAnimation, runMultiThread)
582 {
583     runTestThreaded();
584 }
585
586 // Add a layer animation to a layer, but continually fail to draw. Confirm that after
587 // a while, we do eventually force a draw.
588 class CCLayerTreeHostTestCheckerboardDoesNotStarveDraws : public CCLayerTreeHostTestThreadOnly {
589 public:
590     CCLayerTreeHostTestCheckerboardDoesNotStarveDraws()
591         : m_startedAnimating(false)
592     {
593     }
594
595     virtual void beginTest()
596     {
597         postAddAnimationToMainThread();
598     }
599
600     virtual void afterTest()
601     {
602     }
603
604     virtual void animateLayers(CCLayerTreeHostImpl* layerTreeHostImpl, double monotonicTime)
605     {
606         m_startedAnimating = true;
607     }
608
609     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*)
610     {
611         if (m_startedAnimating)
612             endTest();
613     }
614
615     virtual bool prepareToDrawOnCCThread(CCLayerTreeHostImpl*)
616     {
617         return false;
618     }
619
620 private:
621     bool m_startedAnimating;
622 };
623
624 // Starvation can only be an issue with the MT compositor.
625 TEST_F(CCLayerTreeHostTestCheckerboardDoesNotStarveDraws, runMultiThread)
626 {
627     runTestThreaded();
628 }
629
630 // Ensures that animations continue to be ticked when we are backgrounded.
631 class CCLayerTreeHostTestTickAnimationWhileBackgrounded : public CCLayerTreeHostTestThreadOnly {
632 public:
633     CCLayerTreeHostTestTickAnimationWhileBackgrounded()
634         : m_numAnimates(0)
635     {
636     }
637
638     virtual void beginTest()
639     {
640         postAddAnimationToMainThread();
641     }
642
643     // Use willAnimateLayers to set visible false before the animation runs and
644     // causes a commit, so we block the second visible animate in single-thread
645     // mode.
646     virtual void willAnimateLayers(CCLayerTreeHostImpl* layerTreeHostImpl, double monotonicTime)
647     {
648         if (m_numAnimates < 2) {
649             if (!m_numAnimates) {
650                 // We have a long animation running. It should continue to tick even if we are not visible.
651                 postSetVisibleToMainThread(false);
652             }
653             m_numAnimates++;
654             return;
655         }
656         endTest();
657     }
658
659     virtual void afterTest()
660     {
661     }
662
663 private:
664     int m_numAnimates;
665 };
666
667 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestTickAnimationWhileBackgrounded)
668
669 // Ensures that animations continue to be ticked when we are backgrounded.
670 class CCLayerTreeHostTestAddAnimationWithTimingFunction : public CCLayerTreeHostTestThreadOnly {
671 public:
672     CCLayerTreeHostTestAddAnimationWithTimingFunction()
673     {
674     }
675
676     virtual void beginTest()
677     {
678         postAddAnimationToMainThread();
679     }
680
681     virtual void animateLayers(CCLayerTreeHostImpl* layerTreeHostImpl, double monotonicTime)
682     {
683         const CCActiveAnimation* animation = m_layerTreeHost->rootLayer()->layerAnimationController()->getActiveAnimation(0, CCActiveAnimation::Opacity);
684         if (!animation)
685             return;
686         const CCFloatAnimationCurve* curve = animation->curve()->toFloatAnimationCurve();
687         float startOpacity = curve->getValue(0);
688         float endOpacity = curve->getValue(curve->duration());
689         float linearlyInterpolatedOpacity = 0.25 * endOpacity + 0.75 * startOpacity;
690         double time = curve->duration() * 0.25;
691         // If the linear timing function associated with this animation was not picked up,
692         // then the linearly interpolated opacity would be different because of the
693         // default ease timing function.
694         EXPECT_FLOAT_EQ(linearlyInterpolatedOpacity, curve->getValue(time));
695         endTest();
696     }
697
698     virtual void afterTest()
699     {
700     }
701
702 private:
703 };
704
705 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestAddAnimationWithTimingFunction)
706
707 // Ensures that when opacity is being animated, this value does not cause the subtree to be skipped.
708 class CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity : public CCLayerTreeHostTestThreadOnly {
709 public:
710     CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity()
711     {
712     }
713
714     virtual void beginTest()
715     {
716         m_layerTreeHost->rootLayer()->setDrawOpacity(1);
717         m_layerTreeHost->setViewportSize(IntSize(10, 10));
718         m_layerTreeHost->rootLayer()->setOpacity(0);
719         postAddAnimationToMainThread();
720     }
721
722     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
723     {
724         // If the subtree was skipped when preparing to draw, the layer's draw opacity
725         // will not have been updated. It should be set to 0 due to the animation.
726         // Without the animation, the layer will be skipped since it has zero opacity.
727         EXPECT_EQ(0, m_layerTreeHost->rootLayer()->drawOpacity());
728         endTest();
729     }
730
731     virtual void afterTest()
732     {
733     }
734 };
735
736 #if OS(WINDOWS)
737 // http://webkit.org/b/74623
738 TEST_F(CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, FLAKY_runMultiThread)
739 #else
740 TEST_F(CCLayerTreeHostTestDoNotSkipLayersWithAnimatedOpacity, runMultiThread)
741 #endif
742 {
743     runTestThreaded();
744 }
745
746 // Ensures that main thread animations have their start times synchronized with impl thread animations.
747 class CCLayerTreeHostTestSynchronizeAnimationStartTimes : public CCLayerTreeHostTestThreadOnly {
748 public:
749     CCLayerTreeHostTestSynchronizeAnimationStartTimes()
750         : m_layerTreeHostImpl(0)
751     {
752     }
753
754     virtual void beginTest()
755     {
756         postAddAnimationToMainThread();
757     }
758
759     // This is guaranteed to be called before CCLayerTreeHostImpl::animateLayers.
760     virtual void willAnimateLayers(CCLayerTreeHostImpl* layerTreeHostImpl, double monotonicTime)
761     {
762         m_layerTreeHostImpl = layerTreeHostImpl;
763     }
764
765     virtual void notifyAnimationStarted(double time)
766     {
767         EXPECT_TRUE(m_layerTreeHostImpl);
768
769         CCLayerAnimationController* controllerImpl = m_layerTreeHostImpl->rootLayer()->layerAnimationController();
770         CCLayerAnimationController* controller = m_layerTreeHost->rootLayer()->layerAnimationController();
771         CCActiveAnimation* animationImpl = controllerImpl->getActiveAnimation(0, CCActiveAnimation::Opacity);
772         CCActiveAnimation* animation = controller->getActiveAnimation(0, CCActiveAnimation::Opacity);
773
774         EXPECT_EQ(animationImpl->startTime(), animation->startTime());
775
776         endTest();
777     }
778
779     virtual void afterTest()
780     {
781     }
782
783 private:
784     CCLayerTreeHostImpl* m_layerTreeHostImpl;
785 };
786
787 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestSynchronizeAnimationStartTimes)
788
789 // Ensures that main thread animations have their start times synchronized with impl thread animations.
790 class CCLayerTreeHostTestAnimationFinishedEvents : public CCLayerTreeHostTestThreadOnly {
791 public:
792     CCLayerTreeHostTestAnimationFinishedEvents()
793     {
794     }
795
796     virtual void beginTest()
797     {
798         postAddInstantAnimationToMainThread();
799     }
800
801     virtual void notifyAnimationFinished(double time)
802     {
803         endTest();
804     }
805
806     virtual void afterTest()
807     {
808     }
809
810 private:
811 };
812
813 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestAnimationFinishedEvents)
814
815 class CCLayerTreeHostTestScrollSimple : public CCLayerTreeHostTestThreadOnly {
816 public:
817     CCLayerTreeHostTestScrollSimple()
818         : m_initialScroll(IntPoint(10, 20))
819         , m_secondScroll(IntPoint(40, 5))
820         , m_scrollAmount(2, -1)
821         , m_scrolls(0)
822     {
823     }
824
825     virtual void beginTest()
826     {
827         m_layerTreeHost->rootLayer()->setScrollable(true);
828         m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll);
829         postSetNeedsCommitToMainThread();
830     }
831
832     virtual void layout()
833     {
834         LayerChromium* root = m_layerTreeHost->rootLayer();
835         if (!m_layerTreeHost->frameNumber())
836             EXPECT_EQ(root->scrollPosition(), m_initialScroll);
837         else {
838             EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount);
839
840             // Pretend like Javascript updated the scroll position itself.
841             root->setScrollPosition(m_secondScroll);
842         }
843     }
844
845     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
846     {
847         CCLayerImpl* root = impl->rootLayer();
848         EXPECT_EQ(root->scrollDelta(), IntSize());
849
850         root->setScrollable(true);
851         root->setMaxScrollPosition(IntSize(100, 100));
852         root->scrollBy(m_scrollAmount);
853
854         if (!impl->sourceFrameNumber()) {
855             EXPECT_EQ(root->scrollPosition(), m_initialScroll);
856             EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
857             postSetNeedsCommitToMainThread();
858         } else if (impl->sourceFrameNumber() == 1) {
859             EXPECT_EQ(root->scrollPosition(), m_secondScroll);
860             EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
861             endTest();
862         }
863     }
864
865     virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale)
866     {
867         IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
868         m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
869         m_scrolls++;
870     }
871
872     virtual void afterTest()
873     {
874         EXPECT_EQ(1, m_scrolls);
875     }
876 private:
877     IntPoint m_initialScroll;
878     IntPoint m_secondScroll;
879     IntSize m_scrollAmount;
880     int m_scrolls;
881 };
882
883 TEST_F(CCLayerTreeHostTestScrollSimple, DISABLED_runMultiThread)
884 {
885     runTestThreaded();
886 }
887
888 class CCLayerTreeHostTestScrollMultipleRedraw : public CCLayerTreeHostTestThreadOnly {
889 public:
890     CCLayerTreeHostTestScrollMultipleRedraw()
891         : m_initialScroll(IntPoint(40, 10))
892         , m_scrollAmount(-3, 17)
893         , m_scrolls(0)
894     {
895     }
896
897     virtual void beginTest()
898     {
899         m_layerTreeHost->rootLayer()->setScrollable(true);
900         m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll);
901         postSetNeedsCommitToMainThread();
902     }
903
904     virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl)
905     {
906         LayerChromium* root = m_layerTreeHost->rootLayer();
907         if (!impl->sourceFrameNumber())
908             EXPECT_EQ(root->scrollPosition(), m_initialScroll);
909         else if (impl->sourceFrameNumber() == 1)
910             EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
911         else if (impl->sourceFrameNumber() == 2)
912             EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
913     }
914
915     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
916     {
917         CCLayerImpl* root = impl->rootLayer();
918         root->setScrollable(true);
919         root->setMaxScrollPosition(IntSize(100, 100));
920
921         if (!impl->sourceFrameNumber() && impl->frameNumber() == 1) {
922             // First draw after first commit.
923             EXPECT_EQ(root->scrollDelta(), IntSize());
924             root->scrollBy(m_scrollAmount);
925             EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
926
927             EXPECT_EQ(root->scrollPosition(), m_initialScroll);
928             postSetNeedsRedrawToMainThread();
929         } else if (!impl->sourceFrameNumber() && impl->frameNumber() == 2) {
930             // Second draw after first commit.
931             EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
932             root->scrollBy(m_scrollAmount);
933             EXPECT_EQ(root->scrollDelta(), m_scrollAmount + m_scrollAmount);
934
935             EXPECT_EQ(root->scrollPosition(), m_initialScroll);
936             postSetNeedsCommitToMainThread();
937         } else if (impl->sourceFrameNumber() == 1) {
938             // Third or later draw after second commit.
939             EXPECT_GE(impl->frameNumber(), 3);
940             EXPECT_EQ(root->scrollDelta(), IntSize());
941             EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
942             endTest();
943         }
944     }
945
946     virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale)
947     {
948         IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
949         m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
950         m_scrolls++;
951     }
952
953     virtual void afterTest()
954     {
955         EXPECT_EQ(1, m_scrolls);
956     }
957 private:
958     IntPoint m_initialScroll;
959     IntSize m_scrollAmount;
960     int m_scrolls;
961 };
962
963 TEST_F(CCLayerTreeHostTestScrollMultipleRedraw, DISABLED_runMultiThread)
964 {
965     runTestThreaded();
966 }
967
968 // This test verifies that properties on the layer tree host are commited to the impl side.
969 class CCLayerTreeHostTestCommit : public CCLayerTreeHostTest {
970 public:
971
972     CCLayerTreeHostTestCommit() { }
973
974     virtual void beginTest()
975     {
976         m_layerTreeHost->setViewportSize(IntSize(20, 20));
977         m_layerTreeHost->setBackgroundColor(Color::gray);
978         m_layerTreeHost->setPageScaleFactorAndLimits(5, 5, 5);
979
980         postSetNeedsCommitToMainThread();
981     }
982
983     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
984     {
985         EXPECT_EQ(IntSize(20, 20), impl->viewportSize());
986         EXPECT_EQ(Color::gray, impl->backgroundColor());
987         EXPECT_EQ(5, impl->pageScale());
988
989         endTest();
990     }
991
992     virtual void afterTest() { }
993 };
994
995 TEST_F(CCLayerTreeHostTestCommit, runTest)
996 {
997     runTest(true);
998 }
999
1000 class CCLayerTreeHostTestVisibilityAndAllocationControlDrawing : public CCLayerTreeHostTest {
1001 public:
1002
1003     CCLayerTreeHostTestVisibilityAndAllocationControlDrawing() { }
1004
1005     virtual void beginTest()
1006     {
1007         postSetNeedsCommitToMainThread();
1008     }
1009
1010     virtual void didCommitAndDrawFrame()
1011     {
1012         int lastFrame = m_layerTreeHost->frameNumber() - 1;
1013
1014         // These frames should draw.
1015         switch (lastFrame) {
1016         case 0:
1017             // Set the tree invisible, this should not draw.
1018             m_layerTreeHost->setVisible(false);
1019             break;
1020         case 2:
1021             // Set the tree invisible and give a non-visible allocation, this
1022             // should not draw.
1023             m_layerTreeHost->setVisible(false);
1024             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(0);
1025             break;
1026         case 5:
1027             // Give a memory allocation not for display, but while we are
1028             // visible. This should not be used and we should remain
1029             // ready for display and it should draw.
1030             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(0);
1031             break;
1032         case 6:
1033             endTest();
1034             break;
1035
1036         default:
1037             ASSERT_NOT_REACHED();
1038         }
1039     }
1040
1041     virtual void didCommit()
1042     {
1043         int lastFrame = m_layerTreeHost->frameNumber() - 1;
1044
1045         // These frames should not draw.
1046         switch (lastFrame) {
1047         case 1:
1048             // Set the tree visible, this should draw.
1049             m_layerTreeHost->setVisible(true);
1050             break;
1051         case 3:
1052             // Set visible without giving a visible memory allocation, this
1053             // shouldn't make the impl side ready for display, so it should
1054             // not draw.
1055             m_layerTreeHost->setVisible(true);
1056             break;
1057         case 4:
1058             // Now give a memory allocation for display, this should draw.
1059             m_layerTreeHost->setContentsMemoryAllocationLimitBytes(1);
1060             break;
1061         }
1062     }
1063
1064     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
1065     {
1066         switch (impl->sourceFrameNumber()) {
1067         case 0:
1068             // The host starts out visible and able to display before we do any commit.
1069             EXPECT_TRUE(impl->visible());
1070             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
1071             break;
1072         case 1:
1073             // We still have a memory allocation for display.
1074             EXPECT_FALSE(impl->visible());
1075             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
1076             break;
1077         case 2:
1078             EXPECT_TRUE(impl->visible());
1079             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
1080             break;
1081         case 3:
1082             EXPECT_FALSE(impl->visible());
1083             EXPECT_FALSE(impl->sourceFrameCanBeDrawn());
1084             break;
1085         case 4:
1086             EXPECT_TRUE(impl->visible());
1087             EXPECT_FALSE(impl->sourceFrameCanBeDrawn());
1088             break;
1089         case 5:
1090             EXPECT_TRUE(impl->visible());
1091             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
1092             break;
1093         case 6:
1094             EXPECT_TRUE(impl->visible());
1095             EXPECT_TRUE(impl->sourceFrameCanBeDrawn());
1096             break;
1097         }
1098     }
1099
1100     virtual void afterTest()
1101     {
1102     }
1103 };
1104
1105 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestVisibilityAndAllocationControlDrawing)
1106
1107 // Verifies that startPageScaleAnimation events propagate correctly from CCLayerTreeHost to
1108 // CCLayerTreeHostImpl in the MT compositor.
1109 class CCLayerTreeHostTestStartPageScaleAnimation : public CCLayerTreeHostTest {
1110 public:
1111
1112     CCLayerTreeHostTestStartPageScaleAnimation()
1113         : m_animationRequested(false)
1114     {
1115     }
1116
1117     virtual void beginTest()
1118     {
1119         m_layerTreeHost->rootLayer()->setScrollable(true);
1120         m_layerTreeHost->rootLayer()->setScrollPosition(IntPoint());
1121         postSetNeedsRedrawToMainThread();
1122     }
1123
1124     static void requestStartPageScaleAnimation(void* self)
1125     {
1126         CCLayerTreeHostTestStartPageScaleAnimation* test = static_cast<CCLayerTreeHostTestStartPageScaleAnimation*>(self);
1127         if (test->layerTreeHost())
1128             test->layerTreeHost()->startPageScaleAnimation(IntSize(), false, 1.25, 0);
1129     }
1130
1131     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
1132     {
1133         impl->rootLayer()->setScrollable(true);
1134         impl->rootLayer()->setScrollPosition(IntPoint());
1135         impl->setPageScaleFactorAndLimits(impl->pageScale(), 0.5, 2);
1136
1137         // We request animation only once.
1138         if (!m_animationRequested) {
1139             callOnMainThread(CCLayerTreeHostTestStartPageScaleAnimation::requestStartPageScaleAnimation, this);
1140             m_animationRequested = true;
1141         }
1142     }
1143
1144     virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale)
1145     {
1146         IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
1147         m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
1148         m_layerTreeHost->setPageScaleFactorAndLimits(scale, 0.5, 2);
1149     }
1150
1151     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
1152     {
1153         impl->processScrollDeltas();
1154         // We get one commit before the first draw, and the animation doesn't happen until the second draw.
1155         if (impl->sourceFrameNumber() == 1) {
1156             EXPECT_EQ(1.25, impl->pageScale());
1157             endTest();
1158         } else
1159             postSetNeedsRedrawToMainThread();
1160     }
1161
1162     virtual void afterTest()
1163     {
1164     }
1165
1166 private:
1167     bool m_animationRequested;
1168 };
1169
1170 TEST_F(CCLayerTreeHostTestStartPageScaleAnimation, runTest)
1171 {
1172     runTest(true);
1173 }
1174
1175 class CCLayerTreeHostTestSetVisible : public CCLayerTreeHostTest {
1176 public:
1177
1178     CCLayerTreeHostTestSetVisible()
1179         : m_numDraws(0)
1180     {
1181     }
1182
1183     virtual void beginTest()
1184     {
1185         postSetVisibleToMainThread(false);
1186         postSetNeedsRedrawToMainThread(); // This is suppressed while we're invisible.
1187         postSetVisibleToMainThread(true); // Triggers the redraw.
1188     }
1189
1190     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
1191     {
1192         EXPECT_TRUE(impl->visible());
1193         ++m_numDraws;
1194         endTest();
1195     }
1196
1197     virtual void afterTest()
1198     {
1199         EXPECT_EQ(1, m_numDraws);
1200     }
1201
1202 private:
1203     int m_numDraws;
1204 };
1205
1206 TEST_F(CCLayerTreeHostTestSetVisible, runMultiThread)
1207 {
1208     runTest(true);
1209 }
1210
1211 class TestOpacityChangeLayerDelegate : public ContentLayerDelegate {
1212 public:
1213     TestOpacityChangeLayerDelegate(CCLayerTreeHostTest* test)
1214         : m_test(test)
1215     {
1216     }
1217
1218     virtual void paintContents(SkCanvas*, const IntRect&, IntRect&)
1219     {
1220         // Set layer opacity to 0.
1221         m_test->layerTreeHost()->rootLayer()->setOpacity(0);
1222     }
1223
1224     virtual bool preserves3D() { return false; }
1225
1226 private:
1227     CCLayerTreeHostTest* m_test;
1228 };
1229
1230 class ContentLayerChromiumWithUpdateTracking : public ContentLayerChromium {
1231 public:
1232     static PassRefPtr<ContentLayerChromiumWithUpdateTracking> create(ContentLayerDelegate *delegate) { return adoptRef(new ContentLayerChromiumWithUpdateTracking(delegate)); }
1233
1234     int paintContentsCount() { return m_paintContentsCount; }
1235     int idlePaintContentsCount() { return m_idlePaintContentsCount; }
1236     void resetPaintContentsCount() { m_paintContentsCount = 0; m_idlePaintContentsCount = 0;}
1237
1238     virtual void update(CCTextureUpdater& updater, const CCOcclusionTracker* occlusion) OVERRIDE
1239     {
1240         ContentLayerChromium::update(updater, occlusion);
1241         m_paintContentsCount++;
1242     }
1243
1244     virtual void idleUpdate(CCTextureUpdater& updater, const CCOcclusionTracker* occlusion) OVERRIDE
1245     {
1246         ContentLayerChromium::idleUpdate(updater, occlusion);
1247         m_idlePaintContentsCount++;
1248     }
1249
1250 private:
1251     explicit ContentLayerChromiumWithUpdateTracking(ContentLayerDelegate* delegate)
1252         : ContentLayerChromium(delegate)
1253         , m_paintContentsCount(0)
1254         , m_idlePaintContentsCount(0)
1255     {
1256         setBounds(IntSize(10, 10));
1257         setIsDrawable(true);
1258     }
1259
1260     int m_paintContentsCount;
1261     int m_idlePaintContentsCount;
1262 };
1263
1264 // Layer opacity change during paint should not prevent compositor resources from being updated during commit.
1265 class CCLayerTreeHostTestOpacityChange : public CCLayerTreeHostTest {
1266 public:
1267     CCLayerTreeHostTestOpacityChange()
1268         : m_testOpacityChangeDelegate(this)
1269         , m_updateCheckLayer(ContentLayerChromiumWithUpdateTracking::create(&m_testOpacityChangeDelegate))
1270     {
1271     }
1272
1273     virtual void beginTest()
1274     {
1275         m_layerTreeHost->setRootLayer(m_updateCheckLayer);
1276         m_layerTreeHost->setViewportSize(IntSize(10, 10));
1277
1278         postSetNeedsCommitToMainThread();
1279     }
1280
1281     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*)
1282     {
1283         endTest();
1284     }
1285
1286     virtual void afterTest()
1287     {
1288         // update() should have been called once.
1289         EXPECT_EQ(1, m_updateCheckLayer->paintContentsCount());
1290
1291         // idleUpdate() should have been called once
1292         EXPECT_EQ(1, m_updateCheckLayer->idlePaintContentsCount());
1293
1294         // clear m_updateCheckLayer so CCLayerTreeHost dies.
1295         m_updateCheckLayer.clear();
1296     }
1297
1298 private:
1299     TestOpacityChangeLayerDelegate m_testOpacityChangeDelegate;
1300     RefPtr<ContentLayerChromiumWithUpdateTracking> m_updateCheckLayer;
1301 };
1302
1303 TEST_F(CCLayerTreeHostTestOpacityChange, runMultiThread)
1304 {
1305     runTest(true);
1306 }
1307
1308 class MockContentLayerDelegate : public ContentLayerDelegate {
1309 public:
1310     bool drawsContent() const { return true; }
1311     MOCK_CONST_METHOD0(preserves3D, bool());
1312     void paintContents(SkCanvas*, const IntRect&, IntRect&) { }
1313     void notifySyncRequired() { }
1314 };
1315
1316 class CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers : public CCLayerTreeHostTest {
1317 public:
1318
1319     CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers()
1320         : m_rootLayer(ContentLayerChromium::create(&m_delegate))
1321         , m_childLayer(ContentLayerChromium::create(&m_delegate))
1322     {
1323     }
1324
1325     virtual void beginTest()
1326     {
1327         // The device viewport should be scaled by the device scale factor.
1328         m_layerTreeHost->setViewportSize(IntSize(40, 40));
1329         m_layerTreeHost->setDeviceScaleFactor(1.5);
1330         EXPECT_EQ(IntSize(40, 40), m_layerTreeHost->viewportSize());
1331         EXPECT_EQ(IntSize(60, 60), m_layerTreeHost->deviceViewportSize());
1332
1333         m_rootLayer->addChild(m_childLayer);
1334
1335         m_rootLayer->setIsDrawable(true);
1336         m_rootLayer->setBounds(IntSize(30, 30));
1337         m_rootLayer->setAnchorPoint(FloatPoint(0, 0));
1338
1339         m_childLayer->setIsDrawable(true);
1340         m_childLayer->setPosition(IntPoint(2, 2));
1341         m_childLayer->setBounds(IntSize(10, 10));
1342         m_childLayer->setAnchorPoint(FloatPoint(0, 0));
1343
1344         m_layerTreeHost->setRootLayer(m_rootLayer);
1345     }
1346
1347     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
1348     {
1349         // Get access to protected methods.
1350         MockLayerTreeHostImpl* mockImpl = static_cast<MockLayerTreeHostImpl*>(impl);
1351
1352         // Should only do one commit.
1353         EXPECT_EQ(0, impl->sourceFrameNumber());
1354         // Device scale factor should come over to impl.
1355         EXPECT_NEAR(impl->deviceScaleFactor(), 1.5, 0.00001);
1356
1357         // Both layers are on impl.
1358         ASSERT_EQ(1u, impl->rootLayer()->children().size());
1359
1360         // Device viewport is scaled.
1361         EXPECT_EQ(IntSize(40, 40), impl->viewportSize());
1362         EXPECT_EQ(IntSize(60, 60), impl->deviceViewportSize());
1363
1364         CCLayerImpl* root = impl->rootLayer();
1365         CCLayerImpl* child = impl->rootLayer()->children()[0].get();
1366
1367         // Positions remain in layout pixels.
1368         EXPECT_EQ(IntPoint(0, 0), root->position());
1369         EXPECT_EQ(IntPoint(2, 2), child->position());
1370
1371         // Compute all the layer transforms for the frame.
1372         MockLayerTreeHostImpl::CCLayerList renderSurfaceLayerList;
1373         mockImpl->calculateRenderSurfaceLayerList(renderSurfaceLayerList);
1374
1375         // Both layers should be drawing into the root render surface.
1376         ASSERT_EQ(1u, renderSurfaceLayerList.size());
1377         ASSERT_EQ(root->renderSurface(), renderSurfaceLayerList[0]->renderSurface());
1378         ASSERT_EQ(2u, root->renderSurface()->layerList().size());
1379
1380         // The root render surface is the size of the viewport.
1381         EXPECT_EQ_RECT(IntRect(0, 0, 60, 60), root->renderSurface()->contentRect());
1382
1383         WebTransformationMatrix scaleTransform;
1384         scaleTransform.scale(impl->deviceScaleFactor());
1385
1386         // The root layer is scaled by 2x.
1387         WebTransformationMatrix rootScreenSpaceTransform = scaleTransform;
1388         WebTransformationMatrix rootDrawTransform = scaleTransform;
1389         rootDrawTransform.translate(root->bounds().width() * 0.5, root->bounds().height() * 0.5);
1390
1391         EXPECT_EQ(rootDrawTransform, root->drawTransform());
1392         EXPECT_EQ(rootScreenSpaceTransform, root->screenSpaceTransform());
1393
1394         // The child is at position 2,2, so translate by 2,2 before applying the scale by 2x.
1395         WebTransformationMatrix childScreenSpaceTransform = scaleTransform;
1396         childScreenSpaceTransform.translate(2, 2);
1397         WebTransformationMatrix childDrawTransform = scaleTransform;
1398         childDrawTransform.translate(2, 2);
1399         childDrawTransform.translate(child->bounds().width() * 0.5, child->bounds().height() * 0.5);
1400
1401         EXPECT_EQ(childDrawTransform, child->drawTransform());
1402         EXPECT_EQ(childScreenSpaceTransform, child->screenSpaceTransform());
1403
1404         endTest();
1405     }
1406
1407     virtual void afterTest()
1408     {
1409         m_rootLayer.clear();
1410         m_childLayer.clear();
1411     }
1412
1413 private:
1414     MockContentLayerDelegate m_delegate;
1415     RefPtr<ContentLayerChromium> m_rootLayer;
1416     RefPtr<ContentLayerChromium> m_childLayer;
1417 };
1418
1419 TEST_F(CCLayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers, runMultiThread)
1420 {
1421     runTest(true);
1422 }
1423
1424 // Verify atomicity of commits and reuse of textures.
1425 class CCLayerTreeHostTestAtomicCommit : public CCLayerTreeHostTest {
1426 public:
1427     CCLayerTreeHostTestAtomicCommit()
1428         : m_layer(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
1429     {
1430         // Make sure partial texture updates are turned off.
1431         m_settings.maxPartialTextureUpdates = 0;
1432     }
1433
1434     virtual void beginTest()
1435     {
1436         m_layerTreeHost->setRootLayer(m_layer);
1437         m_layerTreeHost->setViewportSize(IntSize(10, 10));
1438
1439         postSetNeedsCommitToMainThread();
1440         postSetNeedsRedrawToMainThread();
1441     }
1442
1443     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
1444     {
1445         CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()->context3D()));
1446
1447         switch (impl->sourceFrameNumber()) {
1448         case 0:
1449             // Number of textures should be one.
1450             ASSERT_EQ(1, context->numTextures());
1451             // Number of textures used for commit should be one.
1452             EXPECT_EQ(1, context->numUsedTextures());
1453             // Verify that used texture is correct.
1454             EXPECT_TRUE(context->usedTexture(context->texture(0)));
1455
1456             context->resetUsedTextures();
1457             break;
1458         case 1:
1459             // Number of textures should be two as the first texture
1460             // is used by impl thread and cannot by used for update.
1461             ASSERT_EQ(2, context->numTextures());
1462             // Number of textures used for commit should still be one.
1463             EXPECT_EQ(1, context->numUsedTextures());
1464             // First texture should not have been used.
1465             EXPECT_FALSE(context->usedTexture(context->texture(0)));
1466             // New texture should have been used.
1467             EXPECT_TRUE(context->usedTexture(context->texture(1)));
1468
1469             context->resetUsedTextures();
1470             break;
1471         default:
1472             ASSERT_NOT_REACHED();
1473             break;
1474         }
1475     }
1476
1477     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
1478     {
1479         CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()->context3D()));
1480
1481         // Number of textures used for draw should always be one.
1482         EXPECT_EQ(1, context->numUsedTextures());
1483
1484         if (impl->sourceFrameNumber() < 1) {
1485             context->resetUsedTextures();
1486             postSetNeedsAnimateAndCommitToMainThread();
1487             postSetNeedsRedrawToMainThread();
1488         } else
1489             endTest();
1490     }
1491
1492     virtual void layout()
1493     {
1494         m_layer->setNeedsDisplay();
1495     }
1496
1497     virtual void afterTest()
1498     {
1499     }
1500
1501 private:
1502     MockContentLayerDelegate m_delegate;
1503     RefPtr<ContentLayerChromiumWithUpdateTracking> m_layer;
1504 };
1505
1506 TEST_F(CCLayerTreeHostTestAtomicCommit, runMultiThread)
1507 {
1508     runTest(true);
1509 }
1510
1511 static void setLayerPropertiesForTesting(LayerChromium* layer, LayerChromium* parent, const WebTransformationMatrix& transform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool opaque)
1512 {
1513     layer->removeAllChildren();
1514     if (parent)
1515         parent->addChild(layer);
1516     layer->setTransform(transform);
1517     layer->setAnchorPoint(anchor);
1518     layer->setPosition(position);
1519     layer->setBounds(bounds);
1520     layer->setOpaque(opaque);
1521 }
1522
1523 class CCLayerTreeHostTestAtomicCommitWithPartialUpdate : public CCLayerTreeHostTest {
1524 public:
1525     CCLayerTreeHostTestAtomicCommitWithPartialUpdate()
1526         : m_parent(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
1527         , m_child(ContentLayerChromiumWithUpdateTracking::create(&m_delegate))
1528         , m_numCommits(0)
1529     {
1530         // Allow one partial texture update.
1531         m_settings.maxPartialTextureUpdates = 1;
1532     }
1533
1534     virtual void beginTest()
1535     {
1536         m_layerTreeHost->setRootLayer(m_parent);
1537         m_layerTreeHost->setViewportSize(IntSize(10, 20));
1538
1539         WebTransformationMatrix identityMatrix;
1540         setLayerPropertiesForTesting(m_parent.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 20), true);
1541         setLayerPropertiesForTesting(m_child.get(), m_parent.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(0, 10), IntSize(10, 10), false);
1542
1543         postSetNeedsCommitToMainThread();
1544         postSetNeedsRedrawToMainThread();
1545     }
1546
1547     virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
1548     {
1549         CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()->context3D()));
1550
1551         switch (impl->sourceFrameNumber()) {
1552         case 0:
1553             // Number of textures should be two.
1554             ASSERT_EQ(2, context->numTextures());
1555             // Number of textures used for commit should be two.
1556             EXPECT_EQ(2, context->numUsedTextures());
1557             // Verify that used textures are correct.
1558             EXPECT_TRUE(context->usedTexture(context->texture(0)));
1559             EXPECT_TRUE(context->usedTexture(context->texture(1)));
1560
1561             context->resetUsedTextures();
1562             break;
1563         case 1:
1564             // Number of textures should be four as the first two
1565             // textures are used by the impl thread.
1566             ASSERT_EQ(4, context->numTextures());
1567             // Number of textures used for commit should still be two.
1568             EXPECT_EQ(2, context->numUsedTextures());
1569             // First two textures should not have been used.
1570             EXPECT_FALSE(context->usedTexture(context->texture(0)));
1571             EXPECT_FALSE(context->usedTexture(context->texture(1)));
1572             // New textures should have been used.
1573             EXPECT_TRUE(context->usedTexture(context->texture(2)));
1574             EXPECT_TRUE(context->usedTexture(context->texture(3)));
1575
1576             context->resetUsedTextures();
1577             break;
1578         case 2:
1579             // Number of textures should be three as we allow one
1580             // partial update and the first two textures are used by
1581             // the impl thread.
1582             ASSERT_EQ(3, context->numTextures());
1583             // Number of textures used for commit should still be two.
1584             EXPECT_EQ(2, context->numUsedTextures());
1585             // First texture should have been used.
1586             EXPECT_TRUE(context->usedTexture(context->texture(0)));
1587             // Second texture should not have been used.
1588             EXPECT_FALSE(context->usedTexture(context->texture(1)));
1589             // Third texture should have been used.
1590             EXPECT_TRUE(context->usedTexture(context->texture(2)));
1591
1592             context->resetUsedTextures();
1593             break;
1594         case 3:
1595             // Number of textures should be two.
1596             EXPECT_EQ(2, context->numTextures());
1597             // No textures should be used for commit.
1598             EXPECT_EQ(0, context->numUsedTextures());
1599
1600             context->resetUsedTextures();
1601             break;
1602         case 4:
1603             // Number of textures should be two.
1604             EXPECT_EQ(2, context->numTextures());
1605             // Number of textures used for commit should be one.
1606             EXPECT_EQ(1, context->numUsedTextures());
1607
1608             context->resetUsedTextures();
1609             break;
1610         default:
1611             ASSERT_NOT_REACHED();
1612             break;
1613         }
1614     }
1615
1616     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
1617     {
1618         CompositorFakeWebGraphicsContext3DWithTextureTracking* context = static_cast<CompositorFakeWebGraphicsContext3DWithTextureTracking*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(impl->context()->context3D()));
1619
1620         // Number of textures used for drawing should two except for frame 4
1621         // where the viewport only contains one layer.
1622         if (impl->sourceFrameNumber() == 3)
1623             EXPECT_EQ(1, context->numUsedTextures());
1624         else
1625             EXPECT_EQ(2, context->numUsedTextures());
1626
1627         if (impl->sourceFrameNumber() < 4) {
1628             context->resetUsedTextures();
1629             postSetNeedsAnimateAndCommitToMainThread();
1630             postSetNeedsRedrawToMainThread();
1631         } else
1632             endTest();
1633     }
1634
1635     virtual void layout()
1636     {
1637         switch (m_numCommits++) {
1638         case 0:
1639         case 1:
1640             m_parent->setNeedsDisplay();
1641             m_child->setNeedsDisplay();
1642             break;
1643         case 2:
1644             // Damage part of layers.
1645             m_parent->setNeedsDisplayRect(FloatRect(0, 0, 5, 5));
1646             m_child->setNeedsDisplayRect(FloatRect(0, 0, 5, 5));
1647             break;
1648         case 3:
1649             m_child->setNeedsDisplay();
1650             m_layerTreeHost->setViewportSize(IntSize(10, 10));
1651             break;
1652         case 4:
1653             m_layerTreeHost->setViewportSize(IntSize(10, 20));
1654             break;
1655         default:
1656             ASSERT_NOT_REACHED();
1657             break;
1658         }
1659     }
1660
1661     virtual void afterTest()
1662     {
1663     }
1664
1665 private:
1666     MockContentLayerDelegate m_delegate;
1667     RefPtr<ContentLayerChromiumWithUpdateTracking> m_parent;
1668     RefPtr<ContentLayerChromiumWithUpdateTracking> m_child;
1669     int m_numCommits;
1670 };
1671
1672 TEST_F(CCLayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread)
1673 {
1674     runTest(true);
1675 }
1676
1677 class TestLayerChromium : public LayerChromium {
1678 public:
1679     static PassRefPtr<TestLayerChromium> create() { return adoptRef(new TestLayerChromium()); }
1680
1681     virtual void update(CCTextureUpdater&, const CCOcclusionTracker* occlusion) OVERRIDE
1682     {
1683         // Gain access to internals of the CCOcclusionTracker.
1684         const TestCCOcclusionTracker* testOcclusion = static_cast<const TestCCOcclusionTracker*>(occlusion);
1685         m_occludedScreenSpace = testOcclusion ? testOcclusion->occlusionInScreenSpace() : Region();
1686     }
1687
1688     virtual bool drawsContent() const OVERRIDE { return true; }
1689
1690     const Region& occludedScreenSpace() const { return m_occludedScreenSpace; }
1691     void clearOccludedScreenSpace() { m_occludedScreenSpace = Region(); }
1692
1693 private:
1694     TestLayerChromium() : LayerChromium() { }
1695
1696     Region m_occludedScreenSpace;
1697 };
1698
1699 static void setTestLayerPropertiesForTesting(TestLayerChromium* layer, LayerChromium* parent, const WebTransformationMatrix& transform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool opaque)
1700 {
1701     setLayerPropertiesForTesting(layer, parent, transform, anchor, position, bounds, opaque);
1702     layer->clearOccludedScreenSpace();
1703 }
1704
1705 class CCLayerTreeHostTestLayerOcclusion : public CCLayerTreeHostTest {
1706 public:
1707     CCLayerTreeHostTestLayerOcclusion() { }
1708
1709     virtual void beginTest()
1710     {
1711         RefPtr<TestLayerChromium> rootLayer = TestLayerChromium::create();
1712         RefPtr<TestLayerChromium> child = TestLayerChromium::create();
1713         RefPtr<TestLayerChromium> child2 = TestLayerChromium::create();
1714         RefPtr<TestLayerChromium> grandChild = TestLayerChromium::create();
1715         RefPtr<TestLayerChromium> mask = TestLayerChromium::create();
1716
1717         WebTransformationMatrix identityMatrix;
1718         WebTransformationMatrix childTransform;
1719         childTransform.translate(250, 250);
1720         childTransform.rotate(90);
1721         childTransform.translate(-250, -250);
1722
1723         child->setMasksToBounds(true);
1724
1725         // See CCLayerTreeHostCommonTest.layerAddsSelfToOccludedRegionWithRotatedSurface for a nice visual of these layers and how they end up
1726         // positioned on the screen.
1727
1728         // The child layer is rotated and the grandChild is opaque, but clipped to the child and rootLayer
1729         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1730         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false);
1731         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1732
1733         m_layerTreeHost->setRootLayer(rootLayer);
1734         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1735         ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
1736         CCTextureUpdater updater;
1737         m_layerTreeHost->updateLayers(updater);
1738         m_layerTreeHost->commitComplete();
1739
1740         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1741         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1742         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1743         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1744         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), rootLayer->occludedScreenSpace().bounds());
1745         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1746
1747         // If the child layer is opaque, then it adds to the occlusion seen by the rootLayer.
1748         setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1749         setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1750         setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1751
1752         m_layerTreeHost->setRootLayer(rootLayer);
1753         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1754         m_layerTreeHost->updateLayers(updater);
1755         m_layerTreeHost->commitComplete();
1756
1757         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1758         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1759         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1760         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1761         EXPECT_EQ_RECT(IntRect(30, 30, 170, 170), rootLayer->occludedScreenSpace().bounds());
1762         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1763
1764         // Add a second child to the root layer and the regions should merge
1765         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1766         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(70, 20), IntSize(500, 500), true);
1767         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1768         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1769
1770         m_layerTreeHost->setRootLayer(rootLayer);
1771         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1772         m_layerTreeHost->updateLayers(updater);
1773         m_layerTreeHost->commitComplete();
1774
1775         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1776         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1777         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1778         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1779         EXPECT_EQ_RECT(IntRect(30, 30, 170, 170), child2->occludedScreenSpace().bounds());
1780         EXPECT_EQ(1u, child2->occludedScreenSpace().rects().size());
1781         EXPECT_EQ_RECT(IntRect(30, 20, 170, 180), rootLayer->occludedScreenSpace().bounds());
1782         EXPECT_EQ(2u, rootLayer->occludedScreenSpace().rects().size());
1783
1784         // Move the second child to be sure.
1785         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1786         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1787         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1788         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1789
1790         m_layerTreeHost->setRootLayer(rootLayer);
1791         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1792         m_layerTreeHost->updateLayers(updater);
1793         m_layerTreeHost->commitComplete();
1794
1795         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1796         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1797         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1798         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1799         EXPECT_EQ_RECT(IntRect(30, 30, 170, 170), child2->occludedScreenSpace().bounds());
1800         EXPECT_EQ(1u, child2->occludedScreenSpace().rects().size());
1801         EXPECT_EQ_RECT(IntRect(10, 30, 190, 170), rootLayer->occludedScreenSpace().bounds());
1802         EXPECT_EQ(2u, rootLayer->occludedScreenSpace().rects().size());
1803
1804         // If the child layer has a mask on it, then it shouldn't contribute to occlusion on stuff below it
1805         setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1806         setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1807         setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1808         setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1809
1810         child->setMaskLayer(mask.get());
1811
1812         m_layerTreeHost->setRootLayer(rootLayer);
1813         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1814         m_layerTreeHost->updateLayers(updater);
1815         m_layerTreeHost->commitComplete();
1816
1817         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1818         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1819         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1820         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1821         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1822         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1823         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1824         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1825
1826         // If the child layer with a mask is below child2, then child2 should contribute to occlusion on everything, and child shouldn't contribute to the rootLayer
1827         setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1828         setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1829         setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1830         setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1831
1832         child->setMaskLayer(mask.get());
1833
1834         m_layerTreeHost->setRootLayer(rootLayer);
1835         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1836         m_layerTreeHost->updateLayers(updater);
1837         m_layerTreeHost->commitComplete();
1838
1839         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1840         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1841         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), grandChild->occludedScreenSpace().bounds());
1842         EXPECT_EQ(1u, grandChild->occludedScreenSpace().rects().size());
1843         EXPECT_EQ_RECT(IntRect(10, 40, 190, 160), child->occludedScreenSpace().bounds());
1844         EXPECT_EQ(2u, child->occludedScreenSpace().rects().size());
1845         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1846         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1847
1848         // If the child layer has a non-opaque drawOpacity, then it shouldn't contribute to occlusion on stuff below it
1849         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1850         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1851         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1852         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1853
1854         child->setMaskLayer(0);
1855         child->setOpacity(0.5);
1856
1857         m_layerTreeHost->setRootLayer(rootLayer);
1858         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1859         m_layerTreeHost->updateLayers(updater);
1860         m_layerTreeHost->commitComplete();
1861
1862         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1863         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1864         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1865         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1866         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1867         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1868         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1869         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1870
1871         // If the child layer with non-opaque drawOpacity is below child2, then child2 should contribute to occlusion on everything, and child shouldn't contribute to the rootLayer
1872         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1873         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1874         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1875         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1876
1877         child->setMaskLayer(0);
1878         child->setOpacity(0.5);
1879
1880         m_layerTreeHost->setRootLayer(rootLayer);
1881         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1882         m_layerTreeHost->updateLayers(updater);
1883         m_layerTreeHost->commitComplete();
1884
1885         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1886         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1887         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), grandChild->occludedScreenSpace().bounds());
1888         EXPECT_EQ(1u, grandChild->occludedScreenSpace().rects().size());
1889         EXPECT_EQ_RECT(IntRect(10, 40, 190, 160), child->occludedScreenSpace().bounds());
1890         EXPECT_EQ(2u, child->occludedScreenSpace().rects().size());
1891         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1892         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1893
1894         // Kill the layerTreeHost immediately.
1895         m_layerTreeHost->setRootLayer(0);
1896         m_layerTreeHost.clear();
1897
1898         endTest();
1899     }
1900
1901     virtual void afterTest()
1902     {
1903     }
1904 };
1905
1906 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestLayerOcclusion)
1907
1908 class CCLayerTreeHostTestLayerOcclusionWithFilters : public CCLayerTreeHostTest {
1909 public:
1910     CCLayerTreeHostTestLayerOcclusionWithFilters() { }
1911
1912     virtual void beginTest()
1913     {
1914         RefPtr<TestLayerChromium> rootLayer = TestLayerChromium::create();
1915         RefPtr<TestLayerChromium> child = TestLayerChromium::create();
1916         RefPtr<TestLayerChromium> child2 = TestLayerChromium::create();
1917         RefPtr<TestLayerChromium> grandChild = TestLayerChromium::create();
1918         RefPtr<TestLayerChromium> mask = TestLayerChromium::create();
1919
1920         WebTransformationMatrix identityMatrix;
1921         WebTransformationMatrix childTransform;
1922         childTransform.translate(250, 250);
1923         childTransform.rotate(90);
1924         childTransform.translate(-250, -250);
1925
1926         child->setMasksToBounds(true);
1927
1928         // If the child layer has a filter that changes alpha values, and is below child2, then child2 should contribute to occlusion on everything,
1929         // and child shouldn't contribute to the rootLayer
1930         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1931         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1932         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1933         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1934
1935         {
1936             WebFilterOperations filters;
1937             filters.append(WebFilterOperation::createOpacityFilter(0.5));
1938             child->setFilters(filters);
1939         }
1940
1941         m_layerTreeHost->setRootLayer(rootLayer);
1942         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1943         ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
1944         CCTextureUpdater updater;
1945         m_layerTreeHost->updateLayers(updater);
1946         m_layerTreeHost->commitComplete();
1947
1948         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1949         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1950         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), grandChild->occludedScreenSpace().bounds());
1951         EXPECT_EQ(1u, grandChild->occludedScreenSpace().rects().size());
1952         EXPECT_EQ_RECT(IntRect(10, 40, 190, 160), child->occludedScreenSpace().bounds());
1953         EXPECT_EQ(2u, child->occludedScreenSpace().rects().size());
1954         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1955         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1956
1957         // If the child layer has a filter that moves pixels/changes alpha, and is below child2, then child should not inherit occlusion from outside its subtree,
1958         // and should not contribute to the rootLayer
1959         setTestLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
1960         setTestLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true);
1961         setTestLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true);
1962         setTestLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true);
1963
1964         {
1965             WebFilterOperations filters;
1966             filters.append(WebFilterOperation::createBlurFilter(10));
1967             child->setFilters(filters);
1968         }
1969
1970         m_layerTreeHost->setRootLayer(rootLayer);
1971         m_layerTreeHost->setViewportSize(rootLayer->bounds());
1972         m_layerTreeHost->updateLayers(updater);
1973         m_layerTreeHost->commitComplete();
1974
1975         EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds());
1976         EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size());
1977         EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds());
1978         EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size());
1979         EXPECT_EQ_RECT(IntRect(30, 40, 170, 160), child->occludedScreenSpace().bounds());
1980         EXPECT_EQ(1u, child->occludedScreenSpace().rects().size());
1981         EXPECT_EQ_RECT(IntRect(10, 70, 190, 130), rootLayer->occludedScreenSpace().bounds());
1982         EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size());
1983
1984         // Kill the layerTreeHost immediately.
1985         m_layerTreeHost->setRootLayer(0);
1986         m_layerTreeHost.clear();
1987
1988         CCLayerTreeHost::setNeedsFilterContext(false);
1989         endTest();
1990     }
1991
1992     virtual void afterTest()
1993     {
1994     }
1995 };
1996
1997 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestLayerOcclusionWithFilters)
1998
1999 class CCLayerTreeHostTestManySurfaces : public CCLayerTreeHostTest {
2000 public:
2001     CCLayerTreeHostTestManySurfaces() { }
2002
2003     virtual void beginTest()
2004     {
2005         // We create enough RenderSurfaces that it will trigger Vector reallocation while computing occlusion.
2006         Region occluded;
2007         const WebTransformationMatrix identityMatrix;
2008         Vector<RefPtr<TestLayerChromium> > layers;
2009         Vector<RefPtr<TestLayerChromium> > children;
2010         int numSurfaces = 20;
2011         RefPtr<TestLayerChromium> replica = TestLayerChromium::create();
2012
2013         for (int i = 0; i < numSurfaces; ++i) {
2014             layers.append(TestLayerChromium::create());
2015             if (!i) {
2016                 setTestLayerPropertiesForTesting(layers.last().get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(200, 200), true);
2017                 layers.last()->createRenderSurface();
2018             } else {
2019                 setTestLayerPropertiesForTesting(layers.last().get(), layers[layers.size()-2].get(), identityMatrix, FloatPoint(0, 0), FloatPoint(1, 1), IntSize(200-i, 200-i), true);
2020                 layers.last()->setMasksToBounds(true);
2021                 layers.last()->setReplicaLayer(replica.get()); // Make it have a RenderSurface
2022             }
2023         }
2024
2025         for (int i = 1; i < numSurfaces; ++i) {
2026             children.append(TestLayerChromium::create());
2027             setTestLayerPropertiesForTesting(children.last().get(), layers[i].get(), identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
2028         }
2029
2030         m_layerTreeHost->setRootLayer(layers[0].get());
2031         m_layerTreeHost->setViewportSize(layers[0]->bounds());
2032         ASSERT_TRUE(m_layerTreeHost->initializeLayerRendererIfNeeded());
2033         CCTextureUpdater updater;
2034         m_layerTreeHost->updateLayers(updater);
2035         m_layerTreeHost->commitComplete();
2036
2037         for (int i = 0; i < numSurfaces-1; ++i) {
2038             IntRect expectedOcclusion(i+1, i+1, 200-i-1, 200-i-1);
2039
2040             EXPECT_EQ_RECT(expectedOcclusion, layers[i]->occludedScreenSpace().bounds());
2041             EXPECT_EQ(1u, layers[i]->occludedScreenSpace().rects().size());
2042         }
2043
2044         // Kill the layerTreeHost immediately.
2045         m_layerTreeHost->setRootLayer(0);
2046         m_layerTreeHost.clear();
2047
2048         endTest();
2049     }
2050
2051     virtual void afterTest()
2052     {
2053     }
2054 };
2055
2056 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestManySurfaces)
2057
2058 // A loseContext(1) should lead to a didRecreateContext(true)
2059 class CCLayerTreeHostTestSetSingleLostContext : public CCLayerTreeHostTestThreadOnly {
2060 public:
2061     CCLayerTreeHostTestSetSingleLostContext()
2062     {
2063     }
2064
2065     virtual void beginTest()
2066     {
2067         postSetNeedsCommitToMainThread();
2068     }
2069
2070     virtual void didCommitAndDrawFrame()
2071     {
2072         m_layerTreeHost->loseContext(1);
2073     }
2074
2075     virtual void didRecreateContext(bool succeeded)
2076     {
2077         EXPECT_TRUE(succeeded);
2078         endTest();
2079     }
2080
2081     virtual void afterTest()
2082     {
2083     }
2084 };
2085
2086 TEST_F(CCLayerTreeHostTestSetSingleLostContext, runMultiThread)
2087 {
2088     runTestThreaded();
2089 }
2090
2091 // A loseContext(10) should lead to a didRecreateContext(false), and
2092 // a finishAllRendering() should not hang.
2093 class CCLayerTreeHostTestSetRepeatedLostContext : public CCLayerTreeHostTestThreadOnly {
2094 public:
2095     CCLayerTreeHostTestSetRepeatedLostContext()
2096     {
2097     }
2098
2099     virtual void beginTest()
2100     {
2101         postSetNeedsCommitToMainThread();
2102     }
2103
2104     virtual void didCommitAndDrawFrame()
2105     {
2106         m_layerTreeHost->loseContext(10);
2107     }
2108
2109     virtual void didRecreateContext(bool succeeded)
2110     {
2111         EXPECT_FALSE(succeeded);
2112         m_layerTreeHost->finishAllRendering();
2113         endTest();
2114     }
2115
2116     virtual void afterTest()
2117     {
2118     }
2119 };
2120
2121 TEST_F(CCLayerTreeHostTestSetRepeatedLostContext, runMultiThread)
2122 {
2123     runTestThreaded();
2124 }
2125
2126 class CCLayerTreeHostTestFractionalScroll : public CCLayerTreeHostTestThreadOnly {
2127 public:
2128     CCLayerTreeHostTestFractionalScroll()
2129         : m_scrollAmount(1.75, 0)
2130     {
2131     }
2132
2133     virtual void beginTest()
2134     {
2135         m_layerTreeHost->rootLayer()->setScrollable(true);
2136         postSetNeedsCommitToMainThread();
2137     }
2138
2139     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
2140     {
2141         CCLayerImpl* root = impl->rootLayer();
2142         root->setMaxScrollPosition(IntSize(100, 100));
2143
2144         // Check that a fractional scroll delta is correctly accumulated over multiple commits.
2145         if (!impl->sourceFrameNumber()) {
2146             EXPECT_EQ(root->scrollPosition(), IntPoint(0, 0));
2147             EXPECT_EQ(root->scrollDelta(), FloatSize(0, 0));
2148             postSetNeedsCommitToMainThread();
2149         } else if (impl->sourceFrameNumber() == 1) {
2150             EXPECT_EQ(root->scrollPosition(), flooredIntPoint(m_scrollAmount));
2151             EXPECT_EQ(root->scrollDelta(), FloatSize(fmod(m_scrollAmount.width(), 1), 0));
2152             postSetNeedsCommitToMainThread();
2153         } else if (impl->sourceFrameNumber() == 2) {
2154             EXPECT_EQ(root->scrollPosition(), flooredIntPoint(m_scrollAmount + m_scrollAmount));
2155             EXPECT_EQ(root->scrollDelta(), FloatSize(fmod(2 * m_scrollAmount.width(), 1), 0));
2156             endTest();
2157         }
2158         root->scrollBy(m_scrollAmount);
2159     }
2160
2161     virtual void applyScrollAndScale(const IntSize& scrollDelta, float scale)
2162     {
2163         IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
2164         m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
2165     }
2166
2167     virtual void afterTest()
2168     {
2169     }
2170 private:
2171     FloatSize m_scrollAmount;
2172 };
2173
2174 TEST_F(CCLayerTreeHostTestFractionalScroll, runMultiThread)
2175 {
2176     runTestThreaded();
2177 }
2178
2179 class CCLayerTreeHostTestFinishAllRendering : public CCLayerTreeHostTest {
2180 public:
2181     CCLayerTreeHostTestFinishAllRendering()
2182         : m_once(false)
2183         , m_mutex()
2184         , m_drawCount(0)
2185     {
2186     }
2187
2188     virtual void beginTest()
2189     {
2190         m_layerTreeHost->setNeedsRedraw();
2191     }
2192
2193     virtual void didCommitAndDrawFrame()
2194     {
2195         if (m_once)
2196             return;
2197         m_once = true;
2198         m_layerTreeHost->setNeedsRedraw();
2199         m_layerTreeHost->acquireLayerTextures();
2200         {
2201             Locker<Mutex> lock(m_mutex);
2202             m_drawCount = 0;
2203         }
2204         m_layerTreeHost->finishAllRendering();
2205         {
2206             Locker<Mutex> lock(m_mutex);
2207             EXPECT_EQ(0, m_drawCount);
2208         }
2209         endTest();
2210     }
2211
2212     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
2213     {
2214         Locker<Mutex> lock(m_mutex);
2215         ++m_drawCount;
2216     }
2217
2218     virtual void afterTest()
2219     {
2220     }
2221 private:
2222
2223     bool m_once;
2224     Mutex m_mutex;
2225     int m_drawCount;
2226 };
2227
2228 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestFinishAllRendering)
2229
2230 // Layers added to tree with existing active animations should have the animation
2231 // correctly recognized.
2232 class CCLayerTreeHostTestLayerAddedWithAnimation : public CCLayerTreeHostTest {
2233 public:
2234     CCLayerTreeHostTestLayerAddedWithAnimation()
2235         : m_addedAnimation(false)
2236     {
2237     }
2238
2239     virtual void beginTest()
2240     {
2241         EXPECT_FALSE(m_addedAnimation);
2242
2243         RefPtr<LayerChromium> layer = LayerChromium::create();
2244         layer->setLayerAnimationDelegate(this);
2245
2246         // Any valid CCAnimationCurve will do here.
2247         OwnPtr<CCAnimationCurve> curve(CCEaseTimingFunction::create());
2248         OwnPtr<CCActiveAnimation> animation(CCActiveAnimation::create(curve.release(), AnimationIdVendor::getNextAnimationId(), AnimationIdVendor::getNextGroupId(), CCActiveAnimation::Opacity));
2249         layer->layerAnimationController()->addAnimation(animation.release());
2250
2251         // We add the animation *before* attaching the layer to the tree.
2252         m_layerTreeHost->rootLayer()->addChild(layer);
2253         EXPECT_TRUE(m_addedAnimation);
2254
2255         endTest();
2256     }
2257
2258     virtual void didAddAnimation()
2259     {
2260         m_addedAnimation = true;
2261     }
2262
2263     virtual void afterTest() { }
2264
2265 private:
2266     bool m_addedAnimation;
2267 };
2268
2269 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestLayerAddedWithAnimation)
2270
2271 class CCLayerTreeHostTestScrollChildLayer : public CCLayerTreeHostTest, public LayerChromiumScrollDelegate {
2272 public:
2273     CCLayerTreeHostTestScrollChildLayer()
2274         : m_scrollAmount(2, 1)
2275     {
2276     }
2277
2278     virtual void beginTest() OVERRIDE
2279     {
2280         m_layerTreeHost->setViewportSize(IntSize(10, 10));
2281         m_rootScrollLayer = ContentLayerChromium::create(&m_mockDelegate);
2282         m_rootScrollLayer->setBounds(IntSize(10, 10));
2283         m_rootScrollLayer->setIsDrawable(true);
2284         m_rootScrollLayer->setScrollable(true);
2285         m_rootScrollLayer->setMaxScrollPosition(IntSize(100, 100));
2286         m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer);
2287         m_childLayer = ContentLayerChromium::create(&m_mockDelegate);
2288         m_childLayer->setLayerScrollDelegate(this);
2289         m_childLayer->setBounds(IntSize(50, 50));
2290         m_childLayer->setIsDrawable(true);
2291         m_childLayer->setScrollable(true);
2292         m_childLayer->setMaxScrollPosition(IntSize(100, 100));
2293         m_rootScrollLayer->addChild(m_childLayer);
2294         postSetNeedsCommitToMainThread();
2295     }
2296
2297     virtual void didScroll(const IntSize& scrollDelta) OVERRIDE
2298     {
2299         m_reportedScrollAmount = scrollDelta;
2300     }
2301
2302     virtual void applyScrollAndScale(const IntSize& scrollDelta, float) OVERRIDE
2303     {
2304         IntPoint position = m_rootScrollLayer->scrollPosition();
2305         m_rootScrollLayer->setScrollPosition(position + scrollDelta);
2306     }
2307
2308     virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl) OVERRIDE
2309     {
2310         EXPECT_EQ(m_rootScrollLayer->scrollPosition(), IntPoint());
2311         if (!m_layerTreeHost->frameNumber())
2312             EXPECT_EQ(m_childLayer->scrollPosition(), IntPoint());
2313         else
2314             EXPECT_EQ(m_childLayer->scrollPosition(), IntPoint() + m_scrollAmount);
2315     }
2316
2317     virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl) OVERRIDE
2318     {
2319         if (impl->frameNumber() == 1) {
2320             EXPECT_EQ(impl->scrollBegin(IntPoint(5, 5), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollStarted);
2321             impl->scrollBy(m_scrollAmount);
2322             impl->scrollEnd();
2323         } else if (impl->frameNumber() == 2)
2324             endTest();
2325     }
2326
2327     virtual void afterTest() OVERRIDE
2328     {
2329         EXPECT_EQ(m_scrollAmount, m_reportedScrollAmount);
2330     }
2331
2332 private:
2333     const IntSize m_scrollAmount;
2334     IntSize m_reportedScrollAmount;
2335     MockContentLayerDelegate m_mockDelegate;
2336     RefPtr<LayerChromium> m_childLayer;
2337     RefPtr<LayerChromium> m_rootScrollLayer;
2338 };
2339
2340 TEST_F(CCLayerTreeHostTestScrollChildLayer, runMultiThread)
2341 {
2342     runTest(true);
2343 }
2344
2345 } // namespace