OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tests/gl_manager.h" | 5 #include "gpu/command_buffer/tests/gl_manager.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "ui/gfx/gpu_memory_buffer.h" | 29 #include "ui/gfx/gpu_memory_buffer.h" |
30 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
31 #include "ui/gl/gl_image_ref_counted_memory.h" | 31 #include "ui/gl/gl_image_ref_counted_memory.h" |
32 #include "ui/gl/gl_share_group.h" | 32 #include "ui/gl/gl_share_group.h" |
33 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
34 | 34 |
35 namespace gpu { | 35 namespace gpu { |
36 namespace { | 36 namespace { |
37 | 37 |
38 int BytesPerPixel(unsigned internalformat) { | 38 size_t BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { |
39 switch (internalformat) { | 39 switch (format) { |
40 case GL_RGBA8_OES: | 40 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 41 case gfx::GpuMemoryBuffer::BGRA_8888: |
41 return 4; | 42 return 4; |
42 default: | 43 case gfx::GpuMemoryBuffer::RGBX_8888: |
43 NOTREACHED(); | 44 break; |
44 return 0; | |
45 } | 45 } |
| 46 |
| 47 NOTREACHED(); |
| 48 return 0; |
46 } | 49 } |
47 | 50 |
48 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 51 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
49 public: | 52 public: |
50 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, | 53 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, |
51 const gfx::Size& size, | 54 const gfx::Size& size, |
52 unsigned internalformat) | 55 gfx::GpuMemoryBuffer::Format format) |
53 : bytes_(bytes), | 56 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} |
54 size_(size), | 57 |
55 internalformat_(internalformat), | 58 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { |
56 mapped_(false) {} | 59 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
| 60 } |
57 | 61 |
58 // Overridden from gfx::GpuMemoryBuffer: | 62 // Overridden from gfx::GpuMemoryBuffer: |
59 virtual void* Map() override { | 63 virtual void* Map() override { |
60 mapped_ = true; | 64 mapped_ = true; |
61 return &bytes_->data().front(); | 65 return &bytes_->data().front(); |
62 } | 66 } |
63 virtual void Unmap() override { mapped_ = false; } | 67 virtual void Unmap() override { mapped_ = false; } |
64 virtual bool IsMapped() const override { return mapped_; } | 68 virtual bool IsMapped() const override { return mapped_; } |
| 69 virtual Format GetFormat() const override { return format_; } |
65 virtual uint32 GetStride() const override { | 70 virtual uint32 GetStride() const override { |
66 return size_.width() * BytesPerPixel(internalformat_); | 71 return size_.width() * BytesPerPixel(format_); |
67 } | 72 } |
68 virtual gfx::GpuMemoryBufferHandle GetHandle() const override { | 73 virtual gfx::GpuMemoryBufferHandle GetHandle() const override { |
69 NOTREACHED(); | 74 NOTREACHED(); |
70 return gfx::GpuMemoryBufferHandle(); | 75 return gfx::GpuMemoryBufferHandle(); |
71 } | 76 } |
| 77 virtual ClientBuffer AsClientBuffer() override { |
| 78 return reinterpret_cast<ClientBuffer>(this); |
| 79 } |
| 80 |
| 81 base::RefCountedBytes* bytes() { return bytes_.get(); } |
72 | 82 |
73 private: | 83 private: |
74 scoped_refptr<base::RefCountedBytes> bytes_; | 84 scoped_refptr<base::RefCountedBytes> bytes_; |
75 const gfx::Size size_; | 85 const gfx::Size size_; |
76 unsigned internalformat_; | 86 gfx::GpuMemoryBuffer::Format format_; |
77 bool mapped_; | 87 bool mapped_; |
78 }; | 88 }; |
79 | 89 |
80 } // namespace | 90 } // namespace |
81 | 91 |
82 int GLManager::use_count_; | 92 int GLManager::use_count_; |
83 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; | 93 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; |
84 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; | 94 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; |
85 scoped_refptr<gfx::GLContext>* GLManager::base_context_; | 95 scoped_refptr<gfx::GLContext>* GLManager::base_context_; |
86 | 96 |
(...skipping 22 matching lines...) Expand all Loading... |
109 delete base_surface_; | 119 delete base_surface_; |
110 base_surface_ = NULL; | 120 base_surface_ = NULL; |
111 } | 121 } |
112 if (base_context_) { | 122 if (base_context_) { |
113 delete base_context_; | 123 delete base_context_; |
114 base_context_ = NULL; | 124 base_context_ = NULL; |
115 } | 125 } |
116 } | 126 } |
117 } | 127 } |
118 | 128 |
| 129 // static |
| 130 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( |
| 131 const gfx::Size& size, |
| 132 gfx::GpuMemoryBuffer::Format format) { |
| 133 std::vector<unsigned char> data(size.GetArea() * BytesPerPixel(format), 0); |
| 134 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
| 135 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
| 136 new GpuMemoryBufferImpl(bytes.get(), size, format)); |
| 137 } |
| 138 |
119 void GLManager::Initialize(const GLManager::Options& options) { | 139 void GLManager::Initialize(const GLManager::Options& options) { |
120 const int32 kCommandBufferSize = 1024 * 1024; | 140 const int32 kCommandBufferSize = 1024 * 1024; |
121 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 141 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
122 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 142 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
123 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; | 143 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
124 | 144 |
125 context_lost_allowed_ = options.context_lost_allowed; | 145 context_lost_allowed_ = options.context_lost_allowed; |
126 | 146 |
127 gles2::MailboxManager* mailbox_manager = NULL; | 147 gles2::MailboxManager* mailbox_manager = NULL; |
128 if (options.share_mailbox_manager) { | 148 if (options.share_mailbox_manager) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 328 } |
309 | 329 |
310 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { | 330 bool GLManager::GetBufferChanged(int32 transfer_buffer_id) { |
311 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); | 331 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); |
312 } | 332 } |
313 | 333 |
314 Capabilities GLManager::GetCapabilities() { | 334 Capabilities GLManager::GetCapabilities() { |
315 return decoder_->GetCapabilities(); | 335 return decoder_->GetCapabilities(); |
316 } | 336 } |
317 | 337 |
318 gfx::GpuMemoryBuffer* GLManager::CreateGpuMemoryBuffer( | 338 int32 GLManager::CreateImage(ClientBuffer buffer, |
319 size_t width, | 339 size_t width, |
320 size_t height, | 340 size_t height, |
321 unsigned internalformat, | 341 unsigned internalformat) { |
322 unsigned usage, | 342 GpuMemoryBufferImpl* gpu_memory_buffer = |
323 int32* id) { | 343 GpuMemoryBufferImpl::FromClientBuffer(buffer); |
324 gfx::Size size(width, height); | |
325 | 344 |
326 *id = -1; | 345 scoped_refptr<gfx::GLImageRefCountedMemory> image( |
327 | 346 new gfx::GLImageRefCountedMemory(gfx::Size(width, height), |
328 std::vector<unsigned char> data( | 347 internalformat)); |
329 size.GetArea() * BytesPerPixel(internalformat), 0); | 348 if (!image->Initialize(gpu_memory_buffer->bytes(), |
330 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 349 gpu_memory_buffer->GetFormat())) { |
331 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 350 return -1; |
332 new GpuMemoryBufferImpl(bytes.get(), size, internalformat)); | 351 } |
333 | 352 |
334 static int32 next_id = 1; | 353 static int32 next_id = 1; |
335 int32 new_id = next_id++; | 354 int32 new_id = next_id++; |
336 | 355 |
337 scoped_refptr<gfx::GLImageRefCountedMemory> image( | |
338 new gfx::GLImageRefCountedMemory(size, internalformat)); | |
339 if (!image->Initialize(bytes.get())) | |
340 return NULL; | |
341 | |
342 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 356 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
343 DCHECK(image_manager); | 357 DCHECK(image_manager); |
344 image_manager->AddImage(image.get(), new_id); | 358 image_manager->AddImage(image.get(), new_id); |
345 | 359 return new_id; |
346 *id = new_id; | |
347 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | |
348 return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second; | |
349 } | 360 } |
350 | 361 |
351 void GLManager::DestroyGpuMemoryBuffer(int32 id) { | 362 int32 GLManager::CreateGpuMemoryBufferImage(size_t width, |
| 363 size_t height, |
| 364 unsigned internalformat, |
| 365 unsigned usage) { |
| 366 DCHECK_EQ(usage, static_cast<unsigned>(GL_MAP_CHROMIUM)); |
| 367 scoped_ptr<gfx::GpuMemoryBuffer> buffer = GLManager::CreateGpuMemoryBuffer( |
| 368 gfx::Size(width, height), gfx::GpuMemoryBuffer::RGBA_8888); |
| 369 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
| 370 } |
| 371 |
| 372 void GLManager::DestroyImage(int32 id) { |
352 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 373 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
353 DCHECK(image_manager); | 374 DCHECK(image_manager); |
354 image_manager->RemoveImage(id); | 375 image_manager->RemoveImage(id); |
355 | |
356 gpu_memory_buffers_.erase(id); | |
357 } | 376 } |
358 | 377 |
359 uint32 GLManager::InsertSyncPoint() { | 378 uint32 GLManager::InsertSyncPoint() { |
360 NOTIMPLEMENTED(); | 379 NOTIMPLEMENTED(); |
361 return 0u; | 380 return 0u; |
362 } | 381 } |
363 | 382 |
364 uint32 GLManager::InsertFutureSyncPoint() { | 383 uint32 GLManager::InsertFutureSyncPoint() { |
365 NOTIMPLEMENTED(); | 384 NOTIMPLEMENTED(); |
366 return 0u; | 385 return 0u; |
(...skipping 15 matching lines...) Expand all Loading... |
382 void GLManager::SetSurfaceVisible(bool visible) { | 401 void GLManager::SetSurfaceVisible(bool visible) { |
383 NOTIMPLEMENTED(); | 402 NOTIMPLEMENTED(); |
384 } | 403 } |
385 | 404 |
386 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { | 405 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { |
387 NOTIMPLEMENTED(); | 406 NOTIMPLEMENTED(); |
388 return 0; | 407 return 0; |
389 } | 408 } |
390 | 409 |
391 } // namespace gpu | 410 } // namespace gpu |
OLD | NEW |