OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/view_manager/gles2/mojo_gpu_memory_buffer.h" | 5 #include "components/view_manager/gles2/mojo_gpu_memory_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "ui/gfx/buffer_format_util.h" | 10 #include "ui/gfx/buffer_format_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 case gfx::BufferFormat::RGBA_4444: | 24 case gfx::BufferFormat::RGBA_4444: |
25 case gfx::BufferFormat::RGBA_8888: | 25 case gfx::BufferFormat::RGBA_8888: |
26 case gfx::BufferFormat::RGBX_8888: | 26 case gfx::BufferFormat::RGBX_8888: |
27 case gfx::BufferFormat::BGRA_8888: | 27 case gfx::BufferFormat::BGRA_8888: |
28 return 1; | 28 return 1; |
29 case gfx::BufferFormat::YUV_420: { | 29 case gfx::BufferFormat::YUV_420: { |
30 static size_t factor[] = {1, 2, 2}; | 30 static size_t factor[] = {1, 2, 2}; |
31 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); | 31 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
32 return factor[plane]; | 32 return factor[plane]; |
33 } | 33 } |
| 34 case gfx::BufferFormat::YUV_420_BIPLANAR: { |
| 35 static size_t factor[] = {1, 2}; |
| 36 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 37 return factor[plane]; |
| 38 } |
34 } | 39 } |
35 NOTREACHED(); | 40 NOTREACHED(); |
36 return 0; | 41 return 0; |
37 } | 42 } |
38 | 43 |
39 size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { | 44 size_t StrideInBytes(size_t width, gfx::BufferFormat format, int plane) { |
40 switch (format) { | 45 switch (format) { |
41 case gfx::BufferFormat::ATCIA: | 46 case gfx::BufferFormat::ATCIA: |
42 case gfx::BufferFormat::DXT5: | 47 case gfx::BufferFormat::DXT5: |
43 DCHECK_EQ(plane, 0); | 48 DCHECK_EQ(plane, 0); |
44 return width; | 49 return width; |
45 case gfx::BufferFormat::ATC: | 50 case gfx::BufferFormat::ATC: |
46 case gfx::BufferFormat::DXT1: | 51 case gfx::BufferFormat::DXT1: |
47 case gfx::BufferFormat::ETC1: | 52 case gfx::BufferFormat::ETC1: |
48 DCHECK_EQ(plane, 0); | 53 DCHECK_EQ(plane, 0); |
49 DCHECK_EQ(width % 2, 0u); | 54 DCHECK_EQ(width % 2, 0u); |
50 return width / 2; | 55 return width / 2; |
51 case gfx::BufferFormat::R_8: | 56 case gfx::BufferFormat::R_8: |
52 return (width + 3) & ~0x3; | 57 return (width + 3) & ~0x3; |
53 case gfx::BufferFormat::RGBA_4444: | 58 case gfx::BufferFormat::RGBA_4444: |
54 DCHECK_EQ(plane, 0); | 59 DCHECK_EQ(plane, 0); |
55 return width * 2; | 60 return width * 2; |
56 case gfx::BufferFormat::RGBA_8888: | 61 case gfx::BufferFormat::RGBA_8888: |
57 case gfx::BufferFormat::RGBX_8888: | 62 case gfx::BufferFormat::RGBX_8888: |
58 case gfx::BufferFormat::BGRA_8888: | 63 case gfx::BufferFormat::BGRA_8888: |
59 DCHECK_EQ(plane, 0); | 64 DCHECK_EQ(plane, 0); |
60 return width * 4; | 65 return width * 4; |
61 case gfx::BufferFormat::YUV_420: | 66 case gfx::BufferFormat::YUV_420: |
62 return width / SubsamplingFactor(format, plane); | 67 return width / SubsamplingFactor(format, plane); |
| 68 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 69 return width; |
63 } | 70 } |
64 NOTREACHED(); | 71 NOTREACHED(); |
65 return 0; | 72 return 0; |
66 } | 73 } |
67 | 74 |
68 size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { | 75 size_t BufferSizeInBytes(const gfx::Size& size, gfx::BufferFormat format) { |
69 size_t size_in_bytes = 0; | 76 size_t size_in_bytes = 0; |
70 int num_planes = static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format)); | 77 int num_planes = static_cast<int>(gfx::NumberOfPlanesForBufferFormat(format)); |
71 for (int i = 0; i < num_planes; ++i) { | 78 for (int i = 0; i < num_planes; ++i) { |
72 size_in_bytes += StrideInBytes(size.width(), format, i) * | 79 size_in_bytes += StrideInBytes(size.width(), format, i) * |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 handle.type = gfx::SHARED_MEMORY_BUFFER; | 160 handle.type = gfx::SHARED_MEMORY_BUFFER; |
154 handle.handle = shared_memory_->handle(); | 161 handle.handle = shared_memory_->handle(); |
155 return handle; | 162 return handle; |
156 } | 163 } |
157 | 164 |
158 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { | 165 ClientBuffer MojoGpuMemoryBufferImpl::AsClientBuffer() { |
159 return reinterpret_cast<ClientBuffer>(this); | 166 return reinterpret_cast<ClientBuffer>(this); |
160 } | 167 } |
161 | 168 |
162 } // namespace gles2 | 169 } // namespace gles2 |
OLD | NEW |