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