| 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 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/gfx/gpu_memory_buffer.h" | 32 #include "ui/gfx/gpu_memory_buffer.h" |
| 33 #include "ui/gl/gl_context.h" | 33 #include "ui/gl/gl_context.h" |
| 34 #include "ui/gl/gl_image_ref_counted_memory.h" | 34 #include "ui/gl/gl_image_ref_counted_memory.h" |
| 35 #include "ui/gl/gl_share_group.h" | 35 #include "ui/gl/gl_share_group.h" |
| 36 #include "ui/gl/gl_surface.h" | 36 #include "ui/gl/gl_surface.h" |
| 37 | 37 |
| 38 namespace gpu { | 38 namespace gpu { |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 size_t BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { | 41 size_t StrideInBytes(size_t width, gfx::GpuMemoryBuffer::Format format) { |
| 42 switch (format) { | 42 switch (format) { |
| 43 case gfx::GpuMemoryBuffer::RGBA_8888: | 43 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 44 case gfx::GpuMemoryBuffer::BGRA_8888: | 44 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 45 return 4; | 45 return width * 4; |
| 46 case gfx::GpuMemoryBuffer::RGBX_8888: | 46 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 47 NOTREACHED(); | 47 NOTREACHED(); |
| 48 return 0; | 48 return 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 NOTREACHED(); | 51 NOTREACHED(); |
| 52 return 0; | 52 return 0; |
| 53 } | 53 } |
| 54 | 54 |
| 55 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 55 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
| 56 public: | 56 public: |
| 57 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, | 57 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, |
| 58 const gfx::Size& size, | 58 const gfx::Size& size, |
| 59 gfx::GpuMemoryBuffer::Format format) | 59 gfx::GpuMemoryBuffer::Format format) |
| 60 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} | 60 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} |
| 61 | 61 |
| 62 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { | 62 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { |
| 63 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 63 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Overridden from gfx::GpuMemoryBuffer: | 66 // Overridden from gfx::GpuMemoryBuffer: |
| 67 void* Map() override { | 67 void* Map() override { |
| 68 mapped_ = true; | 68 mapped_ = true; |
| 69 return &bytes_->data().front(); | 69 return &bytes_->data().front(); |
| 70 } | 70 } |
| 71 void Unmap() override { mapped_ = false; } | 71 void Unmap() override { mapped_ = false; } |
| 72 bool IsMapped() const override { return mapped_; } | 72 bool IsMapped() const override { return mapped_; } |
| 73 Format GetFormat() const override { return format_; } | 73 Format GetFormat() const override { return format_; } |
| 74 uint32 GetStride() const override { | 74 uint32 GetStride() const override { |
| 75 return size_.width() * BytesPerPixel(format_); | 75 return StrideInBytes(size_.width(), format_); |
| 76 } | 76 } |
| 77 gfx::GpuMemoryBufferHandle GetHandle() const override { | 77 gfx::GpuMemoryBufferHandle GetHandle() const override { |
| 78 NOTREACHED(); | 78 NOTREACHED(); |
| 79 return gfx::GpuMemoryBufferHandle(); | 79 return gfx::GpuMemoryBufferHandle(); |
| 80 } | 80 } |
| 81 ClientBuffer AsClientBuffer() override { | 81 ClientBuffer AsClientBuffer() override { |
| 82 return reinterpret_cast<ClientBuffer>(this); | 82 return reinterpret_cast<ClientBuffer>(this); |
| 83 } | 83 } |
| 84 | 84 |
| 85 base::RefCountedBytes* bytes() { return bytes_.get(); } | 85 base::RefCountedBytes* bytes() { return bytes_.get(); } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 delete base_context_; | 127 delete base_context_; |
| 128 base_context_ = NULL; | 128 base_context_ = NULL; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // static | 133 // static |
| 134 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( | 134 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( |
| 135 const gfx::Size& size, | 135 const gfx::Size& size, |
| 136 gfx::GpuMemoryBuffer::Format format) { | 136 gfx::GpuMemoryBuffer::Format format) { |
| 137 std::vector<unsigned char> data(size.GetArea() * BytesPerPixel(format), 0); | 137 std::vector<unsigned char> data( |
| 138 StrideInBytes(size.width(), format) * size.height(), 0); |
| 138 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 139 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
| 139 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 140 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
| 140 new GpuMemoryBufferImpl(bytes.get(), size, format)); | 141 new GpuMemoryBufferImpl(bytes.get(), size, format)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void GLManager::Initialize(const GLManager::Options& options) { | 144 void GLManager::Initialize(const GLManager::Options& options) { |
| 144 InitializeWithCommandLine(options, nullptr); | 145 InitializeWithCommandLine(options, nullptr); |
| 145 } | 146 } |
| 146 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, | 147 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, |
| 147 base::CommandLine* command_line) { | 148 base::CommandLine* command_line) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 void GLManager::SetSurfaceVisible(bool visible) { | 423 void GLManager::SetSurfaceVisible(bool visible) { |
| 423 NOTIMPLEMENTED(); | 424 NOTIMPLEMENTED(); |
| 424 } | 425 } |
| 425 | 426 |
| 426 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { | 427 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { |
| 427 NOTIMPLEMENTED(); | 428 NOTIMPLEMENTED(); |
| 428 return 0; | 429 return 0; |
| 429 } | 430 } |
| 430 | 431 |
| 431 } // namespace gpu | 432 } // namespace gpu |
| OLD | NEW |