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

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

Issue 2009443002: Revert of Consolidate OutputSurface constructors into GL vs Vulkan. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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(gpu::gles2::GLES2Interface* gl, 88 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
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(gl, 92 : BufferQueue(context_provider,
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 context_provider_ = cc::TestContextProvider::Create(std::move(context)); 111 scoped_refptr<cc::TestContextProvider> context_provider =
112 context_provider_->BindToCurrentThread(); 112 cc::TestContextProvider::Create(std::move(context));
113 context_provider->BindToCurrentThread();
113 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager); 114 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager);
114 mock_output_surface_ = new MockBufferQueue(context_provider_->ContextGL(), 115 mock_output_surface_ =
115 gpu_memory_buffer_manager_.get(), 116 new MockBufferQueue(context_provider, gpu_memory_buffer_manager_.get(),
116 GL_TEXTURE_2D, GL_RGBA); 117 GL_TEXTURE_2D, GL_RGBA);
117 output_surface_.reset(mock_output_surface_); 118 output_surface_.reset(mock_output_surface_);
118 output_surface_->Initialize(); 119 output_surface_->Initialize();
119 } 120 }
120 121
121 unsigned current_surface() { 122 unsigned current_surface() {
122 return output_surface_->current_surface_ 123 return output_surface_->current_surface_
123 ? output_surface_->current_surface_->image 124 ? output_surface_->current_surface_->image
124 : 0; 125 : 0;
125 } 126 }
126 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>& 127 const std::vector<std::unique_ptr<BufferQueue::AllocatedSurface>>&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 protected: 185 protected:
185 bool InsertUnique(std::set<unsigned>* set, unsigned value) { 186 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
186 if (!value) 187 if (!value)
187 return true; 188 return true;
188 if (set->find(value) != set->end()) 189 if (set->find(value) != set->end())
189 return false; 190 return false;
190 set->insert(value); 191 set->insert(value);
191 return true; 192 return true;
192 } 193 }
193 194
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 scoped_refptr<cc::TestContextProvider> CreateMockedContextProvider( 241 std::unique_ptr<BufferQueue> CreateOutputSurfaceWithMock(
242 MockedContext** context) { 242 unsigned int target,
243 std::unique_ptr<MockedContext> owned_context(new MockedContext); 243 MockedContext** context,
244 *context = owned_context.get(); 244 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
245 *context = new MockedContext();
245 scoped_refptr<cc::TestContextProvider> context_provider = 246 scoped_refptr<cc::TestContextProvider> context_provider =
246 cc::TestContextProvider::Create(std::move(owned_context)); 247 cc::TestContextProvider::Create(
248 std::unique_ptr<cc::TestWebGraphicsContext3D>(*context));
247 context_provider->BindToCurrentThread(); 249 context_provider->BindToCurrentThread();
248 return context_provider;
249 }
250
251 std::unique_ptr<BufferQueue> CreateBufferQueue(
252 unsigned int target,
253 gpu::gles2::GLES2Interface* gl,
254 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
255 std::unique_ptr<BufferQueue> buffer_queue( 250 std::unique_ptr<BufferQueue> buffer_queue(
256 new BufferQueue(gl, target, GL_RGBA, nullptr, gpu_memory_buffer_manager, 251 new BufferQueue(context_provider, target, GL_RGBA, nullptr,
257 kFakeSurfaceHandle)); 252 gpu_memory_buffer_manager, kFakeSurfaceHandle));
258 buffer_queue->Initialize(); 253 buffer_queue->Initialize();
259 return buffer_queue; 254 return buffer_queue;
260 } 255 }
261 256
262 TEST(BufferQueueStandaloneTest, FboInitialization) { 257 TEST(BufferQueueStandaloneTest, FboInitialization) {
263 MockedContext* context; 258 MockedContext* context;
264 scoped_refptr<cc::TestContextProvider> context_provider =
265 CreateMockedContextProvider(&context);
266 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( 259 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
267 new StubGpuMemoryBufferManager); 260 new StubGpuMemoryBufferManager);
268 std::unique_ptr<BufferQueue> output_surface = 261 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
269 CreateBufferQueue(GL_TEXTURE_2D, context_provider->ContextGL(), 262 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get());
270 gpu_memory_buffer_manager.get());
271 263
272 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 264 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
273 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) 265 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _))
274 .WillByDefault(Return()); 266 .WillByDefault(Return());
275 267
276 output_surface->Reshape(gfx::Size(10, 20), 1.0f); 268 output_surface->Reshape(gfx::Size(10, 20), 1.0f);
277 } 269 }
278 270
279 TEST(BufferQueueStandaloneTest, FboBinding) { 271 TEST(BufferQueueStandaloneTest, FboBinding) {
280 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB}; 272 GLenum targets[] = {GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB};
281 for (size_t i = 0; i < 2; ++i) { 273 for (size_t i = 0; i < 2; ++i) {
282 GLenum target = targets[i]; 274 GLenum target = targets[i];
283
284 MockedContext* context; 275 MockedContext* context;
285 scoped_refptr<cc::TestContextProvider> context_provider =
286 CreateMockedContextProvider(&context);
287 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager( 276 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
288 new StubGpuMemoryBufferManager); 277 new StubGpuMemoryBufferManager);
289 std::unique_ptr<BufferQueue> output_surface = CreateBufferQueue( 278 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
290 target, context_provider->ContextGL(), gpu_memory_buffer_manager.get()); 279 target, &context, gpu_memory_buffer_manager.get());
291
292 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 280 EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
293 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); 281 EXPECT_CALL(*context, destroyImageCHROMIUM(1));
294 Expectation image = 282 Expectation image =
295 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) 283 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA))
296 .WillOnce(Return(1)); 284 .WillOnce(Return(1));
297 Expectation fb = 285 Expectation fb =
298 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 286 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
299 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 287 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
300 Expectation bind_tex = 288 Expectation bind_tex =
301 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) 289 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1))
302 .After(tex, image); 290 .After(tex, image);
303 EXPECT_CALL(*context, 291 EXPECT_CALL(*context,
304 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 292 framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
305 target, Ne(0U), _)) 293 target, Ne(0U), _))
306 .After(fb, bind_tex); 294 .After(fb, bind_tex);
307 295
308 output_surface->BindFramebuffer(); 296 output_surface->BindFramebuffer();
309 } 297 }
310 } 298 }
311 299
312 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { 300 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) {
313 scoped_refptr<cc::TestContextProvider> context_provider =
314 cc::TestContextProvider::Create();
315 context_provider->BindToCurrentThread();
316 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager; 301 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager;
317 std::unique_ptr<BufferQueue> output_surface; 302 std::unique_ptr<BufferQueue> output_surface;
303 scoped_refptr<cc::TestContextProvider> context_provider =
304 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create());
305 context_provider->BindToCurrentThread();
318 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager); 306 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager);
319 307
320 std::unique_ptr<GLHelper> gl_helper; 308 std::unique_ptr<GLHelper> gl_helper;
321 gl_helper.reset(new GLHelper(context_provider->ContextGL(), 309 gl_helper.reset(new GLHelper(context_provider->ContextGL(),
322 context_provider->ContextSupport())); 310 context_provider->ContextSupport()));
323 311
324 output_surface.reset(new BufferQueue( 312 output_surface.reset(
325 context_provider->ContextGL(), GL_TEXTURE_2D, GL_RGBA, gl_helper.get(), 313 new BufferQueue(context_provider, GL_TEXTURE_2D, GL_RGBA, gl_helper.get(),
326 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle)); 314 gpu_memory_buffer_manager.get(), kFakeSurfaceHandle));
327 output_surface->Initialize(); 315 output_surface->Initialize();
328 output_surface->Reshape(screen_size, 1.0f); 316 output_surface->Reshape(screen_size, 1.0f);
329 // Trigger a sub-buffer copy to exercise all paths. 317 // Trigger a sub-buffer copy to exercise all paths.
330 output_surface->BindFramebuffer(); 318 output_surface->BindFramebuffer();
331 output_surface->SwapBuffers(screen_rect); 319 output_surface->SwapBuffers(screen_rect);
332 output_surface->PageFlipComplete(); 320 output_surface->PageFlipComplete();
333 output_surface->BindFramebuffer(); 321 output_surface->BindFramebuffer();
334 output_surface->SwapBuffers(small_damage); 322 output_surface->SwapBuffers(small_damage);
335 323
336 int current_fbo = 0; 324 int current_fbo = 0;
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 633 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
646 EXPECT_CALL(*mock_output_surface_, 634 EXPECT_CALL(*mock_output_surface_,
647 CopyBufferDamage(target_texture, source_texture, small_damage, _)) 635 CopyBufferDamage(target_texture, source_texture, small_damage, _))
648 .Times(1); 636 .Times(1);
649 output_surface_->SwapBuffers(small_damage); 637 output_surface_->SwapBuffers(small_damage);
650 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 638 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
651 } 639 }
652 640
653 } // namespace 641 } // namespace
654 } // namespace display_compositor 642 } // 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