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