OLD | NEW |
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" | 7 #include "gpu/command_buffer/service/feature_info.h" |
| 8 #include "gpu/command_buffer/service/gpu_service_test.h" |
8 #include "gpu/command_buffer/service/mailbox_synchronizer.h" | 9 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
9 #include "gpu/command_buffer/service/texture_manager.h" | 10 #include "gpu/command_buffer/service/texture_manager.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/gl/gl_context_stub.h" | 12 #include "ui/gl/gl_context_stub.h" |
12 #include "ui/gl/gl_mock.h" | 13 #include "ui/gl/gl_mock.h" |
13 #include "ui/gl/gl_surface_stub.h" | 14 #include "ui/gl/gl_surface_stub.h" |
14 | 15 |
15 namespace gpu { | 16 namespace gpu { |
16 namespace gles2 { | 17 namespace gles2 { |
17 | 18 |
18 using namespace ::testing; | 19 using namespace ::testing; |
19 | 20 |
20 class MailboxManagerTest : public testing::Test { | 21 class MailboxManagerTest : public GpuServiceTest { |
21 public: | 22 public: |
22 MailboxManagerTest() {} | 23 MailboxManagerTest() : initialized_synchronizer_(false) {} |
23 virtual ~MailboxManagerTest() {} | 24 virtual ~MailboxManagerTest() {} |
24 | 25 |
25 protected: | 26 protected: |
26 virtual void SetUp() { | 27 virtual void SetUp() { |
27 testing::Test::SetUp(); | 28 GpuServiceTest::SetUp(); |
28 feature_info_ = new FeatureInfo; | 29 feature_info_ = new FeatureInfo; |
29 manager_ = new MailboxManager; | 30 manager_ = new MailboxManager; |
30 } | 31 } |
31 | 32 |
| 33 virtual void SetUpWithSynchronizer() { |
| 34 GpuServiceTest::SetUp(); |
| 35 MailboxSynchronizer::Initialize(); |
| 36 initialized_synchronizer_ = true; |
| 37 feature_info_ = new FeatureInfo; |
| 38 manager_ = new MailboxManager; |
| 39 } |
| 40 |
| 41 virtual void TearDown() { |
| 42 if (initialized_synchronizer_) |
| 43 MailboxSynchronizer::Terminate(); |
| 44 GpuServiceTest::TearDown(); |
| 45 } |
| 46 |
32 Texture* CreateTexture() { | 47 Texture* CreateTexture() { |
33 return new Texture(1); | 48 return new Texture(1); |
34 } | 49 } |
35 | 50 |
36 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { | 51 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { |
37 texture->SetTarget(NULL, target, max_level); | 52 texture->SetTarget(NULL, target, max_level); |
38 } | 53 } |
39 | 54 |
40 void SetLevelInfo( | 55 void SetLevelInfo( |
41 Texture* texture, | 56 Texture* texture, |
(...skipping 24 matching lines...) Expand all Loading... |
66 return texture->SetParameteri(feature_info_, pname, param); | 81 return texture->SetParameteri(feature_info_, pname, param); |
67 } | 82 } |
68 | 83 |
69 void DestroyTexture(Texture* texture) { | 84 void DestroyTexture(Texture* texture) { |
70 delete texture; | 85 delete texture; |
71 } | 86 } |
72 | 87 |
73 scoped_refptr<MailboxManager> manager_; | 88 scoped_refptr<MailboxManager> manager_; |
74 | 89 |
75 private: | 90 private: |
| 91 bool initialized_synchronizer_; |
76 scoped_refptr<FeatureInfo> feature_info_; | 92 scoped_refptr<FeatureInfo> feature_info_; |
77 | 93 |
78 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); | 94 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); |
79 }; | 95 }; |
80 | 96 |
81 // Tests basic produce/consume behavior. | 97 // Tests basic produce/consume behavior. |
82 TEST_F(MailboxManagerTest, Basic) { | 98 TEST_F(MailboxManagerTest, Basic) { |
83 Texture* texture = CreateTexture(); | 99 Texture* texture = CreateTexture(); |
84 | 100 |
85 Mailbox name = Mailbox::Generate(); | 101 Mailbox name = Mailbox::Generate(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 const GLsizei kMaxTextureHeight = 64; | 194 const GLsizei kMaxTextureHeight = 64; |
179 const GLsizei kMaxTextureDepth = 1; | 195 const GLsizei kMaxTextureDepth = 1; |
180 | 196 |
181 class MailboxManagerSyncTest : public MailboxManagerTest { | 197 class MailboxManagerSyncTest : public MailboxManagerTest { |
182 public: | 198 public: |
183 MailboxManagerSyncTest() {} | 199 MailboxManagerSyncTest() {} |
184 virtual ~MailboxManagerSyncTest() {} | 200 virtual ~MailboxManagerSyncTest() {} |
185 | 201 |
186 protected: | 202 protected: |
187 virtual void SetUp() { | 203 virtual void SetUp() { |
188 MailboxSynchronizer::Initialize(); | 204 MailboxManagerTest::SetUpWithSynchronizer(); |
189 MailboxManagerTest::SetUp(); | |
190 manager2_ = new MailboxManager; | 205 manager2_ = new MailboxManager; |
191 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | |
192 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | |
193 context_ = new gfx::GLContextStub(); | 206 context_ = new gfx::GLContextStub(); |
194 surface_ = new gfx::GLSurfaceStub(); | 207 surface_ = new gfx::GLSurfaceStub(); |
195 context_->MakeCurrent(surface_); | 208 context_->MakeCurrent(surface_); |
196 } | 209 } |
197 | 210 |
198 Texture* DefineTexture() { | 211 Texture* DefineTexture() { |
199 Texture* texture = CreateTexture(); | 212 Texture* texture = CreateTexture(); |
200 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( | 213 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( |
201 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); | 214 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); |
202 SetTarget(texture, GL_TEXTURE_2D, levels_needed); | 215 SetTarget(texture, GL_TEXTURE_2D, levels_needed); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 .RetiresOnSaturation(); | 258 .RetiresOnSaturation(); |
246 EXPECT_CALL(*gl_, Flush()) | 259 EXPECT_CALL(*gl_, Flush()) |
247 .Times(1) | 260 .Times(1) |
248 .RetiresOnSaturation(); | 261 .RetiresOnSaturation(); |
249 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) | 262 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) |
250 .Times(1) | 263 .Times(1) |
251 .RetiresOnSaturation(); | 264 .RetiresOnSaturation(); |
252 } | 265 } |
253 | 266 |
254 virtual void TearDown() { | 267 virtual void TearDown() { |
| 268 context_->ReleaseCurrent(NULL); |
255 MailboxManagerTest::TearDown(); | 269 MailboxManagerTest::TearDown(); |
256 MailboxSynchronizer::Terminate(); | |
257 context_->ReleaseCurrent(NULL); | |
258 ::gfx::MockGLInterface::SetGLInterface(NULL); | |
259 gl_.reset(); | |
260 } | 270 } |
261 | 271 |
262 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | |
263 scoped_refptr<MailboxManager> manager2_; | 272 scoped_refptr<MailboxManager> manager2_; |
264 scoped_refptr<gfx::GLContext> context_; | 273 scoped_refptr<gfx::GLContext> context_; |
265 scoped_refptr<gfx::GLSurface> surface_; | 274 scoped_refptr<gfx::GLSurface> surface_; |
266 | 275 |
267 private: | 276 private: |
268 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); | 277 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); |
269 }; | 278 }; |
270 | 279 |
271 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { | 280 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { |
272 Texture* texture = DefineTexture(); | 281 Texture* texture = DefineTexture(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 // TODO: same texture, multiple mailboxes | 470 // TODO: same texture, multiple mailboxes |
462 | 471 |
463 // TODO: Produce incomplete texture | 472 // TODO: Produce incomplete texture |
464 | 473 |
465 // TODO: Texture::level_infos_[][].size() | 474 // TODO: Texture::level_infos_[][].size() |
466 | 475 |
467 // TODO: unsupported targets and formats | 476 // TODO: unsupported targets and formats |
468 | 477 |
469 } // namespace gles2 | 478 } // namespace gles2 |
470 } // namespace gpu | 479 } // namespace gpu |
OLD | NEW |