OLD | NEW |
---|---|
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/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "cc/trees/layer_tree_impl.h" | 30 #include "cc/trees/layer_tree_impl.h" |
31 #include "cc/trees/single_thread_proxy.h" | 31 #include "cc/trees/single_thread_proxy.h" |
32 #include "gpu/GLES2/gl2extchromium.h" | 32 #include "gpu/GLES2/gl2extchromium.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 | 35 |
36 using ::testing::Mock; | 36 using ::testing::Mock; |
37 using ::testing::_; | 37 using ::testing::_; |
38 using ::testing::AtLeast; | 38 using ::testing::AtLeast; |
39 using ::testing::AnyNumber; | 39 using ::testing::AnyNumber; |
40 using ::testing::InvokeWithoutArgs; | |
40 | 41 |
41 namespace cc { | 42 namespace cc { |
42 namespace { | 43 namespace { |
43 | 44 |
44 gpu::Mailbox MailboxFromChar(char value) { | 45 gpu::Mailbox MailboxFromChar(char value) { |
45 gpu::Mailbox mailbox; | 46 gpu::Mailbox mailbox; |
46 memset(mailbox.name, value, sizeof(mailbox.name)); | 47 memset(mailbox.name, value, sizeof(mailbox.name)); |
47 return mailbox; | 48 return mailbox; |
48 } | 49 } |
49 | 50 |
50 class MockLayerTreeHost : public LayerTreeHost { | 51 class MockLayerTreeHost : public LayerTreeHost { |
51 public: | 52 public: |
52 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) | 53 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
53 : LayerTreeHost(client, NULL, LayerTreeSettings()) { | 54 : LayerTreeHost(client, NULL, LayerTreeSettings()) { |
54 InitializeSingleThreaded(client); | 55 InitializeSingleThreaded(client); |
55 } | 56 } |
56 | 57 |
57 MOCK_METHOD0(AcquireLayerTextures, void()); | 58 MOCK_METHOD0(AcquireLayerTextures, void()); |
58 MOCK_METHOD0(SetNeedsCommit, void()); | 59 MOCK_METHOD0(SetNeedsCommit, void()); |
59 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 60 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
60 MOCK_METHOD0(StartRateLimiter, void()); | 61 MOCK_METHOD0(StartRateLimiter, void()); |
61 MOCK_METHOD0(StopRateLimiter, void()); | 62 MOCK_METHOD0(StopRateLimiter, void()); |
62 }; | 63 }; |
63 | 64 |
65 class FakeTextureLayerClient : public TextureLayerClient { | |
66 public: | |
67 FakeTextureLayerClient() : texture_(0), mailbox_changed_(true) {} | |
68 | |
69 virtual unsigned PrepareTexture() OVERRIDE { return texture_; } | |
70 | |
71 virtual bool PrepareTextureMailbox( | |
72 TextureMailbox* mailbox, | |
73 scoped_ptr<SingleReleaseCallback>* release_callback, | |
74 bool use_shared_memory) OVERRIDE { | |
75 if (!mailbox_changed_) | |
76 return false; | |
77 | |
78 *mailbox = mailbox_; | |
79 *release_callback = release_callback_.Pass(); | |
80 mailbox_changed_ = false; | |
81 return true; | |
82 } | |
83 | |
84 void set_texture(unsigned texture) { texture_ = texture; } | |
85 | |
86 void set_mailbox(const TextureMailbox& mailbox, | |
87 scoped_ptr<SingleReleaseCallback> release_callback) { | |
88 mailbox_ = mailbox; | |
89 release_callback_ = release_callback.Pass(); | |
90 mailbox_changed_ = true; | |
91 } | |
92 | |
93 private: | |
94 unsigned texture_; | |
95 TextureMailbox mailbox_; | |
96 scoped_ptr<SingleReleaseCallback> release_callback_; | |
97 bool mailbox_changed_; | |
98 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | |
99 }; | |
100 | |
101 class MockMailboxCallback { | |
102 public: | |
103 MOCK_METHOD3(Release, | |
104 void(const gpu::Mailbox& mailbox, | |
105 uint32 sync_point, | |
106 bool lost_resource)); | |
107 MOCK_METHOD3(Release2, | |
108 void(base::SharedMemory* shared_memory, | |
109 uint32 sync_point, | |
110 bool lost_resource)); | |
111 }; | |
112 | |
113 struct CommonMailboxObjects { | |
114 CommonMailboxObjects() | |
115 : mailbox_name1_(MailboxFromChar('1')), | |
116 mailbox_name2_(MailboxFromChar('2')), | |
117 sync_point1_(1), | |
118 sync_point2_(2), | |
119 shared_memory_(new base::SharedMemory) { | |
120 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | |
121 base::Unretained(&mock_callback_), | |
122 mailbox_name1_); | |
123 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | |
124 base::Unretained(&mock_callback_), | |
125 mailbox_name2_); | |
126 const uint32 arbitrary_target1 = 1; | |
127 const uint32 arbitrary_target2 = 2; | |
128 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); | |
129 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); | |
130 gfx::Size size(128, 128); | |
131 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | |
132 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | |
133 base::Unretained(&mock_callback_), | |
134 shared_memory_.get()); | |
135 mailbox3_ = TextureMailbox(shared_memory_.get(), size); | |
136 } | |
137 | |
138 gpu::Mailbox mailbox_name1_; | |
139 gpu::Mailbox mailbox_name2_; | |
140 MockMailboxCallback mock_callback_; | |
141 ReleaseCallback release_mailbox1_; | |
142 ReleaseCallback release_mailbox2_; | |
143 ReleaseCallback release_mailbox3_; | |
144 TextureMailbox mailbox1_; | |
145 TextureMailbox mailbox2_; | |
146 TextureMailbox mailbox3_; | |
147 uint32 sync_point1_; | |
148 uint32 sync_point2_; | |
149 scoped_ptr<base::SharedMemory> shared_memory_; | |
150 }; | |
151 | |
64 class TextureLayerTest : public testing::Test { | 152 class TextureLayerTest : public testing::Test { |
65 public: | 153 public: |
66 TextureLayerTest() | 154 TextureLayerTest() |
67 : fake_client_( | 155 : fake_client_( |
68 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), | 156 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
69 host_impl_(&proxy_, &shared_bitmap_manager_) {} | 157 host_impl_(&proxy_, &shared_bitmap_manager_) {} |
70 | 158 |
71 protected: | 159 protected: |
72 virtual void SetUp() { | 160 virtual void SetUp() { |
73 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); | 161 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
162 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | |
163 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); | |
164 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
74 } | 165 } |
75 | 166 |
76 virtual void TearDown() { | 167 virtual void TearDown() { |
77 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 168 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
78 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 169 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
79 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 170 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
80 | 171 |
81 layer_tree_host_->SetRootLayer(NULL); | 172 layer_tree_host_->SetRootLayer(NULL); |
82 layer_tree_host_.reset(); | 173 layer_tree_host_.reset(); |
83 } | 174 } |
84 | 175 |
85 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 176 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
86 FakeImplProxy proxy_; | 177 FakeImplProxy proxy_; |
87 FakeLayerTreeHostClient fake_client_; | 178 FakeLayerTreeHostClient fake_client_; |
88 TestSharedBitmapManager shared_bitmap_manager_; | 179 TestSharedBitmapManager shared_bitmap_manager_; |
89 FakeLayerTreeHostImpl host_impl_; | 180 FakeLayerTreeHostImpl host_impl_; |
90 }; | 181 }; |
91 | 182 |
92 TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) { | 183 TEST_F(TextureLayerTest, SyncImplWhenClearingTexture) { |
93 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 184 scoped_ptr<TestWebGraphicsContext3D> context( |
185 TestWebGraphicsContext3D::Create()); | |
186 FakeTextureLayerClient client; | |
187 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client); | |
94 ASSERT_TRUE(test_layer.get()); | 188 ASSERT_TRUE(test_layer.get()); |
189 test_layer->SetIsDrawable(true); | |
190 test_layer->SetBounds(gfx::Size(10, 10)); | |
95 | 191 |
96 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 192 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
97 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 193 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
98 layer_tree_host_->SetRootLayer(test_layer); | 194 layer_tree_host_->SetRootLayer(test_layer); |
99 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 195 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
100 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); | 196 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
101 | 197 |
198 // Clearing the texture before we gave one should not sync. | |
102 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 199 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
103 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 200 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
104 test_layer->SetTextureId(1); | 201 test_layer->ClearTexture(); |
105 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 202 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
106 | 203 |
204 // Give a texture to the layer through the client. | |
205 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | |
206 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); | |
207 client.set_texture(context->createTexture()); | |
208 test_layer->SetNeedsDisplay(); | |
209 // Force a commit. | |
210 layer_tree_host_->Composite(base::TimeTicks()); | |
211 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
danakj
2014/04/01 15:03:37
Can you verify before the Composite() call?
piman
2014/04/01 20:21:11
Done.
| |
212 | |
213 // Clearing the texture should sync. | |
107 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 214 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
108 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 215 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
109 test_layer->SetTextureId(2); | 216 test_layer->ClearTexture(); |
110 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 217 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
111 | 218 |
112 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 219 // But only once. |
220 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | |
113 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 221 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
114 test_layer->SetTextureId(0); | 222 test_layer->ClearTexture(); |
223 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
224 | |
225 // Force a commit to give another texture. | |
226 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); | |
227 test_layer->SetNeedsDisplay(); | |
228 layer_tree_host_->Composite(base::TimeTicks()); | |
229 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
danakj
2014/04/01 15:03:37
can you verify before Composite()?
piman
2014/04/01 20:21:11
Done.
| |
230 | |
231 // Make undrawable and commit. | |
232 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | |
233 test_layer->SetIsDrawable(false); | |
234 layer_tree_host_->Composite(base::TimeTicks()); | |
235 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
danakj
2014/04/01 15:03:37
and here?
piman
2014/04/01 20:21:11
Done.
| |
236 | |
237 // Clearing textures should not sync. | |
238 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | |
239 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | |
240 test_layer->ClearTexture(); | |
115 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 241 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
116 } | 242 } |
117 | 243 |
118 TEST_F(TextureLayerTest, SyncImplWhenDrawing) { | 244 TEST_F(TextureLayerTest, SyncImplWhenClearingMailbox) { |
119 gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f); | 245 CommonMailboxObjects mailboxes; |
120 | 246 FakeTextureLayerClient client; |
121 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 247 scoped_refptr<TextureLayer> test_layer = |
248 TextureLayer::CreateForMailbox(&client); | |
122 ASSERT_TRUE(test_layer.get()); | 249 ASSERT_TRUE(test_layer.get()); |
123 scoped_ptr<TextureLayerImpl> impl_layer; | 250 test_layer->SetIsDrawable(true); |
124 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 251 test_layer->SetBounds(gfx::Size(10, 10)); |
125 ASSERT_TRUE(impl_layer); | 252 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
126 | |
127 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | |
128 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 253 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
129 layer_tree_host_->SetRootLayer(test_layer); | 254 layer_tree_host_->SetRootLayer(test_layer); |
130 test_layer->SetTextureId(1); | |
131 test_layer->SetIsDrawable(true); | |
132 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 255 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
133 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); | 256 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
134 | 257 |
135 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); | 258 // Clearing the mailbox before we gave one should not sync. |
136 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 259 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
137 test_layer->WillModifyTexture(); | 260 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
261 test_layer->ClearTexture(); | |
138 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 262 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
139 | 263 |
264 // Give a mailbox to the layer through the client. | |
140 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 265 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
141 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); | 266 client.set_mailbox( |
142 test_layer->SetNeedsDisplayRect(dirty_rect); | 267 mailboxes.mailbox1_, |
268 SingleReleaseCallback::Create(mailboxes.release_mailbox1_)); | |
269 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); | |
270 test_layer->SetNeedsDisplay(); | |
271 // Force a commit. | |
272 layer_tree_host_->Composite(base::TimeTicks()); | |
143 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 273 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
danakj
2014/04/01 15:03:37
and here? .. and the rest
piman
2014/04/01 20:21:11
Done.
| |
144 | 274 |
275 // Clearing the mailbox should not sync. | |
145 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 276 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
146 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 277 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
147 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit | 278 test_layer->ClearTexture(); |
148 test_layer->SetIsDrawable(false); | |
149 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 279 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
150 | 280 |
151 // Verify that non-drawable layers don't signal the compositor, | 281 // But only once. |
danakj
2014/04/01 15:03:37
It didn't sync already, so not sure what this case
piman
2014/04/01 20:21:11
Yeah, copy&paste and fixup didn't make sense here.
| |
152 // except for the first draw after last commit, which must acquire | 282 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
153 // the texture. | 283 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
154 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); | 284 test_layer->ClearTexture(); |
155 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | |
156 test_layer->WillModifyTexture(); | |
157 test_layer->SetNeedsDisplayRect(dirty_rect); | |
158 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit | |
159 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 285 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
160 | 286 |
161 // Second draw with layer in non-drawable state: no texture | 287 // Force a commit to give another mailbox. |
162 // acquisition. | |
163 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 288 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
164 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 289 client.set_mailbox( |
165 test_layer->WillModifyTexture(); | 290 mailboxes.mailbox2_, |
166 test_layer->SetNeedsDisplayRect(dirty_rect); | 291 SingleReleaseCallback::Create(mailboxes.release_mailbox2_)); |
292 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); | |
293 test_layer->SetNeedsDisplay(); | |
294 // Commit will return mailbox1. | |
danakj
2014/04/01 15:03:37
should we commit earlier to show that the ClearTex
piman
2014/04/01 20:21:11
Done.
| |
295 EXPECT_CALL(mailboxes.mock_callback_, | |
296 Release(mailboxes.mailbox_name1_, _, false)); | |
297 layer_tree_host_->Composite(base::TimeTicks()); | |
298 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
299 | |
300 // Make undrawable and commit. | |
301 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | |
302 test_layer->SetIsDrawable(false); | |
303 layer_tree_host_->Composite(base::TimeTicks()); | |
304 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
305 | |
306 // Clearing textures should not sync. | |
307 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | |
308 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | |
309 test_layer->ClearTexture(); | |
310 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | |
311 | |
312 // Commit will return the mailbox. | |
313 EXPECT_CALL(mailboxes.mock_callback_, | |
314 Release(mailboxes.mailbox_name2_, _, false)); | |
315 layer_tree_host_->Composite(base::TimeTicks()); | |
167 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 316 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
168 } | 317 } |
169 | 318 |
170 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { | 319 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { |
320 scoped_ptr<TestWebGraphicsContext3D> context( | |
321 TestWebGraphicsContext3D::Create()); | |
171 scoped_refptr<Layer> root_layer = Layer::Create(); | 322 scoped_refptr<Layer> root_layer = Layer::Create(); |
172 ASSERT_TRUE(root_layer.get()); | 323 ASSERT_TRUE(root_layer.get()); |
173 scoped_refptr<Layer> child_layer = Layer::Create(); | 324 scoped_refptr<Layer> child_layer = Layer::Create(); |
174 ASSERT_TRUE(child_layer.get()); | 325 ASSERT_TRUE(child_layer.get()); |
175 root_layer->AddChild(child_layer); | 326 root_layer->AddChild(child_layer); |
176 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 327 FakeTextureLayerClient client; |
328 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client); | |
329 test_layer->SetIsDrawable(true); | |
330 test_layer->SetBounds(gfx::Size(10, 10)); | |
177 ASSERT_TRUE(test_layer.get()); | 331 ASSERT_TRUE(test_layer.get()); |
178 test_layer->SetTextureId(0); | |
179 child_layer->AddChild(test_layer); | 332 child_layer->AddChild(test_layer); |
180 | 333 |
181 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 334 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
182 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 335 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
183 layer_tree_host_->SetRootLayer(root_layer); | 336 layer_tree_host_->SetRootLayer(root_layer); |
184 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 337 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
185 | 338 |
186 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 339 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
187 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 340 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
188 test_layer->RemoveFromParent(); | 341 test_layer->RemoveFromParent(); |
189 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 342 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
190 | 343 |
191 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 344 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
192 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 345 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
193 child_layer->AddChild(test_layer); | 346 child_layer->AddChild(test_layer); |
194 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 347 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
195 | 348 |
349 // Give a texture to the layer through the client. | |
196 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 350 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
197 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 351 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); |
198 test_layer->SetTextureId(1); | 352 client.set_texture(context->createTexture()); |
353 test_layer->SetNeedsDisplay(); | |
354 // Force a commit. | |
355 layer_tree_host_->Composite(base::TimeTicks()); | |
199 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 356 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
200 | 357 |
201 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 358 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
202 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 359 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
203 test_layer->RemoveFromParent(); | 360 test_layer->RemoveFromParent(); |
204 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 361 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
205 } | 362 } |
206 | 363 |
207 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 364 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
208 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 365 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
209 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); | 366 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
210 | 367 |
211 // Test properties that should call SetNeedsCommit. All properties need to | 368 // Test properties that should call SetNeedsCommit. All properties need to |
212 // be set to new values in order for SetNeedsCommit to be called. | 369 // be set to new values in order for SetNeedsCommit to be called. |
213 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); | 370 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
214 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( | 371 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( |
215 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); | 372 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); |
216 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( | 373 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( |
217 0.5f, 0.5f, 0.5f, 0.5f)); | 374 0.5f, 0.5f, 0.5f, 0.5f)); |
218 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); | 375 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); |
219 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); | 376 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); |
220 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1)); | 377 EXPECT_SET_NEEDS_COMMIT(1, test_layer->ClearTexture()); |
221 | |
222 // Calling SetTextureId can call AcquireLayerTextures. | |
223 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | |
224 } | 378 } |
225 | 379 |
226 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { | 380 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { |
227 const gfx::Size layer_bounds(100, 100); | 381 const gfx::Size layer_bounds(100, 100); |
228 const gfx::Rect layer_rect(layer_bounds); | 382 const gfx::Rect layer_rect(layer_bounds); |
229 const Region layer_region(layer_rect); | 383 const Region layer_region(layer_rect); |
230 | 384 |
231 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL); | 385 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL); |
232 layer->SetBounds(layer_bounds); | 386 layer->SetBounds(layer_bounds); |
233 layer->draw_properties().visible_content_rect = layer_rect; | 387 layer->draw_properties().visible_content_rect = layer_rect; |
234 layer->SetBlendBackgroundColor(true); | 388 layer->SetBlendBackgroundColor(true); |
235 | 389 |
236 // Verify initial conditions. | 390 // Verify initial conditions. |
237 EXPECT_FALSE(layer->contents_opaque()); | 391 EXPECT_FALSE(layer->contents_opaque()); |
238 EXPECT_EQ(0u, layer->background_color()); | 392 EXPECT_EQ(0u, layer->background_color()); |
239 EXPECT_EQ(Region().ToString(), | 393 EXPECT_EQ(Region().ToString(), |
240 layer->VisibleContentOpaqueRegion().ToString()); | 394 layer->VisibleContentOpaqueRegion().ToString()); |
241 | 395 |
242 // Opaque background. | 396 // Opaque background. |
243 layer->SetBackgroundColor(SK_ColorWHITE); | 397 layer->SetBackgroundColor(SK_ColorWHITE); |
244 EXPECT_EQ(layer_region.ToString(), | 398 EXPECT_EQ(layer_region.ToString(), |
245 layer->VisibleContentOpaqueRegion().ToString()); | 399 layer->VisibleContentOpaqueRegion().ToString()); |
246 | 400 |
247 // Transparent background. | 401 // Transparent background. |
248 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); | 402 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); |
249 EXPECT_EQ(Region().ToString(), | 403 EXPECT_EQ(Region().ToString(), |
250 layer->VisibleContentOpaqueRegion().ToString()); | 404 layer->VisibleContentOpaqueRegion().ToString()); |
251 } | 405 } |
252 | 406 |
253 class FakeTextureLayerClient : public TextureLayerClient { | |
254 public: | |
255 FakeTextureLayerClient() {} | |
256 | |
257 virtual unsigned PrepareTexture() OVERRIDE { | |
258 return 0; | |
259 } | |
260 | |
261 virtual bool PrepareTextureMailbox( | |
262 TextureMailbox* mailbox, | |
263 scoped_ptr<SingleReleaseCallback>* release_callback, | |
264 bool use_shared_memory) OVERRIDE { | |
265 *mailbox = TextureMailbox(); | |
266 *release_callback = scoped_ptr<SingleReleaseCallback>(); | |
267 return true; | |
268 } | |
269 | |
270 private: | |
271 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | |
272 }; | |
273 | |
274 TEST_F(TextureLayerTest, RateLimiter) { | 407 TEST_F(TextureLayerTest, RateLimiter) { |
275 FakeTextureLayerClient client; | 408 FakeTextureLayerClient client; |
276 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( | 409 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
277 &client); | 410 &client); |
278 test_layer->SetIsDrawable(true); | 411 test_layer->SetIsDrawable(true); |
279 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 412 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
280 layer_tree_host_->SetRootLayer(test_layer); | 413 layer_tree_host_->SetRootLayer(test_layer); |
281 | 414 |
282 // Don't rate limit until we invalidate. | 415 // Don't rate limit until we invalidate. |
283 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); | 416 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
(...skipping 25 matching lines...) Expand all Loading... | |
309 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 442 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
310 layer_tree_host_->SetRootLayer(test_layer); | 443 layer_tree_host_->SetRootLayer(test_layer); |
311 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); | 444 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); |
312 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 445 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
313 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); | 446 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); |
314 test_layer->SetNeedsDisplay(); | 447 test_layer->SetNeedsDisplay(); |
315 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 448 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
316 | 449 |
317 // Stop rate limiter when we're removed from the tree. | 450 // Stop rate limiter when we're removed from the tree. |
318 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); | 451 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); |
452 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
319 layer_tree_host_->SetRootLayer(NULL); | 453 layer_tree_host_->SetRootLayer(NULL); |
320 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 454 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
321 } | 455 } |
322 | 456 |
323 class MockMailboxCallback { | |
324 public: | |
325 MOCK_METHOD3(Release, | |
326 void(const gpu::Mailbox& mailbox, | |
327 uint32 sync_point, | |
328 bool lost_resource)); | |
329 MOCK_METHOD3(Release2, | |
330 void(base::SharedMemory* shared_memory, | |
331 uint32 sync_point, | |
332 bool lost_resource)); | |
333 }; | |
334 | |
335 struct CommonMailboxObjects { | |
336 CommonMailboxObjects() | |
337 : mailbox_name1_(MailboxFromChar('1')), | |
338 mailbox_name2_(MailboxFromChar('2')), | |
339 sync_point1_(1), | |
340 sync_point2_(2), | |
341 shared_memory_(new base::SharedMemory) { | |
342 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | |
343 base::Unretained(&mock_callback_), | |
344 mailbox_name1_); | |
345 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | |
346 base::Unretained(&mock_callback_), | |
347 mailbox_name2_); | |
348 const uint32 arbitrary_target1 = 1; | |
349 const uint32 arbitrary_target2 = 2; | |
350 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); | |
351 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); | |
352 gfx::Size size(128, 128); | |
353 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | |
354 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | |
355 base::Unretained(&mock_callback_), | |
356 shared_memory_.get()); | |
357 mailbox3_ = TextureMailbox(shared_memory_.get(), size); | |
358 } | |
359 | |
360 gpu::Mailbox mailbox_name1_; | |
361 gpu::Mailbox mailbox_name2_; | |
362 MockMailboxCallback mock_callback_; | |
363 ReleaseCallback release_mailbox1_; | |
364 ReleaseCallback release_mailbox2_; | |
365 ReleaseCallback release_mailbox3_; | |
366 TextureMailbox mailbox1_; | |
367 TextureMailbox mailbox2_; | |
368 TextureMailbox mailbox3_; | |
369 uint32 sync_point1_; | |
370 uint32 sync_point2_; | |
371 scoped_ptr<base::SharedMemory> shared_memory_; | |
372 }; | |
373 | |
374 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { | 457 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { |
375 public: | 458 public: |
376 using TextureLayer::TextureMailboxHolder::Create; | 459 using TextureLayer::TextureMailboxHolder::Create; |
377 | 460 |
378 protected: | 461 protected: |
379 virtual ~TestMailboxHolder() {} | 462 virtual ~TestMailboxHolder() {} |
380 }; | 463 }; |
381 | 464 |
382 class TextureLayerWithMailboxTest : public TextureLayerTest { | 465 class TextureLayerWithMailboxTest : public TextureLayerTest { |
383 protected: | 466 protected: |
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2192 int callback_count_; | 2275 int callback_count_; |
2193 scoped_refptr<Layer> root_; | 2276 scoped_refptr<Layer> root_; |
2194 scoped_refptr<TextureLayer> layer_; | 2277 scoped_refptr<TextureLayer> layer_; |
2195 }; | 2278 }; |
2196 | 2279 |
2197 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 2280 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
2198 TextureLayerWithMailboxImplThreadDeleted); | 2281 TextureLayerWithMailboxImplThreadDeleted); |
2199 | 2282 |
2200 } // namespace | 2283 } // namespace |
2201 } // namespace cc | 2284 } // namespace cc |
OLD | NEW |