Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_video.cc
blobffeda727fe3f30fc38280a8f78b161fcb6918ceb
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 void SetupTree() override {
26 scoped_refptr<Layer> root = Layer::Create();
27 root->SetBounds(gfx::Size(10, 10));
28 root->SetIsDrawable(true);
30 scoped_refptr<VideoLayer> video =
31 VideoLayer::Create(&video_frame_provider_, media::VIDEO_ROTATION_90);
32 video->SetPosition(gfx::PointF(3.f, 3.f));
33 video->SetBounds(gfx::Size(4, 5));
34 video->SetIsDrawable(true);
35 root->AddChild(video);
37 layer_tree_host()->SetRootLayer(root);
38 layer_tree_host()->SetDeviceScaleFactor(2.f);
39 LayerTreeHostVideoTest::SetupTree();
42 void BeginTest() override {
43 num_draws_ = 0;
44 PostSetNeedsCommitToMainThread();
47 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
48 LayerTreeHostImpl::FrameData* frame,
49 DrawResult draw_result) override {
50 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
51 RenderSurfaceImpl* root_surface = root_layer->render_surface();
52 gfx::RectF damage_rect =
53 root_surface->damage_tracker()->current_damage_rect();
55 switch (num_draws_) {
56 case 0:
57 // First frame the whole viewport is damaged.
58 EXPECT_EQ(gfx::RectF(0.f, 0.f, 20.f, 20.f).ToString(),
59 damage_rect.ToString());
60 break;
61 case 1:
62 // Second frame the video layer is damaged.
63 EXPECT_EQ(gfx::RectF(6.f, 6.f, 8.f, 10.f).ToString(),
64 damage_rect.ToString());
65 EndTest();
66 break;
69 EXPECT_EQ(DRAW_SUCCESS, draw_result);
70 return draw_result;
73 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
74 VideoLayerImpl* video = static_cast<VideoLayerImpl*>(
75 host_impl->active_tree()->root_layer()->children()[0]);
77 EXPECT_EQ(media::VIDEO_ROTATION_90, video->video_rotation());
79 if (num_draws_ == 0)
80 video->SetNeedsRedraw();
82 ++num_draws_;
85 void AfterTest() override { EXPECT_EQ(2, num_draws_); }
87 private:
88 int num_draws_;
90 FakeVideoFrameProvider video_frame_provider_;
93 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostVideoTestSetNeedsDisplay);
95 } // namespace
96 } // namespace cc