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

Side by Side Diff: gpu/command_buffer/service/mailbox_manager_unittest.cc

Issue 180723023: gpu: Mailbox emulation with EGLImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 6 years, 9 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
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 "gpu/command_buffer/service/mailbox_manager.h" 5 #include "gpu/command_buffer/service/mailbox_manager.h"
6 6
7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/mailbox_synchronizer.h"
7 #include "gpu/command_buffer/service/texture_manager.h" 9 #include "gpu/command_buffer/service/texture_manager.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gl/gl_mock.h"
9 12
10 namespace gpu { 13 namespace gpu {
11 namespace gles2 { 14 namespace gles2 {
12 15
16 using namespace ::testing;
17
13 class MailboxManagerTest : public testing::Test { 18 class MailboxManagerTest : public testing::Test {
14 public: 19 public:
15 MailboxManagerTest() : manager_(new MailboxManager()) {} 20 MailboxManagerTest() {}
16 virtual ~MailboxManagerTest() {} 21 virtual ~MailboxManagerTest() {}
17 22
18 protected: 23 protected:
24 virtual void SetUp() {
25 testing::Test::SetUp();
26 feature_info_ = new FeatureInfo;
27 manager_ = new MailboxManager;
28 }
29
19 Texture* CreateTexture() { 30 Texture* CreateTexture() {
20 return new Texture(0); 31 return new Texture(1);
32 }
33
34 void SetTarget(Texture* texture, GLenum target, GLuint max_level) {
35 texture->SetTarget(NULL, target, max_level);
36 }
37
38 void SetLevelInfo(
39 Texture* texture,
40 GLenum target,
41 GLint level,
42 GLenum internal_format,
43 GLsizei width,
44 GLsizei height,
45 GLsizei depth,
46 GLint border,
47 GLenum format,
48 GLenum type,
49 bool cleared) {
50 texture->SetLevelInfo(NULL,
51 target,
52 level,
53 internal_format,
54 width,
55 height,
56 depth,
57 border,
58 format,
59 type,
60 cleared);
61 }
62
63 GLenum SetParameter(Texture* texture, GLenum pname, GLint param) {
64 return texture->SetParameteri(feature_info_, pname, param);
21 } 65 }
22 66
23 void DestroyTexture(Texture* texture) { 67 void DestroyTexture(Texture* texture) {
24 delete texture; 68 delete texture;
25 } 69 }
26 70
27 scoped_refptr<MailboxManager> manager_; 71 scoped_refptr<MailboxManager> manager_;
28 72
29 private: 73 private:
74 scoped_refptr<FeatureInfo> feature_info_;
75
30 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); 76 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest);
31 }; 77 };
32 78
33 // Tests basic produce/consume behavior. 79 // Tests basic produce/consume behavior.
34 TEST_F(MailboxManagerTest, Basic) { 80 TEST_F(MailboxManagerTest, Basic) {
35 Texture* texture = CreateTexture(); 81 Texture* texture = CreateTexture();
36 82
37 Mailbox name = Mailbox::Generate(); 83 Mailbox name = Mailbox::Generate();
38 manager_->ProduceTexture(0, name, texture); 84 manager_->ProduceTexture(0, name, texture);
39 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name)); 85 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 165
120 // Destroy texture1, shouldn't affect name2. 166 // Destroy texture1, shouldn't affect name2.
121 DestroyTexture(texture1); 167 DestroyTexture(texture1);
122 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1)); 168 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1));
123 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2)); 169 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2));
124 170
125 DestroyTexture(texture2); 171 DestroyTexture(texture2);
126 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2)); 172 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2));
127 } 173 }
128 174
175 const GLsizei kMaxTextureWidth = 64;
176 const GLsizei kMaxTextureHeight = 64;
177 const GLsizei kMaxTextureDepth = 1;
178
179 class MailboxManagerSyncTest : public MailboxManagerTest {
180 public:
181 MailboxManagerSyncTest() {}
182 virtual ~MailboxManagerSyncTest() {}
183
184 protected:
185 virtual void SetUp() {
186 MailboxSynchronizer::Initialize();
187 MailboxManagerTest::SetUp();
188 manager2_ = new MailboxManager;
189 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
190 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
191 }
192
193 Texture* DefineTexture() {
194 Texture* texture = CreateTexture();
195 const GLsizei levels_needed = TextureManager::ComputeMipMapCount(
196 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth);
197 SetTarget(texture, GL_TEXTURE_2D, levels_needed);
198 SetLevelInfo(texture,
199 GL_TEXTURE_2D,
200 0,
201 GL_RGBA,
202 1,
203 1,
204 1,
205 0,
206 GL_RGBA,
207 GL_UNSIGNED_BYTE,
208 true);
209 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
210 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
211 return texture;
212 }
213
214 void SetupUpdateTexParamExpectations(GLuint texture_id,
215 GLenum min,
216 GLenum mag,
217 GLenum wrap_s,
218 GLenum wrap_t) {
219 DCHECK(texture_id);
220 const GLuint kCurrentTexture = 0;
221 EXPECT_CALL(*gl_, GetIntegerv(GL_TEXTURE_BINDING_2D, _))
222 .WillOnce(SetArgPointee<1>(kCurrentTexture))
223 .RetiresOnSaturation();
224 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, texture_id))
225 .Times(1)
226 .RetiresOnSaturation();
227 EXPECT_CALL(*gl_,
228 TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min))
229 .Times(1)
230 .RetiresOnSaturation();
231 EXPECT_CALL(*gl_,
232 TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag))
233 .Times(1)
234 .RetiresOnSaturation();
235 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s))
236 .Times(1)
237 .RetiresOnSaturation();
238 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t))
239 .Times(1)
240 .RetiresOnSaturation();
241 EXPECT_CALL(*gl_, Flush())
242 .Times(1)
243 .RetiresOnSaturation();
244 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture))
245 .Times(1)
246 .RetiresOnSaturation();
247 }
248
249 virtual void TearDown() {
250 MailboxManagerTest::TearDown();
251 MailboxSynchronizer::Terminate();
252 ::gfx::MockGLInterface::SetGLInterface(NULL);
253 gl_.reset();
254 }
255
256 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
257 scoped_refptr<MailboxManager> manager2_;
258
259 private:
260 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest);
261 };
262
263 TEST_F(MailboxManagerSyncTest, ProduceDestroy) {
264 Texture* texture = DefineTexture();
265 Mailbox name = Mailbox::Generate();
266
267 InSequence sequence;
268 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
269 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
270
271 DestroyTexture(texture);
272 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
273 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
274 }
275
276 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) {
277 InSequence sequence;
278
279 Texture* texture = DefineTexture();
280 Mailbox name = Mailbox::Generate();
281
282 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
283 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
284
285 // Synchronize
286 EXPECT_CALL(*gl_, Flush()).Times(1);
287 manager_->PushTextureUpdates();
288 manager2_->PullTextureUpdates();
289
290 DestroyTexture(texture);
291 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
292 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
293 }
294
295 // Duplicates a texture into a second manager instance, and then
296 // makes sure a redefinition becomes visible there too.
297 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) {
298 const GLuint kNewTextureId = 1234;
299 InSequence sequence;
300
301 Texture* texture = DefineTexture();
302 Mailbox name = Mailbox::Generate();
303
304 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
305 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
306
307 // Synchronize
308 EXPECT_CALL(*gl_, Flush()).Times(1);
309 manager_->PushTextureUpdates();
310 manager2_->PullTextureUpdates();
311
312 EXPECT_CALL(*gl_, GenTextures(1, _))
313 .WillOnce(SetArgPointee<1>(kNewTextureId));
314 SetupUpdateTexParamExpectations(
315 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
316 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name);
317 EXPECT_FALSE(new_texture == NULL);
318 EXPECT_NE(texture, new_texture);
319 EXPECT_EQ(kNewTextureId, new_texture->service_id());
320
321 // Resize original texture
322 SetLevelInfo(texture,
323 GL_TEXTURE_2D,
324 0,
325 GL_RGBA,
326 16,
327 32,
328 1,
329 0,
330 GL_RGBA,
331 GL_UNSIGNED_BYTE,
332 true);
333 // Should have been orphaned
334 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
335
336 // Synchronize again
337 EXPECT_CALL(*gl_, Flush()).Times(1);
338 manager_->PushTextureUpdates();
339 SetupUpdateTexParamExpectations(
340 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
341 manager2_->PullTextureUpdates();
342 GLsizei width, height;
343 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height);
344 EXPECT_EQ(16, width);
345 EXPECT_EQ(32, height);
346
347 DestroyTexture(texture);
348 // Should be still around since there is a ref from manager2.
349 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
350
351 DestroyTexture(new_texture);
352 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
353 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
354 }
355
356 // Makes sure changes are correctly published even when updates are
357 // pushed in both directions, i.e. makes sure we don't clobber a shared
358 // texture definition with an older version.
359 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) {
360 const GLuint kNewTextureId1 = 1234;
361 const GLuint kNewTextureId2 = 4321;
362
363 Texture* texture1 = DefineTexture();
364 Mailbox name1 = Mailbox::Generate();
365 Texture* texture2 = DefineTexture();
366 Mailbox name2 = Mailbox::Generate();
367 Texture* new_texture1 = NULL;
368 Texture* new_texture2 = NULL;
369
370 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1);
371 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2);
372
373 // Make visible.
374 EXPECT_CALL(*gl_, Flush()).Times(2);
375 manager_->PushTextureUpdates();
376 manager2_->PushTextureUpdates();
377
378 // Create textures in the other manager instances for texture1 and texture2,
379 // respectively to create a real sharing scenario. Otherwise, there would
380 // never be conflicting updates/pushes.
381 {
382 InSequence sequence;
383 EXPECT_CALL(*gl_, GenTextures(1, _))
384 .WillOnce(SetArgPointee<1>(kNewTextureId1));
385 SetupUpdateTexParamExpectations(
386 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
387 new_texture1 = manager2_->ConsumeTexture(GL_TEXTURE_2D, name1);
388 EXPECT_CALL(*gl_, GenTextures(1, _))
389 .WillOnce(SetArgPointee<1>(kNewTextureId2));
390 SetupUpdateTexParamExpectations(
391 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
392 new_texture2 = manager_->ConsumeTexture(GL_TEXTURE_2D, name2);
393 }
394 EXPECT_EQ(kNewTextureId1, new_texture1->service_id());
395 EXPECT_EQ(kNewTextureId2, new_texture2->service_id());
396
397 // Make a change to texture1
398 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter());
399 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
400 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
401
402 // Make sure this does not clobber it with the previous version we pushed.
403 manager_->PullTextureUpdates();
404
405 // Make a change to texture2
406 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter());
407 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
408 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
409
410 Mock::VerifyAndClearExpectations(gl_.get());
411
412 // Synchronize in both directions
413 EXPECT_CALL(*gl_, Flush()).Times(2);
414 manager_->PushTextureUpdates();
415 manager2_->PushTextureUpdates();
416 // manager1 should see the change to texture2 mag_filter being applied.
417 SetupUpdateTexParamExpectations(
418 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
419 manager_->PullTextureUpdates();
420 // manager2 should see the change to texture1 min_filter being applied.
421 SetupUpdateTexParamExpectations(
422 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
423 manager2_->PullTextureUpdates();
424
425 DestroyTexture(texture1);
426 DestroyTexture(texture2);
427 DestroyTexture(new_texture1);
428 DestroyTexture(new_texture2);
429 }
430
431 // TODO: different texture into same mailbox
432
433 // TODO: same texture, multiple mailboxes
434
435 // TODO: Produce incomplete texture
436
437 // TODO: Texture::level_infos_[][].size()
438
439 // TODO: unsupported targets and formats
440
129 } // namespace gles2 441 } // namespace gles2
130 } // namespace gpu 442 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698