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

Side by Side Diff: content/browser/compositor/buffer_queue_unittest.cc

Issue 1881033003: Decouple buffer_queue_unittest from content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/compositor/buffer_queue.h" 5 #include "content/browser/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>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "cc/test/test_context_provider.h" 14 #include "cc/test/test_context_provider.h"
15 #include "cc/test/test_gpu_memory_buffer_manager.h"
15 #include "cc/test/test_web_graphics_context_3d.h" 16 #include "cc/test/test_web_graphics_context_3d.h"
16 #include "content/browser/compositor/gl_helper.h" 17 #include "content/browser/compositor/gl_helper.h"
17 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s urface.h"
18 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
19 #include "gpu/GLES2/gl2extchromium.h" 18 #include "gpu/GLES2/gl2extchromium.h"
20 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/khronos/GLES2/gl2ext.h" 21 #include "third_party/khronos/GLES2/gl2ext.h"
23 22
24 using ::testing::_; 23 using ::testing::_;
25 using ::testing::Expectation; 24 using ::testing::Expectation;
26 using ::testing::Ne; 25 using ::testing::Ne;
27 using ::testing::Return; 26 using ::testing::Return;
28 27
(...skipping 16 matching lines...) Expand all
45 return gfx::GpuMemoryBufferId(0); 44 return gfx::GpuMemoryBufferId(0);
46 } 45 }
47 gfx::GpuMemoryBufferHandle GetHandle() const override { 46 gfx::GpuMemoryBufferHandle GetHandle() const override {
48 return gfx::GpuMemoryBufferHandle(); 47 return gfx::GpuMemoryBufferHandle();
49 } 48 }
50 ClientBuffer AsClientBuffer() override { 49 ClientBuffer AsClientBuffer() override {
51 return reinterpret_cast<ClientBuffer>(this); 50 return reinterpret_cast<ClientBuffer>(this);
52 } 51 }
53 }; 52 };
54 53
55 class StubBrowserGpuMemoryBufferManager : public BrowserGpuMemoryBufferManager { 54 class StubGpuMemoryBufferManager : public cc::TestGpuMemoryBufferManager {
56 public: 55 public:
57 StubBrowserGpuMemoryBufferManager() 56 StubGpuMemoryBufferManager() : allocate_succeeds_(true) {}
58 : BrowserGpuMemoryBufferManager(1, 1), allocate_succeeds_(true) {}
59 57
60 void set_allocate_succeeds(bool value) { allocate_succeeds_ = value; } 58 void set_allocate_succeeds(bool value) { allocate_succeeds_ = value; }
61 59
62 std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer( 60 std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
63 const gfx::Size& size, 61 const gfx::Size& size,
64 gfx::BufferFormat format, 62 gfx::BufferFormat format,
65 gfx::BufferUsage usage, 63 gfx::BufferUsage usage,
66 int32_t surface_id) override { 64 int32_t surface_id) override {
67 if (!surface_id) { 65 if (!surface_id) {
68 return BrowserGpuMemoryBufferManager::AllocateGpuMemoryBuffer( 66 return TestGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
69 size, format, usage, surface_id); 67 size, format, usage, surface_id);
70 } 68 }
71 if (allocate_succeeds_) 69 if (allocate_succeeds_)
72 return base::WrapUnique<gfx::GpuMemoryBuffer>( 70 return base::WrapUnique<gfx::GpuMemoryBuffer>(
73 new StubGpuMemoryBufferImpl); 71 new StubGpuMemoryBufferImpl);
74 return nullptr; 72 return nullptr;
75 } 73 }
76 74
77 private: 75 private:
78 bool allocate_succeeds_; 76 bool allocate_succeeds_;
79 }; 77 };
80 78
81 class MockBufferQueue : public BufferQueue { 79 class MockBufferQueue : public BufferQueue {
82 public: 80 public:
83 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider, 81 MockBufferQueue(scoped_refptr<cc::ContextProvider> context_provider,
84 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager, 82 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
85 unsigned int target, 83 unsigned int target,
86 unsigned int internalformat) 84 unsigned int internalformat)
87 : BufferQueue(context_provider, 85 : BufferQueue(context_provider,
88 target, 86 target,
89 internalformat, 87 internalformat,
90 nullptr, 88 nullptr,
91 gpu_memory_buffer_manager, 89 gpu_memory_buffer_manager,
92 1) {} 90 1) {}
93 MOCK_METHOD4(CopyBufferDamage, 91 MOCK_METHOD4(CopyBufferDamage,
94 void(int, int, const gfx::Rect&, const gfx::Rect&)); 92 void(int, int, const gfx::Rect&, const gfx::Rect&));
95 }; 93 };
96 94
97 class BufferQueueTest : public ::testing::Test { 95 class BufferQueueTest : public ::testing::Test {
98 public: 96 public:
99 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {} 97 BufferQueueTest() : doublebuffering_(true), first_frame_(true) {}
100 98
101 void SetUp() override { 99 void SetUp() override {
102 InitWithContext(cc::TestWebGraphicsContext3D::Create()); 100 InitWithContext(cc::TestWebGraphicsContext3D::Create());
103 } 101 }
104 102
105 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) { 103 void InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D> context) {
106 scoped_refptr<cc::TestContextProvider> context_provider = 104 scoped_refptr<cc::TestContextProvider> context_provider =
107 cc::TestContextProvider::Create(std::move(context)); 105 cc::TestContextProvider::Create(std::move(context));
108 context_provider->BindToCurrentThread(); 106 context_provider->BindToCurrentThread();
109 gpu_memory_buffer_manager_.reset(new StubBrowserGpuMemoryBufferManager); 107 gpu_memory_buffer_manager_.reset(new StubGpuMemoryBufferManager);
110 mock_output_surface_ = 108 mock_output_surface_ =
111 new MockBufferQueue(context_provider, gpu_memory_buffer_manager_.get(), 109 new MockBufferQueue(context_provider, gpu_memory_buffer_manager_.get(),
112 GL_TEXTURE_2D, GL_RGBA); 110 GL_TEXTURE_2D, GL_RGBA);
113 output_surface_.reset(mock_output_surface_); 111 output_surface_.reset(mock_output_surface_);
114 output_surface_->Initialize(); 112 output_surface_->Initialize();
115 } 113 }
116 114
117 unsigned current_surface() { 115 unsigned current_surface() {
118 return output_surface_->current_surface_ 116 return output_surface_->current_surface_
119 ? output_surface_->current_surface_->image 117 ? output_surface_->current_surface_->image
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 protected: 178 protected:
181 bool InsertUnique(std::set<unsigned>* set, unsigned value) { 179 bool InsertUnique(std::set<unsigned>* set, unsigned value) {
182 if (!value) 180 if (!value)
183 return true; 181 return true;
184 if (set->find(value) != set->end()) 182 if (set->find(value) != set->end())
185 return false; 183 return false;
186 set->insert(value); 184 set->insert(value);
187 return true; 185 return true;
188 } 186 }
189 187
190 std::unique_ptr<StubBrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_; 188 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager_;
191 std::unique_ptr<BufferQueue> output_surface_; 189 std::unique_ptr<BufferQueue> output_surface_;
192 MockBufferQueue* mock_output_surface_; 190 MockBufferQueue* mock_output_surface_;
193 bool doublebuffering_; 191 bool doublebuffering_;
194 bool first_frame_; 192 bool first_frame_;
195 }; 193 };
196 194
197 namespace { 195 namespace {
198 const gfx::Size screen_size = gfx::Size(30, 30); 196 const gfx::Size screen_size = gfx::Size(30, 30);
199 const gfx::Rect screen_rect = gfx::Rect(screen_size); 197 const gfx::Rect screen_rect = gfx::Rect(screen_size);
200 const gfx::Rect small_damage = gfx::Rect(gfx::Size(10, 10)); 198 const gfx::Rect small_damage = gfx::Rect(gfx::Size(10, 10));
(...skipping 28 matching lines...) Expand all
229 InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D>(context_)); 227 InitWithContext(std::unique_ptr<cc::TestWebGraphicsContext3D>(context_));
230 } 228 }
231 229
232 protected: 230 protected:
233 MockedContext* context_; 231 MockedContext* context_;
234 }; 232 };
235 233
236 std::unique_ptr<BufferQueue> CreateOutputSurfaceWithMock( 234 std::unique_ptr<BufferQueue> CreateOutputSurfaceWithMock(
237 unsigned int target, 235 unsigned int target,
238 MockedContext** context, 236 MockedContext** context,
239 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager) { 237 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
240 *context = new MockedContext(); 238 *context = new MockedContext();
241 scoped_refptr<cc::TestContextProvider> context_provider = 239 scoped_refptr<cc::TestContextProvider> context_provider =
242 cc::TestContextProvider::Create( 240 cc::TestContextProvider::Create(
243 std::unique_ptr<cc::TestWebGraphicsContext3D>(*context)); 241 std::unique_ptr<cc::TestWebGraphicsContext3D>(*context));
244 context_provider->BindToCurrentThread(); 242 context_provider->BindToCurrentThread();
245 std::unique_ptr<BufferQueue> buffer_queue( 243 std::unique_ptr<BufferQueue> buffer_queue(
246 new BufferQueue(context_provider, target, GL_RGBA, nullptr, 244 new BufferQueue(context_provider, target, GL_RGBA, nullptr,
247 gpu_memory_buffer_manager, 1)); 245 gpu_memory_buffer_manager, 1));
248 buffer_queue->Initialize(); 246 buffer_queue->Initialize();
249 return buffer_queue; 247 return buffer_queue;
250 } 248 }
251 249
252 TEST(BufferQueueStandaloneTest, FboInitialization) { 250 TEST(BufferQueueStandaloneTest, FboInitialization) {
253 MockedContext* context; 251 MockedContext* context;
254 std::unique_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager( 252 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
255 new StubBrowserGpuMemoryBufferManager); 253 new StubGpuMemoryBufferManager);
256 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( 254 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
257 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get()); 255 GL_TEXTURE_2D, &context, gpu_memory_buffer_manager.get());
258 256
259 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 257 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
260 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _)) 258 ON_CALL(*context, framebufferTexture2D(_, _, _, _, _))
261 .WillByDefault(Return()); 259 .WillByDefault(Return());
262 260
263 output_surface->Reshape(gfx::Size(10, 20), 1.0f); 261 output_surface->Reshape(gfx::Size(10, 20), 1.0f);
264 } 262 }
265 263
266 TEST(BufferQueueStandaloneTest, FboBinding) { 264 TEST(BufferQueueStandaloneTest, FboBinding) {
267 GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB }; 265 GLenum targets[] = { GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB };
268 for (size_t i = 0; i < 2; ++i) { 266 for (size_t i = 0; i < 2; ++i) {
269 GLenum target = targets[i]; 267 GLenum target = targets[i];
270 MockedContext* context; 268 MockedContext* context;
271 std::unique_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager( 269 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager(
272 new StubBrowserGpuMemoryBufferManager); 270 new StubGpuMemoryBufferManager);
273 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock( 271 std::unique_ptr<BufferQueue> output_surface = CreateOutputSurfaceWithMock(
274 target, &context, gpu_memory_buffer_manager.get()); 272 target, &context, gpu_memory_buffer_manager.get());
275 EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 273 EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
276 EXPECT_CALL(*context, destroyImageCHROMIUM(1)); 274 EXPECT_CALL(*context, destroyImageCHROMIUM(1));
277 Expectation image = 275 Expectation image =
278 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA)) 276 EXPECT_CALL(*context, createImageCHROMIUM(_, 0, 0, GL_RGBA))
279 .WillOnce(Return(1)); 277 .WillOnce(Return(1));
280 Expectation fb = 278 Expectation fb =
281 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U))); 279 EXPECT_CALL(*context, bindFramebuffer(GL_FRAMEBUFFER, Ne(0U)));
282 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U))); 280 Expectation tex = EXPECT_CALL(*context, bindTexture(target, Ne(0U)));
283 Expectation bind_tex = 281 Expectation bind_tex =
284 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1)) 282 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(target, 1))
285 .After(tex, image); 283 .After(tex, image);
286 EXPECT_CALL( 284 EXPECT_CALL(
287 *context, 285 *context,
288 framebufferTexture2D( 286 framebufferTexture2D(
289 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, Ne(0U), _)) 287 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, Ne(0U), _))
290 .After(fb, bind_tex); 288 .After(fb, bind_tex);
291 289
292 output_surface->BindFramebuffer(); 290 output_surface->BindFramebuffer();
293 } 291 }
294 } 292 }
295 293
296 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) { 294 TEST(BufferQueueStandaloneTest, CheckBoundFramebuffer) {
297 std::unique_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager; 295 std::unique_ptr<StubGpuMemoryBufferManager> gpu_memory_buffer_manager;
298 std::unique_ptr<BufferQueue> output_surface; 296 std::unique_ptr<BufferQueue> output_surface;
299 scoped_refptr<cc::TestContextProvider> context_provider = 297 scoped_refptr<cc::TestContextProvider> context_provider =
300 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create()); 298 cc::TestContextProvider::Create(cc::TestWebGraphicsContext3D::Create());
301 context_provider->BindToCurrentThread(); 299 context_provider->BindToCurrentThread();
302 gpu_memory_buffer_manager.reset(new StubBrowserGpuMemoryBufferManager); 300 gpu_memory_buffer_manager.reset(new StubGpuMemoryBufferManager);
303 301
304 std::unique_ptr<GLHelper> gl_helper; 302 std::unique_ptr<GLHelper> gl_helper;
305 gl_helper.reset(new GLHelper(context_provider->ContextGL(), 303 gl_helper.reset(new GLHelper(context_provider->ContextGL(),
306 context_provider->ContextSupport())); 304 context_provider->ContextSupport()));
307 305
308 output_surface.reset(new BufferQueue(context_provider, GL_TEXTURE_2D, GL_RGBA, 306 output_surface.reset(new BufferQueue(context_provider, GL_TEXTURE_2D, GL_RGBA,
309 gl_helper.get(), 307 gl_helper.get(),
310 gpu_memory_buffer_manager.get(), 1)); 308 gpu_memory_buffer_manager.get(), 1));
311 output_surface->Initialize(); 309 output_surface->Initialize();
312 output_surface->Reshape(screen_size, 1.0f); 310 output_surface->Reshape(screen_size, 1.0f);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 621 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
624 EXPECT_CALL(*mock_output_surface_, 622 EXPECT_CALL(*mock_output_surface_,
625 CopyBufferDamage(target_texture, source_texture, small_damage, _)) 623 CopyBufferDamage(target_texture, source_texture, small_damage, _))
626 .Times(1); 624 .Times(1);
627 output_surface_->SwapBuffers(small_damage); 625 output_surface_->SwapBuffers(small_damage);
628 testing::Mock::VerifyAndClearExpectations(mock_output_surface_); 626 testing::Mock::VerifyAndClearExpectations(mock_output_surface_);
629 } 627 }
630 628
631 } // namespace 629 } // namespace
632 } // namespace content 630 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698