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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | cc/output/begin_frame_args.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui_resource_layer.h" 5 #include "cc/layers/ui_resource_layer.h"
6 6
7 #include "cc/resources/prioritized_resource_manager.h" 7 #include "cc/resources/prioritized_resource_manager.h"
8 #include "cc/resources/resource_provider.h" 8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/resource_update_queue.h" 9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/resources/scoped_ui_resource.h" 10 #include "cc/resources/scoped_ui_resource.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 22
23 using ::testing::Mock; 23 using ::testing::Mock;
24 using ::testing::_; 24 using ::testing::_;
25 using ::testing::AtLeast; 25 using ::testing::AtLeast;
26 using ::testing::AnyNumber; 26 using ::testing::AnyNumber;
27 27
28 namespace cc { 28 namespace cc {
29 namespace { 29 namespace {
30 30
31 class TestUIResourceLayer : public UIResourceLayer {
32 public:
33 static scoped_refptr<TestUIResourceLayer> Create() {
34 return make_scoped_refptr(new TestUIResourceLayer());
35 }
36
37 UIResourceId GetUIResourceId() {
38 if (ui_resource_holder_)
39 return ui_resource_holder_->id();
40 return 0;
41 }
42
43 protected:
44 TestUIResourceLayer() : UIResourceLayer() { SetIsDrawable(true); }
45 ~TestUIResourceLayer() override {}
46 };
47
31 class UIResourceLayerTest : public testing::Test { 48 class UIResourceLayerTest : public testing::Test {
32 public: 49 public:
33 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 50 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
34 51
35 protected: 52 protected:
36 virtual void SetUp() { 53 void SetUp() override {
37 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_); 54 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
38 layer_tree_host_->InitializeSingleThreaded( 55 layer_tree_host_->InitializeSingleThreaded(
39 &fake_client_, 56 &fake_client_,
40 base::MessageLoopProxy::current(), 57 base::MessageLoopProxy::current(),
41 nullptr); 58 nullptr);
42 } 59 }
43 60
44 virtual void TearDown() { 61 void TearDown() override {
45 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 62 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
46 } 63 }
47 64
48 FakeLayerTreeHostClient fake_client_; 65 FakeLayerTreeHostClient fake_client_;
49 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; 66 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
50 }; 67 };
51 68
52 TEST_F(UIResourceLayerTest, SetBitmap) { 69 TEST_F(UIResourceLayerTest, SetBitmap) {
53 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create(); 70 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
54 ASSERT_TRUE(test_layer.get()); 71 ASSERT_TRUE(test_layer.get());
55 test_layer->SetIsDrawable(true);
56 test_layer->SetBounds(gfx::Size(100, 100)); 72 test_layer->SetBounds(gfx::Size(100, 100));
57 73
58 layer_tree_host_->SetRootLayer(test_layer); 74 layer_tree_host_->SetRootLayer(test_layer);
59 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 75 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
60 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 76 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
61 77
62 ResourceUpdateQueue queue; 78 ResourceUpdateQueue queue;
63 gfx::Rect screen_space_clip_rect; 79 gfx::Rect screen_space_clip_rect;
64 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect); 80 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
65 test_layer->SavePaintProperties(); 81 test_layer->SavePaintProperties();
66 test_layer->Update(&queue, &occlusion_tracker); 82 test_layer->Update(&queue, &occlusion_tracker);
67 83
68 EXPECT_FALSE(test_layer->DrawsContent()); 84 EXPECT_FALSE(test_layer->DrawsContent());
69 85
70 SkBitmap bitmap; 86 SkBitmap bitmap;
71 bitmap.allocN32Pixels(10, 10); 87 bitmap.allocN32Pixels(10, 10);
72 bitmap.setImmutable(); 88 bitmap.setImmutable();
73 89
74 test_layer->SetBitmap(bitmap); 90 test_layer->SetBitmap(bitmap);
75 test_layer->Update(&queue, &occlusion_tracker); 91 test_layer->Update(&queue, &occlusion_tracker);
76 92
77 EXPECT_TRUE(test_layer->DrawsContent()); 93 EXPECT_TRUE(test_layer->DrawsContent());
78 } 94 }
79 95
80 TEST_F(UIResourceLayerTest, SetUIResourceId) { 96 TEST_F(UIResourceLayerTest, SetUIResourceId) {
81 scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create(); 97 scoped_refptr<TestUIResourceLayer> test_layer = TestUIResourceLayer::Create();
82 ASSERT_TRUE(test_layer.get()); 98 ASSERT_TRUE(test_layer.get());
83 test_layer->SetIsDrawable(true);
84 test_layer->SetBounds(gfx::Size(100, 100)); 99 test_layer->SetBounds(gfx::Size(100, 100));
85 100
86 layer_tree_host_->SetRootLayer(test_layer); 101 layer_tree_host_->SetRootLayer(test_layer);
87 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 102 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
88 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 103 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
89 104
90 ResourceUpdateQueue queue; 105 ResourceUpdateQueue queue;
91 gfx::Rect screen_space_clip_rect; 106 gfx::Rect screen_space_clip_rect;
92 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect); 107 OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
93 test_layer->SavePaintProperties(); 108 test_layer->SavePaintProperties();
94 test_layer->Update(&queue, &occlusion_tracker); 109 test_layer->Update(&queue, &occlusion_tracker);
95 110
96 EXPECT_FALSE(test_layer->DrawsContent()); 111 EXPECT_FALSE(test_layer->DrawsContent());
97 112
98 bool is_opaque = false; 113 bool is_opaque = false;
99 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create( 114 scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
100 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque)); 115 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque));
101 test_layer->SetUIResourceId(resource->id()); 116 test_layer->SetUIResourceId(resource->id());
102 test_layer->Update(&queue, &occlusion_tracker); 117 test_layer->Update(&queue, &occlusion_tracker);
103 118
104 EXPECT_TRUE(test_layer->DrawsContent()); 119 EXPECT_TRUE(test_layer->DrawsContent());
120
121 // ID is preserved even when you set ID first and attach it to the tree.
122 layer_tree_host_->SetRootLayer(nullptr);
123 scoped_ptr<ScopedUIResource> shared_resource = ScopedUIResource::Create(
124 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque));
125 test_layer->SetUIResourceId(shared_resource->id());
126 layer_tree_host_->SetRootLayer(test_layer);
127 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId());
128 EXPECT_TRUE(test_layer->DrawsContent());
105 } 129 }
106 130
107 } // namespace 131 } // namespace
108 } // namespace cc 132 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | cc/output/begin_frame_args.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698