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

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

Issue 213743005: cc: Remove TextureLayer::SetTextureId and TextureLayer::WillModifyTexture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/layers/texture_layer.cc ('k') | content/shell/renderer/test_runner/TestPlugin.cpp » ('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 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
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 = GL_TEXTURE_2D;
127 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
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.
199 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
200 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
201 test_layer->ClearTexture();
202 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
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 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
210 // Force a commit.
211 layer_tree_host_->Composite(base::TimeTicks());
212
213 // Clearing the texture should sync.
214 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
215 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
216 test_layer->ClearTexture();
217 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
218
219 // But only once.
220 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
221 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(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 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
229 layer_tree_host_->Composite(base::TimeTicks());
230
231 // Make undrawable and commit.
232 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
233 test_layer->SetIsDrawable(false);
234 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
235 layer_tree_host_->Composite(base::TimeTicks());
236
237 // Clearing textures should not sync.
102 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 238 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
103 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 239 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
104 test_layer->SetTextureId(1); 240 test_layer->ClearTexture();
105 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
106
107 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
108 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
109 test_layer->SetTextureId(2);
110 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
111
112 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
113 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
114 test_layer->SetTextureId(0);
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 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
272 // Force a commit.
273 layer_tree_host_->Composite(base::TimeTicks());
274
275 // Clearing the mailbox should not sync.
276 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
277 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
278 test_layer->ClearTexture();
143 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 279 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
144 280
145 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 281 // Commit will return mailbox1.
146 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); 282 EXPECT_CALL(mailboxes.mock_callback_,
147 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit 283 Release(mailboxes.mailbox_name1_, _, false));
148 test_layer->SetIsDrawable(false); 284 layer_tree_host_->Composite(base::TimeTicks());
149 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 285 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
150 286
151 // Verify that non-drawable layers don't signal the compositor, 287 // Force a commit to give another mailbox.
152 // except for the first draw after last commit, which must acquire 288 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
153 // the texture. 289 client.set_mailbox(
154 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); 290 mailboxes.mailbox2_,
155 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); 291 SingleReleaseCallback::Create(mailboxes.release_mailbox2_));
156 test_layer->WillModifyTexture(); 292 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1));
157 test_layer->SetNeedsDisplayRect(dirty_rect); 293 test_layer->SetNeedsDisplay();
158 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit 294 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
295 layer_tree_host_->Composite(base::TimeTicks());
296
297 // Make undrawable and commit.
298 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
299 test_layer->SetIsDrawable(false);
300 layer_tree_host_->Composite(base::TimeTicks());
159 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 301 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
160 302
161 // Second draw with layer in non-drawable state: no texture 303 // Clearing textures should not sync.
162 // acquisition.
163 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 304 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
164 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); 305 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
165 test_layer->WillModifyTexture(); 306 test_layer->ClearTexture();
166 test_layer->SetNeedsDisplayRect(dirty_rect); 307 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
308
309 // Commit will return the mailbox.
310 EXPECT_CALL(mailboxes.mock_callback_,
311 Release(mailboxes.mailbox_name2_, _, false));
312 layer_tree_host_->Composite(base::TimeTicks());
167 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 313 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
168 } 314 }
169 315
170 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { 316 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) {
317 scoped_ptr<TestWebGraphicsContext3D> context(
318 TestWebGraphicsContext3D::Create());
171 scoped_refptr<Layer> root_layer = Layer::Create(); 319 scoped_refptr<Layer> root_layer = Layer::Create();
172 ASSERT_TRUE(root_layer.get()); 320 ASSERT_TRUE(root_layer.get());
173 scoped_refptr<Layer> child_layer = Layer::Create(); 321 scoped_refptr<Layer> child_layer = Layer::Create();
174 ASSERT_TRUE(child_layer.get()); 322 ASSERT_TRUE(child_layer.get());
175 root_layer->AddChild(child_layer); 323 root_layer->AddChild(child_layer);
176 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); 324 FakeTextureLayerClient client;
325 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client);
326 test_layer->SetIsDrawable(true);
327 test_layer->SetBounds(gfx::Size(10, 10));
177 ASSERT_TRUE(test_layer.get()); 328 ASSERT_TRUE(test_layer.get());
178 test_layer->SetTextureId(0);
179 child_layer->AddChild(test_layer); 329 child_layer->AddChild(test_layer);
180 330
181 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); 331 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
182 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 332 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
183 layer_tree_host_->SetRootLayer(root_layer); 333 layer_tree_host_->SetRootLayer(root_layer);
184 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 334 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
185 335
186 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 336 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
187 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 337 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
188 test_layer->RemoveFromParent(); 338 test_layer->RemoveFromParent();
189 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 339 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
190 340
191 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 341 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
192 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 342 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
193 child_layer->AddChild(test_layer); 343 child_layer->AddChild(test_layer);
194 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 344 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
195 345
346 // Give a texture to the layer through the client.
196 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 347 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
197 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 348 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1));
198 test_layer->SetTextureId(1); 349 client.set_texture(context->createTexture());
350 test_layer->SetNeedsDisplay();
199 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 351 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
352 // Force a commit.
353 layer_tree_host_->Composite(base::TimeTicks());
200 354
201 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); 355 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
202 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 356 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
203 test_layer->RemoveFromParent(); 357 test_layer->RemoveFromParent();
204 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 358 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
205 } 359 }
206 360
207 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { 361 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
208 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); 362 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
209 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); 363 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer));
210 364
211 // Test properties that should call SetNeedsCommit. All properties need to 365 // Test properties that should call SetNeedsCommit. All properties need to
212 // be set to new values in order for SetNeedsCommit to be called. 366 // be set to new values in order for SetNeedsCommit to be called.
213 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); 367 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
214 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( 368 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
215 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); 369 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
216 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( 370 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
217 0.5f, 0.5f, 0.5f, 0.5f)); 371 0.5f, 0.5f, 0.5f, 0.5f));
218 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); 372 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
219 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); 373 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
220 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1));
221
222 // Calling SetTextureId can call AcquireLayerTextures.
223 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
224 } 374 }
225 375
226 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { 376 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) {
227 const gfx::Size layer_bounds(100, 100); 377 const gfx::Size layer_bounds(100, 100);
228 const gfx::Rect layer_rect(layer_bounds); 378 const gfx::Rect layer_rect(layer_bounds);
229 const Region layer_region(layer_rect); 379 const Region layer_region(layer_rect);
230 380
231 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL); 381 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL);
232 layer->SetBounds(layer_bounds); 382 layer->SetBounds(layer_bounds);
233 layer->draw_properties().visible_content_rect = layer_rect; 383 layer->draw_properties().visible_content_rect = layer_rect;
234 layer->SetBlendBackgroundColor(true); 384 layer->SetBlendBackgroundColor(true);
235 385
236 // Verify initial conditions. 386 // Verify initial conditions.
237 EXPECT_FALSE(layer->contents_opaque()); 387 EXPECT_FALSE(layer->contents_opaque());
238 EXPECT_EQ(0u, layer->background_color()); 388 EXPECT_EQ(0u, layer->background_color());
239 EXPECT_EQ(Region().ToString(), 389 EXPECT_EQ(Region().ToString(),
240 layer->VisibleContentOpaqueRegion().ToString()); 390 layer->VisibleContentOpaqueRegion().ToString());
241 391
242 // Opaque background. 392 // Opaque background.
243 layer->SetBackgroundColor(SK_ColorWHITE); 393 layer->SetBackgroundColor(SK_ColorWHITE);
244 EXPECT_EQ(layer_region.ToString(), 394 EXPECT_EQ(layer_region.ToString(),
245 layer->VisibleContentOpaqueRegion().ToString()); 395 layer->VisibleContentOpaqueRegion().ToString());
246 396
247 // Transparent background. 397 // Transparent background.
248 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); 398 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255));
249 EXPECT_EQ(Region().ToString(), 399 EXPECT_EQ(Region().ToString(),
250 layer->VisibleContentOpaqueRegion().ToString()); 400 layer->VisibleContentOpaqueRegion().ToString());
251 } 401 }
252 402
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) { 403 TEST_F(TextureLayerTest, RateLimiter) {
275 FakeTextureLayerClient client; 404 FakeTextureLayerClient client;
276 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( 405 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(
277 &client); 406 &client);
278 test_layer->SetIsDrawable(true); 407 test_layer->SetIsDrawable(true);
279 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 408 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
280 layer_tree_host_->SetRootLayer(test_layer); 409 layer_tree_host_->SetRootLayer(test_layer);
281 410
282 // Don't rate limit until we invalidate. 411 // Don't rate limit until we invalidate.
283 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); 412 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0);
(...skipping 25 matching lines...) Expand all
309 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 438 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
310 layer_tree_host_->SetRootLayer(test_layer); 439 layer_tree_host_->SetRootLayer(test_layer);
311 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); 440 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0);
312 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 441 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
313 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); 442 EXPECT_CALL(*layer_tree_host_, StartRateLimiter());
314 test_layer->SetNeedsDisplay(); 443 test_layer->SetNeedsDisplay();
315 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 444 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
316 445
317 // Stop rate limiter when we're removed from the tree. 446 // Stop rate limiter when we're removed from the tree.
318 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); 447 EXPECT_CALL(*layer_tree_host_, StopRateLimiter());
448 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
319 layer_tree_host_->SetRootLayer(NULL); 449 layer_tree_host_->SetRootLayer(NULL);
320 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 450 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
321 } 451 }
322 452
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 { 453 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
375 public: 454 public:
376 using TextureLayer::TextureMailboxHolder::Create; 455 using TextureLayer::TextureMailboxHolder::Create;
377 456
378 protected: 457 protected:
379 virtual ~TestMailboxHolder() {} 458 virtual ~TestMailboxHolder() {}
380 }; 459 };
381 460
382 class TextureLayerWithMailboxTest : public TextureLayerTest { 461 class TextureLayerWithMailboxTest : public TextureLayerTest {
383 protected: 462 protected:
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 int callback_count_; 2271 int callback_count_;
2193 scoped_refptr<Layer> root_; 2272 scoped_refptr<Layer> root_;
2194 scoped_refptr<TextureLayer> layer_; 2273 scoped_refptr<TextureLayer> layer_;
2195 }; 2274 };
2196 2275
2197 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 2276 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
2198 TextureLayerWithMailboxImplThreadDeleted); 2277 TextureLayerWithMailboxImplThreadDeleted);
2199 2278
2200 } // namespace 2279 } // namespace
2201 } // namespace cc 2280 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/texture_layer.cc ('k') | content/shell/renderer/test_runner/TestPlugin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698