Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: cc/layers/contents_scaling_layer_unittest.cc

Issue 1101823002: CC Animations: Make LayerAnimationController creation optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Plumb LayerSettings parameter for cc::Layer construction. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/contents_scaling_layer.h" 5 #include "cc/layers/contents_scaling_layer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/test/fake_layer_tree_host.h" 9 #include "cc/test/fake_layer_tree_host.h"
10 #include "cc/test/geometry_test_utils.h" 10 #include "cc/test/geometry_test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace cc { 13 namespace cc {
14 namespace { 14 namespace {
15 15
16 class MockContentsScalingLayer : public ContentsScalingLayer { 16 class MockContentsScalingLayer : public ContentsScalingLayer {
17 public: 17 public:
18 MockContentsScalingLayer() 18 explicit MockContentsScalingLayer(const LayerSettings& settings)
19 : ContentsScalingLayer() {} 19 : ContentsScalingLayer(settings) {}
20 20
21 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override { 21 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override {
22 last_needs_display_rect_ = dirty_rect; 22 last_needs_display_rect_ = dirty_rect;
23 ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect); 23 ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect);
24 } 24 }
25 25
26 const gfx::Rect& LastNeedsDisplayRect() const { 26 const gfx::Rect& LastNeedsDisplayRect() const {
27 return last_needs_display_rect_; 27 return last_needs_display_rect_;
28 } 28 }
29 29
30 private: 30 private:
31 ~MockContentsScalingLayer() override {} 31 ~MockContentsScalingLayer() override {}
32 32
33 gfx::Rect last_needs_display_rect_; 33 gfx::Rect last_needs_display_rect_;
34 }; 34 };
35 35
36 static void CalcDrawProps(FakeLayerTreeHost* host, float device_scale_factor) { 36 static void CalcDrawProps(FakeLayerTreeHost* host, float device_scale_factor) {
37 RenderSurfaceLayerList render_surface_layer_list; 37 RenderSurfaceLayerList render_surface_layer_list;
38 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 38 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
39 host->root_layer(), gfx::Size(500, 500), &render_surface_layer_list); 39 host->root_layer(), gfx::Size(500, 500), &render_surface_layer_list);
40 inputs.device_scale_factor = device_scale_factor; 40 inputs.device_scale_factor = device_scale_factor;
41 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 41 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
42 } 42 }
43 43
44 TEST(ContentsScalingLayerTest, CheckContentsBounds) { 44 TEST(ContentsScalingLayerTest, CheckContentsBounds) {
45 LayerSettings layer_settings;
46
45 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); 47 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
46 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); 48 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
47 49
48 scoped_refptr<MockContentsScalingLayer> test_layer = 50 scoped_refptr<MockContentsScalingLayer> test_layer =
49 make_scoped_refptr(new MockContentsScalingLayer()); 51 make_scoped_refptr(new MockContentsScalingLayer(layer_settings));
50 52
51 scoped_refptr<Layer> root = Layer::Create(); 53 scoped_refptr<Layer> root = Layer::Create(layer_settings);
52 root->AddChild(test_layer); 54 root->AddChild(test_layer);
53 host->SetRootLayer(root); 55 host->SetRootLayer(root);
54 56
55 test_layer->SetBounds(gfx::Size(320, 240)); 57 test_layer->SetBounds(gfx::Size(320, 240));
56 58
57 CalcDrawProps(host.get(), 1.f); 59 CalcDrawProps(host.get(), 1.f);
58 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x()); 60 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x());
59 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y()); 61 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y());
60 EXPECT_EQ(320, test_layer->content_bounds().width()); 62 EXPECT_EQ(320, test_layer->content_bounds().width());
61 EXPECT_EQ(240, test_layer->content_bounds().height()); 63 EXPECT_EQ(240, test_layer->content_bounds().height());
62 64
63 CalcDrawProps(host.get(), 2.f); 65 CalcDrawProps(host.get(), 2.f);
64 EXPECT_EQ(640, test_layer->content_bounds().width()); 66 EXPECT_EQ(640, test_layer->content_bounds().width());
65 EXPECT_EQ(480, test_layer->content_bounds().height()); 67 EXPECT_EQ(480, test_layer->content_bounds().height());
66 68
67 test_layer->SetBounds(gfx::Size(10, 20)); 69 test_layer->SetBounds(gfx::Size(10, 20));
68 CalcDrawProps(host.get(), 2.f); 70 CalcDrawProps(host.get(), 2.f);
69 EXPECT_EQ(20, test_layer->content_bounds().width()); 71 EXPECT_EQ(20, test_layer->content_bounds().width());
70 EXPECT_EQ(40, test_layer->content_bounds().height()); 72 EXPECT_EQ(40, test_layer->content_bounds().height());
71 73
72 CalcDrawProps(host.get(), 1.33f); 74 CalcDrawProps(host.get(), 1.33f);
73 EXPECT_EQ(14, test_layer->content_bounds().width()); 75 EXPECT_EQ(14, test_layer->content_bounds().width());
74 EXPECT_EQ(27, test_layer->content_bounds().height()); 76 EXPECT_EQ(27, test_layer->content_bounds().height());
75 } 77 }
76 78
77 } // namespace 79 } // namespace
78 } // namespace cc 80 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698