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 TotalBufferSizeInBytes(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 size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); | |
135 if (num_planes > 1) { | |
reveman
2015/04/07 19:03:25
nit: this if statement is not necessary, the for l
| |
136 for (size_t i = 0; i < num_planes - 1; ++i) { | |
137 size_t offset = StrideInBytes(size_.width(), format_, i) * | |
138 (size_.height() / SubsamplingFactor(format_, i)); | |
139 data[i + 1] = reinterpret_cast<uint8*>(data[i]) + offset; | |
140 } | |
141 } | |
76 mapped_ = true; | 142 mapped_ = true; |
77 *data = &bytes_->data().front(); | |
78 return true; | 143 return true; |
79 } | 144 } |
80 void Unmap() override { mapped_ = false; } | 145 void Unmap() override { mapped_ = false; } |
81 bool IsMapped() const override { return mapped_; } | 146 bool IsMapped() const override { return mapped_; } |
82 Format GetFormat() const override { return format_; } | 147 Format GetFormat() const override { return format_; } |
83 void GetStride(uint32* stride) const override { | 148 void GetStride(uint32* stride) const override { |
84 *stride = StrideInBytes(size_.width(), format_); | 149 for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format_); |
150 ++i) { | |
151 stride[i] = StrideInBytes(size_.width(), format_, i); | |
152 } | |
85 } | 153 } |
86 gfx::GpuMemoryBufferHandle GetHandle() const override { | 154 gfx::GpuMemoryBufferHandle GetHandle() const override { |
87 NOTREACHED(); | 155 NOTREACHED(); |
88 return gfx::GpuMemoryBufferHandle(); | 156 return gfx::GpuMemoryBufferHandle(); |
89 } | 157 } |
90 ClientBuffer AsClientBuffer() override { | 158 ClientBuffer AsClientBuffer() override { |
91 return reinterpret_cast<ClientBuffer>(this); | 159 return reinterpret_cast<ClientBuffer>(this); |
92 } | 160 } |
93 | 161 |
94 base::RefCountedBytes* bytes() { return bytes_.get(); } | 162 base::RefCountedBytes* bytes() { return bytes_.get(); } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 delete base_context_; | 204 delete base_context_; |
137 base_context_ = NULL; | 205 base_context_ = NULL; |
138 } | 206 } |
139 } | 207 } |
140 } | 208 } |
141 | 209 |
142 // static | 210 // static |
143 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( | 211 scoped_ptr<gfx::GpuMemoryBuffer> GLManager::CreateGpuMemoryBuffer( |
144 const gfx::Size& size, | 212 const gfx::Size& size, |
145 gfx::GpuMemoryBuffer::Format format) { | 213 gfx::GpuMemoryBuffer::Format format) { |
146 std::vector<unsigned char> data( | 214 std::vector<unsigned char> data(TotalBufferSizeInBytes(size, format), 0); |
147 StrideInBytes(size.width(), format) * size.height(), 0); | |
148 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 215 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
149 return make_scoped_ptr<gfx::GpuMemoryBuffer>( | 216 return make_scoped_ptr<gfx::GpuMemoryBuffer>( |
150 new GpuMemoryBufferImpl(bytes.get(), size, format)); | 217 new GpuMemoryBufferImpl(bytes.get(), size, format)); |
151 } | 218 } |
152 | 219 |
153 void GLManager::Initialize(const GLManager::Options& options) { | 220 void GLManager::Initialize(const GLManager::Options& options) { |
154 InitializeWithCommandLine(options, nullptr); | 221 InitializeWithCommandLine(options, nullptr); |
155 } | 222 } |
156 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, | 223 void GLManager::InitializeWithCommandLine(const GLManager::Options& options, |
157 base::CommandLine* command_line) { | 224 base::CommandLine* command_line) { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { | 503 uint32 GLManager::CreateStreamTexture(uint32 texture_id) { |
437 NOTIMPLEMENTED(); | 504 NOTIMPLEMENTED(); |
438 return 0; | 505 return 0; |
439 } | 506 } |
440 | 507 |
441 void GLManager::SetLock(base::Lock*) { | 508 void GLManager::SetLock(base::Lock*) { |
442 NOTIMPLEMENTED(); | 509 NOTIMPLEMENTED(); |
443 } | 510 } |
444 | 511 |
445 } // namespace gpu | 512 } // namespace gpu |
OLD | NEW |