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

Side by Side Diff: components/display_compositor/buffer_queue_unittest.cc

Issue 2002303002: Consolidate OutputSurface constructors into GL vs Vulkan. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: outputsurface-constructors: rebase-and-fixcrash Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/display_compositor/buffer_queue.h" 5 #include "components/display_compositor/buffer_queue.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 #if defined(OS_WIN) 79 #if defined(OS_WIN)
80 const gpu::SurfaceHandle kFakeSurfaceHandle = 80 const gpu::SurfaceHandle kFakeSurfaceHandle =
81 reinterpret_cast<gpu::SurfaceHandle>(1); 81 reinterpret_cast<gpu::SurfaceHandle>(1);
82 #else 82 #else
83 const gpu::SurfaceHandle kFakeSurfaceHandle = 1; 83 const gpu::SurfaceHandle kFakeSurfaceHandle = 1;
84 #endif 84 #endif
85 85
86 class MockBufferQueue : public BufferQueue { 86 class MockBufferQueue : public BufferQueue {
87 public: 87 public:
88 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider, 88 MockBufferQueue(gpu::gles2::GLES2Interface* gl,
89 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 89 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
90 unsigned int target, 90 unsigned int target,
91 unsigned int internalformat) 91 unsigned int internalformat)
92 : BufferQueue(context_provider, 92 : BufferQueue(gl,
93 target, 93 target,
94 internalformat, 94 internalformat,
95 nullptr, 95 nullptr,
96 gpu_memory_buffer_manager, 96 gpu_memory_buffer_manager,
97 kFakeSurfaceHandle) {} 97 kFakeSurfaceHandle) {}
98 MOCK_METHOD4(CopyBufferDamage, 98 MOCK_METHOD4(CopyBufferDamage,
99 void(int, int, const gfx::Rect&, const gfx::Rect&)); 99 void(int, int, const gfx::Rect&, const gfx::Rect&));
100 }; 100 };
101 101
102 class BufferQueueTest : public ::testing::Test { 102 class BufferQueueTest : public ::testing::Test {
103 public: 103 public:
104 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {} 104 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {}
105 105
106 void SetUp() override { 106 void SetUp() override {
107 InitWithContext(cc::TestWebGraphicsContext3D::Create()); 107 InitWithContext(cc::TestWebGraphicsContext3D::Create());
108 } 108 }
109 109
110 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { 110 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) {
111 scoped_refptr<cc::TestContextProvider> context_provider = 111 context_provider_ = cc::TestContextProvider::Create(std::move(context));
112 cc::TestContextProvider::Create(std::move(context)); 112 context_provider_->BindToCurrentThread();
113 context_provider->BindToCurrentThread();
114 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); 113 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager);
115 mock_output_surface_ = 114 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(),
116 new MockBufferQueue(context_provider, gpu_memory_buffer_manager_.get(), 115 gpu_memory_buffer_manager_.get(),
117 GL_TEXTURE_2D, GL_RGBA); 116 GL_TEXTURE_2D, GL_RGBA);
118 output_surface_.reset(mock_output_surface_); 117 output_surface_.reset(mock_output_surface_);
119 output_surface_->Initialize(); 118 output_surface_->Initialize();
120 } 119 }
121 120
122 unsigned current_surface() { 121 unsigned current_surface() {
123 return output_surface_->current_surface_ 122 return output_surface_->current_surface_
124 ? output_surface_->current_surface_->image 123 ? output_surface_->current_surface_->image
125 : 0; 124 : 0;
126 } 125 }
127 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>& 126 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 protected: 184 protected:
186 bool InsertUnique(std::set<unsigned>* set, unsigned value) { 185 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
187 if (!value) 186 if (!value)
188 return true; 187 return true;
189 if (set->find(value) != set->end()) 188 if (set->find(value) != set->end())
190 return false; 189 return false;
191 set->insert(value); 190 set->insert(value);
192 return true; 191 return true;
193 } 192 }
194 193
194 scoped_refptr<cc::TestContextProvider> context_provider_;
195 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager_; 195 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager_;
196 std::unique_ptr<BufferQueue> output_surface_; 196 std::unique_ptr<BufferQueue> output_surface_;
197 MockBufferQueue* mock_output_surface_; 197 MockBufferQueue* mock_output_surface_;
198 bool doublebuffering_; 198 bool doublebuffering_;
199 bool first_frame_; 199 bool first_frame_;
200 }; 200 };
201 201
202 namespace { 202 namespace {
203 const gfx::Size screen_size = gfx::Size(30, 30); 203 const gfx::Size screen_size = gfx::Size(30, 30);
204 const gfx::Rect screen_rect = gfx::Rect(screen_size); 204 const gfx::Rect screen_rect = gfx::Rect(screen_size);
(...skipping 26 matching lines...) Expand all
231 public: 231 public:
232 void SetUp() override { 232 void SetUp() override {
233 context_ = new MockedContext(); 233 context_ = new MockedContext();
234 InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D>(context_)); 234 InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D>(context_));
235 } 235 }
236 236
237 protected: 237 protected:
238 MockedContext* context_; 238 MockedContext* context_;
239 }; 239 };
240 240
241 std::unique_ptr<BufferQueue> CreateOutputSurfaceWithMock( 241 scoped_refptr<cc::TestContextProvider> CreateMockedContextProvider(
242 MockedContext** context) {
243 std::unique_ptr<MockedContext> owned_context(new MockedContext);
244 *context = owned_context.get();
245 scoped_refptr<cc::TestContextProvider> context_provider =
246 cc::TestContextProvider::Create(std::move(owned_context));
247 context_provider->BindToCurrentThread();
248 return context_provider;
249 }
250
251 std::unique_ptr<BufferQueue> CreateBufferQueue(
242 unsigned int target, 252 unsigned int target,
243 MockedContext** context, 253 gpu::gles2::GLES2Interface* gl,
244 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { 254 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
245 *context = new MockedContext();
246 scoped_refptr<cc::TestContextProvider> context_provider =
247 cc::TestContextProvider::Create(
248 std::unique_ptr<cc::TestWebGraphicsContext3D>(*context));
249 context_provider->BindToCurrentThread();
250 std::unique_ptr<BufferQueue> buffer_queue( 255 std::unique_ptr<BufferQueue> buffer_queue(
251 new BufferQueue(context_provider, target, GL_RGBA, nullptr, 256 new BufferQueue(gl, target, GL_RGBA, nullptr, gpu_memory_buffer_manager,
252 gpu_memory_buffer_manager, kFakeSurfaceHandle)); 257 kFakeSurfaceHandle));
253 buffer_queue->Initialize(); 258 buffer_queue->Initialize();
254 return buffer_queue; 259 return buffer_queue;
255 } 260 }
256 261
257 TEST(BufferQueueStandaloneTest, FboInitialization) { 262 TEST(BufferQueueStandaloneTest, FboInitialization) {
258 MockedContext* context; 263 MockedContext* context;
264 scoped_refptr<cc::TestContextProvider> context_provider =
265 CreateMockedContextProvider(&context);
259 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( 266 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
260 new StubGpuMemoryBufferManager); 267 new StubGpuMemoryBufferManager);
261 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( 268 std::unique_ptr<BufferQueue> output_surface =
262 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get()); 269 CreateBufferQueue(GL_TEXTURE_2D, context_provider->ContextGL(),
270 gpu_memory_buffer_manager.get());
263 271
264 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 272 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
265 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) 273 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _))
266 .WillByDefault(Return()); 274 .WillByDefault(Return());
267 275
268 output_surface->Reshape(gfx::Size(10, 20), 1.0f); 276 output_surface->Reshape(gfx::Size(10, 20), 1.0f);
269 } 277 }
270 278
271 TEST(BufferQueueStandaloneTest, FboBinding) { 279 TEST(BufferQueueStandaloneTest, FboBinding) {
272 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB}; 280 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB};
273 for (size_t i = 0; i < 2; ++i) { 281 for (size_t i = 0; i < 2; ++i) {
274 GLenum target = targets[i]; 282 GLenum target = targets[i];
283
275 MockedContext* context; 284 MockedContext* context;
285 scoped_refptr<cc::TestContextProvider> context_provider =
286 CreateMockedContextProvider(&context);
276 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( 287 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
277 new StubGpuMemoryBufferManager); 288 new StubGpuMemoryBufferManager);
278 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( 289 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue(
279 target, &context, gpu_memory_buffer_manager.get()); 290 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get());
291
280 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 292 EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
281 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); 293 EXPECT_CALL(*context, destroyImageCHROMIUM(1));
282 Expectation image = 294 Expectation image =
283 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) 295 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA))
284 .WillOnce(Return(1)); 296 .WillOnce(Return(1));
285 Expectation fb = 297 Expectation fb =
286 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 298 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
287 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 299 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
288 Expectation bind_tex = 300 Expectation bind_tex =
289 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) 301 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1))
290 .After(tex, image); 302 .After(tex, image);
291 EXPECT_CALL(*context, 303 EXPECT_CALL(*context,
292 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 304 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
293 target, Ne(0U), _)) 305 target, Ne(0U), _))
294 .After(fb, bind_tex); 306 .After(fb, bind_tex);
295 307
296 output_surface->BindFramebuffer(); 308 output_surface->BindFramebuffer();
297 } 309 }
298 } 310 }
299 311
300 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { 312 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) {
313 scoped_refptr<cc::TestContextProvider> context_provider =
314 cc::TestContextProvider::Create();
315 context_provider->BindToCurrentThread();
301 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; 316 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager;
302 std::unique_ptr<BufferQueue> output_surface; 317 std::unique_ptr<BufferQueue> output_surface;
303 scoped_refptr<cc::TestContextProvider> context_provider =
304 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create());
305 context_provider->BindToCurrentThread();
306 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); 318 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager);
307 319
308 std::unique_ptr<GLHelper> gl_helper; 320 std::unique_ptr<GLHelper> gl_helper;
309 gl_helper.reset(new GLHelper(context_provider->ContextGL(), 321 gl_helper.reset(new GLHelper(context_provider->ContextGL(),
310 context_provider->ContextSupport())); 322 context_provider->ContextSupport()));
311 323
312 output_surface.reset( 324 output_surface.reset(new BufferQueue(
313 new BufferQueue(context_provider, GL_TEXTURE_2D, GL_RGBA, gl_helper.get(), 325 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGBA, gl_helper.get(),
314 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); 326 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle));
315 output_surface->Initialize(); 327 output_surface->Initialize();
316 output_surface->Reshape(screen_size, 1.0f); 328 output_surface->Reshape(screen_size, 1.0f);
317 // Trigger a sub-buffer copy to exercise all paths. 329 // Trigger a sub-buffer copy to exercise all paths.
318 output_surface->BindFramebuffer(); 330 output_surface->BindFramebuffer();
319 output_surface->SwapBuffers(screen_rect); 331 output_surface->SwapBuffers(screen_rect);
320 output_surface->PageFlipComplete(); 332 output_surface->PageFlipComplete();
321 output_surface->BindFramebuffer(); 333 output_surface->BindFramebuffer();
322 output_surface->SwapBuffers(small_damage); 334 output_surface->SwapBuffers(small_damage);
323 335
324 int current_fbo = 0; 336 int current_fbo = 0;
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 645 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
634 EXPECT_CALL(*mock_output_surface_, 646 EXPECT_CALL(*mock_output_surface_,
635 CopyBufferDamage(target_texture, source_texture, small_damage, _)) 647 CopyBufferDamage(target_texture, source_texture, small_damage, _))
636 .Times(1); 648 .Times(1);
637 output_surface_->SwapBuffers(small_damage); 649 output_surface_->SwapBuffers(small_damage);
638 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 650 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
639 } 651 }
640 652
641 } // namespace 653 } // namespace
642 } // namespace display_compositor 654 } // namespace display_compositor
OLDNEW
« no previous file with comments | « components/display_compositor/buffer_queue.cc ('k') | components/mus/public/cpp/lib/output_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698