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