OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/numerics/safe_math.h" | 8 #include "base/numerics/safe_math.h" |
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | 74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
75 ClientBuffer buffer) { | 75 ClientBuffer buffer) { |
76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
| 80 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
| 81 Format format) { |
| 82 switch (format) { |
| 83 case ATC: |
| 84 case ATCIA: |
| 85 case DXT1: |
| 86 case DXT5: |
| 87 case ETC1: |
| 88 case RGBA_8888: |
| 89 case RGBX_8888: |
| 90 case BGRA_8888: |
| 91 return 1; |
| 92 case YUV_420: |
| 93 return 3; |
| 94 } |
| 95 NOTREACHED(); |
| 96 return 0; |
| 97 } |
| 98 |
| 99 // static |
80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 100 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, |
81 Format format, | 101 Format format, |
| 102 int plane, |
82 size_t* stride_in_bytes) { | 103 size_t* stride_in_bytes) { |
83 base::CheckedNumeric<size_t> s = width; | |
84 switch (format) { | 104 switch (format) { |
85 case ATCIA: | 105 case ATCIA: |
86 case DXT5: | 106 case DXT5: |
| 107 DCHECK_EQ(plane, 0); |
87 *stride_in_bytes = width; | 108 *stride_in_bytes = width; |
88 return true; | 109 return true; |
89 case ATC: | 110 case ATC: |
90 case DXT1: | 111 case DXT1: |
91 case ETC1: | 112 case ETC1: |
| 113 DCHECK_EQ(plane, 0); |
92 DCHECK_EQ(width % 2, 0U); | 114 DCHECK_EQ(width % 2, 0U); |
93 s /= 2; | 115 *stride_in_bytes = width / 2; |
94 if (!s.IsValid()) | |
95 return false; | |
96 | |
97 *stride_in_bytes = s.ValueOrDie(); | |
98 return true; | 116 return true; |
99 case RGBA_8888: | 117 case RGBA_8888: |
100 case RGBX_8888: | 118 case RGBX_8888: |
101 case BGRA_8888: | 119 case BGRA_8888: { |
| 120 base::CheckedNumeric<size_t> s = width; |
| 121 DCHECK_EQ(plane, 0); |
102 s *= 4; | 122 s *= 4; |
103 if (!s.IsValid()) | 123 if (!s.IsValid()) |
104 return false; | 124 return false; |
105 | |
106 *stride_in_bytes = s.ValueOrDie(); | 125 *stride_in_bytes = s.ValueOrDie(); |
107 return true; | 126 return true; |
| 127 } |
| 128 case YUV_420: { |
| 129 DCHECK_EQ(width % 2, 0u); |
| 130 *stride_in_bytes = width / SubsamplingFactor(format, plane); |
| 131 return true; |
| 132 } |
108 } | 133 } |
109 | |
110 NOTREACHED(); | 134 NOTREACHED(); |
111 return false; | 135 return false; |
112 } | 136 } |
113 | 137 |
114 // static | 138 // static |
115 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( | 139 size_t GpuMemoryBufferImpl::SubsamplingFactor( |
116 gfx::GpuMemoryBuffer::Format format) { | 140 Format format, |
| 141 int plane) { |
117 switch (format) { | 142 switch (format) { |
118 case gfx::GpuMemoryBuffer::Format::ATC: | 143 case ATC: |
119 case gfx::GpuMemoryBuffer::Format::ATCIA: | 144 case ATCIA: |
120 case gfx::GpuMemoryBuffer::Format::DXT1: | 145 case DXT1: |
121 case gfx::GpuMemoryBuffer::Format::DXT5: | 146 case DXT5: |
122 case gfx::GpuMemoryBuffer::Format::ETC1: | 147 case ETC1: |
123 case gfx::GpuMemoryBuffer::Format::RGBA_8888: | 148 case RGBA_8888: |
124 case gfx::GpuMemoryBuffer::Format::RGBX_8888: | 149 case RGBX_8888: |
125 case gfx::GpuMemoryBuffer::Format::BGRA_8888: | 150 case BGRA_8888: |
126 return 1; | 151 return 1; |
127 default: | 152 case YUV_420: { |
128 NOTREACHED(); | 153 static size_t factor[] = {1, 2, 2}; |
129 return 0; | 154 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 155 return factor[plane]; |
| 156 } |
130 } | 157 } |
| 158 NOTREACHED(); |
| 159 return 0; |
131 } | 160 } |
132 | 161 |
133 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 162 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
134 return format_; | 163 return format_; |
135 } | 164 } |
136 | 165 |
137 bool GpuMemoryBufferImpl::IsMapped() const { | 166 bool GpuMemoryBufferImpl::IsMapped() const { |
138 return mapped_; | 167 return mapped_; |
139 } | 168 } |
140 | 169 |
141 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 170 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
142 return reinterpret_cast<ClientBuffer>(this); | 171 return reinterpret_cast<ClientBuffer>(this); |
143 } | 172 } |
144 | 173 |
145 } // namespace content | 174 } // namespace content |
OLD | NEW |