| 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> |
| 8 #include <GLES2/gl2ext.h> |
| 9 |
| 7 #include <vector> | 10 #include <vector> |
| 8 | 11 |
| 9 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/memory/ref_counted_memory.h" |
| 11 #include "gpu/command_buffer/client/gles2_implementation.h" | 15 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 12 #include "gpu/command_buffer/client/gles2_lib.h" | 16 #include "gpu/command_buffer/client/gles2_lib.h" |
| 13 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" | |
| 14 #include "gpu/command_buffer/client/transfer_buffer.h" | 17 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 15 #include "gpu/command_buffer/common/constants.h" | 18 #include "gpu/command_buffer/common/constants.h" |
| 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 19 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 17 #include "gpu/command_buffer/service/command_buffer_service.h" | 20 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 18 #include "gpu/command_buffer/service/context_group.h" | 21 #include "gpu/command_buffer/service/context_group.h" |
| 19 #include "gpu/command_buffer/service/gl_context_virtual.h" | 22 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 21 #include "gpu/command_buffer/service/gpu_control_service.h" | 24 #include "gpu/command_buffer/service/gpu_control_service.h" |
| 22 #include "gpu/command_buffer/service/gpu_scheduler.h" | 25 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 23 #include "gpu/command_buffer/service/image_manager.h" | 26 #include "gpu/command_buffer/service/image_manager.h" |
| 24 #include "gpu/command_buffer/service/mailbox_manager.h" | 27 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/gfx/gpu_memory_buffer.h" |
| 26 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
| 31 #include "ui/gl/gl_image_ref_counted_memory.h" |
| 27 #include "ui/gl/gl_share_group.h" | 32 #include "ui/gl/gl_share_group.h" |
| 28 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
| 29 | 34 |
| 30 namespace gpu { | 35 namespace gpu { |
| 36 namespace { |
| 37 |
| 38 int BytesPerPixel(unsigned internalformat) { |
| 39 switch (internalformat) { |
| 40 case GL_RGBA8_OES: |
| 41 return 4; |
| 42 default: |
| 43 NOTREACHED(); |
| 44 return 0; |
| 45 } |
| 46 } |
| 47 |
| 48 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 49 public: |
| 50 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, |
| 51 const gfx::Size& size, |
| 52 unsigned internalformat) |
| 53 : bytes_(bytes), |
| 54 size_(size), |
| 55 internalformat_(internalformat), |
| 56 mapped_(false) {} |
| 57 |
| 58 // Overridden from gfx::GpuMemoryBuffer: |
| 59 virtual void* Map() OVERRIDE { |
| 60 mapped_ = true; |
| 61 return &bytes_->data().front(); |
| 62 } |
| 63 virtual void Unmap() OVERRIDE { mapped_ = false; } |
| 64 virtual bool IsMapped() const OVERRIDE { return mapped_; } |
| 65 virtual uint32 GetStride() const OVERRIDE { |
| 66 return size_.width() * BytesPerPixel(internalformat_); |
| 67 } |
| 68 virtual gfx::GpuMemoryBufferHandle GetHandle() const OVERRIDE { |
| 69 NOTREACHED(); |
| 70 return gfx::GpuMemoryBufferHandle(); |
| 71 } |
| 72 |
| 73 private: |
| 74 scoped_refptr<base::RefCountedBytes> bytes_; |
| 75 const gfx::Size size_; |
| 76 unsigned internalformat_; |
| 77 bool mapped_; |
| 78 }; |
| 79 |
| 80 } // namespace |
| 31 | 81 |
| 32 int GLManager::use_count_; | 82 int GLManager::use_count_; |
| 33 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; | 83 scoped_refptr<gfx::GLShareGroup>* GLManager::base_share_group_; |
| 34 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; | 84 scoped_refptr<gfx::GLSurface>* GLManager::base_surface_; |
| 35 scoped_refptr<gfx::GLContext>* GLManager::base_context_; | 85 scoped_refptr<gfx::GLContext>* GLManager::base_context_; |
| 36 | 86 |
| 37 GLManager::Options::Options() | 87 GLManager::Options::Options() |
| 38 : size(4, 4), | 88 : size(4, 4), |
| 39 share_group_manager(NULL), | 89 share_group_manager(NULL), |
| 40 share_mailbox_manager(NULL), | 90 share_mailbox_manager(NULL), |
| 41 virtual_manager(NULL), | 91 virtual_manager(NULL), |
| 42 bind_generates_resource(false), | 92 bind_generates_resource(false), |
| 43 lose_context_when_out_of_memory(false), | 93 lose_context_when_out_of_memory(false), |
| 44 context_lost_allowed(false), | 94 context_lost_allowed(false) { |
| 45 image_manager(NULL) {} | 95 } |
| 46 | 96 |
| 47 GLManager::GLManager() | 97 GLManager::GLManager() : context_lost_allowed_(false) { |
| 48 : context_lost_allowed_(false), gpu_memory_buffer_factory_(NULL) { | |
| 49 SetupBaseContext(); | 98 SetupBaseContext(); |
| 50 } | 99 } |
| 51 | 100 |
| 52 GLManager::~GLManager() { | 101 GLManager::~GLManager() { |
| 53 --use_count_; | 102 --use_count_; |
| 54 if (!use_count_) { | 103 if (!use_count_) { |
| 55 if (base_share_group_) { | 104 if (base_share_group_) { |
| 56 delete base_context_; | 105 delete base_context_; |
| 57 base_context_ = NULL; | 106 base_context_ = NULL; |
| 58 } | 107 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 attrib_helper.red_size_ = 8; | 162 attrib_helper.red_size_ = 8; |
| 114 attrib_helper.green_size_ = 8; | 163 attrib_helper.green_size_ = 8; |
| 115 attrib_helper.blue_size_ = 8; | 164 attrib_helper.blue_size_ = 8; |
| 116 attrib_helper.alpha_size_ = 8; | 165 attrib_helper.alpha_size_ = 8; |
| 117 attrib_helper.depth_size_ = 16; | 166 attrib_helper.depth_size_ = 16; |
| 118 attrib_helper.Serialize(&attribs); | 167 attrib_helper.Serialize(&attribs); |
| 119 | 168 |
| 120 if (!context_group) { | 169 if (!context_group) { |
| 121 context_group = | 170 context_group = |
| 122 new gles2::ContextGroup(mailbox_manager_.get(), | 171 new gles2::ContextGroup(mailbox_manager_.get(), |
| 123 options.image_manager, | |
| 124 NULL, | 172 NULL, |
| 125 new gpu::gles2::ShaderTranslatorCache, | 173 new gpu::gles2::ShaderTranslatorCache, |
| 126 NULL, | 174 NULL, |
| 127 options.bind_generates_resource); | 175 options.bind_generates_resource); |
| 128 } | 176 } |
| 129 | 177 |
| 130 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group)); | 178 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group)); |
| 131 | 179 |
| 132 command_buffer_.reset(new CommandBufferService( | 180 command_buffer_.reset(new CommandBufferService( |
| 133 decoder_->GetContextGroup()->transfer_buffer_manager())); | 181 decoder_->GetContextGroup()->transfer_buffer_manager())); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 214 |
| 167 ASSERT_TRUE(decoder_->Initialize( | 215 ASSERT_TRUE(decoder_->Initialize( |
| 168 surface_.get(), | 216 surface_.get(), |
| 169 context_.get(), | 217 context_.get(), |
| 170 true, | 218 true, |
| 171 options.size, | 219 options.size, |
| 172 ::gpu::gles2::DisallowedFeatures(), | 220 ::gpu::gles2::DisallowedFeatures(), |
| 173 attribs)) << "could not initialize decoder"; | 221 attribs)) << "could not initialize decoder"; |
| 174 | 222 |
| 175 gpu_control_service_.reset( | 223 gpu_control_service_.reset( |
| 176 new GpuControlService(decoder_->GetContextGroup()->image_manager(), | 224 new GpuControlService(decoder_->GetQueryManager())); |
| 177 decoder_->GetQueryManager())); | |
| 178 gpu_memory_buffer_factory_ = options.gpu_memory_buffer_factory; | |
| 179 | 225 |
| 180 command_buffer_->SetPutOffsetChangeCallback( | 226 command_buffer_->SetPutOffsetChangeCallback( |
| 181 base::Bind(&GLManager::PumpCommands, base::Unretained(this))); | 227 base::Bind(&GLManager::PumpCommands, base::Unretained(this))); |
| 182 command_buffer_->SetGetBufferChangeCallback( | 228 command_buffer_->SetGetBufferChangeCallback( |
| 183 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); | 229 base::Bind(&GLManager::GetBufferChanged, base::Unretained(this))); |
| 184 | 230 |
| 185 // Create the GLES2 helper, which writes the command buffer protocol. | 231 // Create the GLES2 helper, which writes the command buffer protocol. |
| 186 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 232 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
| 187 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); | 233 ASSERT_TRUE(gles2_helper_->Initialize(kCommandBufferSize)); |
| 188 | 234 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 Capabilities GLManager::GetCapabilities() { | 317 Capabilities GLManager::GetCapabilities() { |
| 272 return decoder_->GetCapabilities(); | 318 return decoder_->GetCapabilities(); |
| 273 } | 319 } |
| 274 | 320 |
| 275 gfx::GpuMemoryBuffer* GLManager::CreateGpuMemoryBuffer( | 321 gfx::GpuMemoryBuffer* GLManager::CreateGpuMemoryBuffer( |
| 276 size_t width, | 322 size_t width, |
| 277 size_t height, | 323 size_t height, |
| 278 unsigned internalformat, | 324 unsigned internalformat, |
| 279 unsigned usage, | 325 unsigned usage, |
| 280 int32* id) { | 326 int32* id) { |
| 281 *id = -1; | 327 gfx::Size size(width, height); |
| 282 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 328 |
| 283 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | 329 std::vector<unsigned char> data( |
| 284 width, height, internalformat, usage)); | 330 size.GetArea() * BytesPerPixel(internalformat), 0); |
| 285 if (!buffer.get()) | 331 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
| 332 |
| 333 scoped_ptr<GpuMemoryBufferImpl> gpu_memory_buffer( |
| 334 new GpuMemoryBufferImpl(bytes.get(), size, internalformat)); |
| 335 |
| 336 scoped_refptr<gfx::GLImageRefCountedMemory> gl_image( |
| 337 new gfx::GLImageRefCountedMemory(size, internalformat)); |
| 338 if (!gl_image->Initialize(bytes.get())) |
| 286 return NULL; | 339 return NULL; |
| 287 | 340 |
| 288 static int32 next_id = 1; | 341 static int32 next_id = 1; |
| 289 *id = next_id++; | 342 *id = next_id++; |
| 290 gpu_control_service_->RegisterGpuMemoryBuffer( | 343 |
| 291 *id, buffer->GetHandle(), width, height, internalformat); | 344 decoder()->GetImageManager()->AddImage(gl_image.get(), *id); |
| 292 gfx::GpuMemoryBuffer* raw_buffer = buffer.get(); | 345 gpu_memory_buffers_.add(*id, |
| 293 memory_buffers_.add(*id, buffer.Pass()); | 346 gpu_memory_buffer.PassAs<gfx::GpuMemoryBuffer>()); |
| 294 return raw_buffer; | 347 return gpu_memory_buffers_.get(*id); |
| 295 } | 348 } |
| 296 | 349 |
| 297 void GLManager::DestroyGpuMemoryBuffer(int32 id) { | 350 void GLManager::DestroyGpuMemoryBuffer(int32 id) { |
| 298 memory_buffers_.erase(id); | 351 decoder()->GetImageManager()->RemoveImage(id); |
| 299 gpu_control_service_->UnregisterGpuMemoryBuffer(id); | 352 gpu_memory_buffers_.erase(id); |
| 300 } | 353 } |
| 301 | 354 |
| 302 uint32 GLManager::InsertSyncPoint() { | 355 uint32 GLManager::InsertSyncPoint() { |
| 303 NOTIMPLEMENTED(); | 356 NOTIMPLEMENTED(); |
| 304 return 0u; | 357 return 0u; |
| 305 } | 358 } |
| 306 | 359 |
| 307 void GLManager::SignalSyncPoint(uint32 sync_point, | 360 void GLManager::SignalSyncPoint(uint32 sync_point, |
| 308 const base::Closure& callback) { | 361 const base::Closure& callback) { |
| 309 NOTIMPLEMENTED(); | 362 NOTIMPLEMENTED(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 320 void GLManager::Echo(const base::Closure& callback) { | 373 void GLManager::Echo(const base::Closure& callback) { |
| 321 NOTIMPLEMENTED(); | 374 NOTIMPLEMENTED(); |
| 322 } | 375 } |
| 323 | 376 |
| 324 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { | 377 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { |
| 325 NOTIMPLEMENTED(); | 378 NOTIMPLEMENTED(); |
| 326 return 0; | 379 return 0; |
| 327 } | 380 } |
| 328 | 381 |
| 329 } // namespace gpu | 382 } // namespace gpu |
| OLD | NEW |