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"
19 // These tests deal with compositing video.
20 class LayerTreeHostVideoTest
: public LayerTreeTest
{};
22 class LayerTreeHostVideoTestSetNeedsDisplay
23 : public LayerTreeHostVideoTest
{
25 void SetupTree() override
{
26 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
27 root
->SetBounds(gfx::Size(10, 10));
28 root
->SetIsDrawable(true);
30 scoped_refptr
<VideoLayer
> video
= VideoLayer::Create(
31 layer_settings(), &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
{
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::Rect damage_rect
=
53 root_surface
->damage_tracker()->current_damage_rect();
57 // First frame the whole viewport is damaged.
58 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), damage_rect
);
61 // Second frame the video layer is damaged.
62 EXPECT_EQ(gfx::Rect(6, 6, 8, 10), damage_rect
);
67 EXPECT_EQ(DRAW_SUCCESS
, draw_result
);
71 void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) override
{
72 VideoLayerImpl
* video
= static_cast<VideoLayerImpl
*>(
73 host_impl
->active_tree()->root_layer()->children()[0]);
75 EXPECT_EQ(media::VIDEO_ROTATION_90
, video
->video_rotation());
78 video
->SetNeedsRedraw();
83 void AfterTest() override
{ EXPECT_EQ(2, num_draws_
); }
88 FakeVideoFrameProvider video_frame_provider_
;
91 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostVideoTestSetNeedsDisplay
);