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 StrideInBytes(size_t width, gfx::GpuMemoryBuffer::Format format) { | 41 size_t NumberOfPlanesForGpuMemoryBufferFormat( |
| 42 gfx::GpuMemoryBuffer::Format format) { |
| 43 switch (format) { |
| 44 case gfx::GpuMemoryBuffer::Format::ATC: |
| 45 case gfx::GpuMemoryBuffer::Format::ATCIA: |
| 46 case gfx::GpuMemoryBuffer::Format::DXT1: |
| 47 case gfx::GpuMemoryBuffer::Format::DXT5: |
| 48 case gfx::GpuMemoryBuffer::Format::ETC1: |
| 49 case gfx::GpuMemoryBuffer::Format::RGBA_8888: |
| 50 case gfx::GpuMemoryBuffer::Format::RGBX_8888: |
| 51 case gfx::GpuMemoryBuffer::Format::BGRA_8888: |
| 52 return 1; |
| 53 case gfx::GpuMemoryBuffer::Format::YUV_420: |
| 54 return 3; |
| 55 } |
| 56 NOTREACHED(); |
| 57 return 0; |
| 58 } |
| 59 |
| 60 size_t SubsamplingFactor(gfx::GpuMemoryBuffer::Format format, int plane) { |
| 61 switch (format) { |
| 62 case gfx::GpuMemoryBuffer::ATC: |
| 63 case gfx::GpuMemoryBuffer::ATCIA: |
| 64 case gfx::GpuMemoryBuffer::DXT1: |
| 65 case gfx::GpuMemoryBuffer::DXT5: |
| 66 case gfx::GpuMemoryBuffer::ETC1: |
| 67 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 68 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 69 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 70 return 1; |
| 71 case gfx::GpuMemoryBuffer::YUV_420: { |
| 72 static size_t factor[] = {1, 2, 2}; |
| 73 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 74 return factor[plane]; |
| 75 } |
| 76 } |
| 77 NOTREACHED(); |
| 78 return 0; |
| 79 } |
| 80 |
| 81 size_t StrideInBytes(size_t width, |
| 82 gfx::GpuMemoryBuffer::Format format, |
| 83 int plane) { |
42 switch (format) { | 84 switch (format) { |
43 case gfx::GpuMemoryBuffer::ATCIA: | 85 case gfx::GpuMemoryBuffer::ATCIA: |
44 case gfx::GpuMemoryBuffer::DXT5: | 86 case gfx::GpuMemoryBuffer::DXT5: |
| 87 DCHECK_EQ(plane, 0); |
45 return width; | 88 return width; |
46 case gfx::GpuMemoryBuffer::ATC: | 89 case gfx::GpuMemoryBuffer::ATC: |
47 case gfx::GpuMemoryBuffer::DXT1: | 90 case gfx::GpuMemoryBuffer::DXT1: |
48 case gfx::GpuMemoryBuffer::ETC1: | 91 case gfx::GpuMemoryBuffer::ETC1: |
| 92 DCHECK_EQ(plane, 0); |
49 DCHECK_EQ(width % 2, 0U); | 93 DCHECK_EQ(width % 2, 0U); |
50 return width / 2; | 94 return width / 2; |
51 case gfx::GpuMemoryBuffer::RGBA_8888: | 95 case gfx::GpuMemoryBuffer::RGBA_8888: |
52 case gfx::GpuMemoryBuffer::BGRA_8888: | 96 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 97 DCHECK_EQ(plane, 0); |
53 return width * 4; | 98 return width * 4; |
54 case gfx::GpuMemoryBuffer::RGBX_8888: | 99 case gfx::GpuMemoryBuffer::RGBX_8888: |
55 NOTREACHED(); | 100 NOTREACHED(); |
56 return 0; | 101 return 0; |
| 102 case gfx::GpuMemoryBuffer::YUV_420: |
| 103 return width / SubsamplingFactor(format, plane); |
57 } | 104 } |
58 | 105 |
59 NOTREACHED(); | 106 NOTREACHED(); |
60 return 0; | 107 return 0; |
61 } | 108 } |
62 | 109 |
| 110 size_t BufferSizeInBytes(const gfx::Size& size, |
| 111 gfx::GpuMemoryBuffer::Format format) { |
| 112 size_t size_in_bytes = 0u; |
| 113 for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format); ++i) { |
| 114 size_in_bytes += StrideInBytes(size.width(), format, i) * |
| 115 (size.height() / SubsamplingFactor(format, i)); |
| 116 } |
| 117 return size_in_bytes; |
| 118 } |
| 119 |
63 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { | 120 class GpuMemoryBufferImpl : public gfx::GpuMemoryBuffer { |
64 public: | 121 public: |
65 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, | 122 GpuMemoryBufferImpl(base::RefCountedBytes* bytes, |
66 const gfx::Size& size, | 123 const gfx::Size& size, |
67 gfx::GpuMemoryBuffer::Format format) | 124 gfx::GpuMemoryBuffer::Format format) |
68 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} | 125 : bytes_(bytes), size_(size), format_(format), mapped_(false) {} |
69 | 126 |
70 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { | 127 static GpuMemoryBufferImpl* FromClientBuffer(ClientBuffer buffer) { |
71 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 128 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
72 } | 129 } |
73 | 130 |
74 // Overridden from gfx::GpuMemoryBuffer: | 131 // Overridden from gfx::GpuMemoryBuffer: |
75 bool Map(void** data) override { | 132 bool Map(void** data) override { |
| 133 data[0] = &bytes_->data().front(); |
| 134 for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format_) - 1; |
| 135 ++i) { |
| 136 size_t offset = StrideInBytes(size_.width(), format_, i) * |
| 137 (size_.height() / SubsamplingFactor(format_, i)); |
| 138 data[i + 1] = reinterpret_cast<uint8*>(data[i]) + offset; |
| 139 } |
76 mapped_ = true; | 140 mapped_ = true; |
77 *data = &bytes_->data().front(); | |
78 return true; | 141 return true; |
79 } | 142 } |
80 void Unmap() override { mapped_ = false; } | 143 void Unmap() override { mapped_ = false; } |
81 bool IsMapped() const override { return mapped_; } | 144 bool IsMapped() const override { return mapped_; } |
82 Format GetFormat() const override { return format_; } | 145 Format GetFormat() const override { return format_; } |
83 void GetStride(uint32* stride) const override { | 146 void GetStride(uint32* stride) const override { |
84 *stride = StrideInBytes(size_.width(), format_); | 147 for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format_); |
| 148 ++i) { |
| 149 stride[i] = StrideInBytes(size_.width(), format_, i); |
| 150 } |
85 } | 151 } |
86 gfx::GpuMemoryBufferHandle GetHandle() const override { | 152 gfx::GpuMemoryBufferHandle GetHandle() const override { |
87 NOTREACHED(); | 153 NOTREACHED(); |
88 return gfx::GpuMemoryBufferHandle(); | 154 return gfx::GpuMemoryBufferHandle(); |
89 } | 155 } |
90 ClientBuffer AsClientBuffer() override { | 156 ClientBuffer AsClientBuffer() override { |
91 return reinterpret_cast<ClientBuffer>(this); | 157 return reinterpret_cast<ClientBuffer>(this); |
92 } | 158 } |
93 | 159 |
94 base::RefCountedBytes* bytes() { return bytes_.get(); } | 160 base::RefCountedBytes* bytes() { return bytes_.get(); } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 delete base_context_; | 202 delete base_context_; |
137 base_context_ = NULL; | 203 base_context_ = NULL; |
138 } | 204 } |
139 } | 205 } |
140 } | 206 } |
141 | 207 |
142 // static | 208 // static |
143 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( | 209 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( |
144 const gfx::Size& size, | 210 const gfx::Size& size, |
145 gfx::GpuMemoryBuffer::Format format) { | 211 gfx::GpuMemoryBuffer::Format format) { |
146 std::vector<unsigned char> data( | 212 std::vector<unsigned char> data(BufferSizeInBytes(size, format), 0); |
147 StrideInBytes(size.width(), format) * size.height(), 0); | |
148 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 213 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
149 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 214 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
150 new GpuMemoryBufferImpl(bytes.get(), size, format)); | 215 new GpuMemoryBufferImpl(bytes.get(), size, format)); |
151 } | 216 } |
152 | 217 |
153 void GLManager::Initialize(const GLManager::Options& options) { | 218 void GLManager::Initialize(const GLManager::Options& options) { |
154 InitializeWithCommandLine(options, nullptr); | 219 InitializeWithCommandLine(options, nullptr); |
155 } | 220 } |
156 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, | 221 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, |
157 base::CommandLine* command_line) { | 222 base::CommandLine* command_line) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { | 501 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { |
437 NOTIMPLEMENTED(); | 502 NOTIMPLEMENTED(); |
438 return 0; | 503 return 0; |
439 } | 504 } |
440 | 505 |
441 void GLManager::SetLock(base::Lock*) { | 506 void GLManager::SetLock(base::Lock*) { |
442 NOTIMPLEMENTED(); | 507 NOTIMPLEMENTED(); |
443 } | 508 } |
444 | 509 |
445 } // namespace gpu | 510 } // namespace gpu |
OLD | NEW |