Fix revert "[chromeos] Remove dependencies of StatisticsProvider on chrome."
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_video.cc
blob5413a602d4be3f7a21b789333206d21ea0838732
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_host.h"
7 #include "base/basictypes.h"
8 #include "cc/layers/render_surface_impl.h"
9 #include "cc/layers/video_layer.h"
10 #include "cc/layers/video_layer_impl.h"
11 #include "cc/test/fake_video_frame_provider.h"
12 #include "cc/test/layer_tree_test.h"
13 #include "cc/trees/damage_tracker.h"
14 #include "cc/trees/layer_tree_impl.h"
16 namespace cc {
17 namespace {
19 // These tests deal with compositing video.
20 class LayerTreeHostVideoTest : public LayerTreeTest {};
22 class LayerTreeHostVideoTestSetNeedsDisplay
23 : public LayerTreeHostVideoTest {
24 public:
25 virtual void SetupTree() OVERRIDE {
26 scoped_refptr<Layer> root = Layer::Create();
27 root->SetBounds(gfx::Size(10, 10));
28 root->SetAnchorPoint(gfx::PointF());
29 root->SetIsDrawable(true);
31 scoped_refptr<VideoLayer> video = VideoLayer::Create(
32 &video_frame_provider_);
33 video->SetPosition(gfx::PointF(3.f, 3.f));
34 video->SetBounds(gfx::Size(4, 4));
35 video->SetAnchorPoint(gfx::PointF());
36 video->SetIsDrawable(true);
37 root->AddChild(video);
39 layer_tree_host()->SetRootLayer(root);
40 layer_tree_host()->SetDeviceScaleFactor(2.f);
41 LayerTreeHostVideoTest::SetupTree();
44 virtual void BeginTest() OVERRIDE {
45 num_draws_ = 0;
46 PostSetNeedsCommitToMainThread();
49 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
50 LayerTreeHostImpl::FrameData* frame,
51 bool result) OVERRIDE {
52 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
53 RenderSurfaceImpl* root_surface = root_layer->render_surface();
54 gfx::RectF damage_rect =
55 root_surface->damage_tracker()->current_damage_rect();
57 switch (num_draws_) {
58 case 0:
59 // First frame the whole viewport is damaged.
60 EXPECT_EQ(gfx::RectF(0.f, 0.f, 20.f, 20.f).ToString(),
61 damage_rect.ToString());
62 break;
63 case 1:
64 // Second frame the video layer is damaged.
65 EXPECT_EQ(gfx::RectF(6.f, 6.f, 8.f, 8.f).ToString(),
66 damage_rect.ToString());
67 EndTest();
68 break;
71 EXPECT_TRUE(result);
72 return result;
75 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
76 VideoLayerImpl* video = static_cast<VideoLayerImpl*>(
77 host_impl->active_tree()->root_layer()->children()[0]);
79 if (num_draws_ == 0)
80 video->SetNeedsRedraw();
82 ++num_draws_;
85 virtual void AfterTest() OVERRIDE {
86 EXPECT_EQ(2, num_draws_);
89 private:
90 int num_draws_;
92 FakeVideoFrameProvider video_frame_provider_;
95 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostVideoTestSetNeedsDisplay);
97 } // namespace
98 } // namespace cc