Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_video.cc
blob5484e4c9163ff252bc7f15a69b9e73e296128cf3
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->SetIsDrawable(true);
30 scoped_refptr<VideoLayer> video = VideoLayer::Create(
31 &video_frame_provider_);
32 video->SetPosition(gfx::PointF(3.f, 3.f));
33 video->SetBounds(gfx::Size(4, 4));
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 virtual void BeginTest() OVERRIDE {
43 num_draws_ = 0;
44 PostSetNeedsCommitToMainThread();
47 virtual 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, 8.f).ToString(),
64 damage_rect.ToString());
65 EndTest();
66 break;
69 EXPECT_EQ(DRAW_SUCCESS, draw_result);
70 return draw_result;
73 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
74 VideoLayerImpl* video = static_cast<VideoLayerImpl*>(
75 host_impl->active_tree()->root_layer()->children()[0]);
77 if (num_draws_ == 0)
78 video->SetNeedsRedraw();
80 ++num_draws_;
83 virtual void AfterTest() OVERRIDE {
84 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