| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( | 80 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
| 81 Format format) { | 81 Format format) { |
| 82 switch (format) { | 82 switch (format) { |
| 83 case ATC: | 83 case ATC: |
| 84 case ATCIA: | 84 case ATCIA: |
| 85 case DXT1: | 85 case DXT1: |
| 86 case DXT5: | 86 case DXT5: |
| 87 case ETC1: | 87 case ETC1: |
| 88 case R_8: |
| 88 case RGBA_8888: | 89 case RGBA_8888: |
| 89 case RGBX_8888: | 90 case RGBX_8888: |
| 90 case BGRA_8888: | 91 case BGRA_8888: |
| 91 return 1; | 92 return 1; |
| 92 case YUV_420: | 93 case YUV_420: |
| 93 return 3; | 94 return 3; |
| 94 } | 95 } |
| 95 NOTREACHED(); | 96 NOTREACHED(); |
| 96 return 0; | 97 return 0; |
| 97 } | 98 } |
| 98 | 99 |
| 99 // static | 100 // static |
| 100 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 101 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, |
| 101 Format format, | 102 Format format, |
| 102 int plane, | 103 int plane, |
| 103 size_t* stride_in_bytes) { | 104 size_t* stride_in_bytes) { |
| 105 base::CheckedNumeric<size_t> checked_stride = width; |
| 104 switch (format) { | 106 switch (format) { |
| 105 case ATCIA: | 107 case ATCIA: |
| 106 case DXT5: | 108 case DXT5: |
| 107 DCHECK_EQ(plane, 0); | 109 DCHECK_EQ(plane, 0); |
| 108 *stride_in_bytes = width; | 110 *stride_in_bytes = width; |
| 109 return true; | 111 return true; |
| 110 case ATC: | 112 case ATC: |
| 111 case DXT1: | 113 case DXT1: |
| 112 case ETC1: | 114 case ETC1: |
| 113 DCHECK_EQ(plane, 0); | 115 DCHECK_EQ(plane, 0); |
| 114 DCHECK_EQ(width % 2, 0U); | 116 DCHECK_EQ(width % 2, 0u); |
| 115 *stride_in_bytes = width / 2; | 117 *stride_in_bytes = width / 2; |
| 116 return true; | 118 return true; |
| 119 case R_8: |
| 120 checked_stride += 3; |
| 121 if (!checked_stride.IsValid()) |
| 122 return false; |
| 123 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; |
| 124 return true; |
| 125 case RGBX_8888: |
| 117 case RGBA_8888: | 126 case RGBA_8888: |
| 118 case RGBX_8888: | 127 case BGRA_8888: |
| 119 case BGRA_8888: { | 128 checked_stride *= 4; |
| 120 base::CheckedNumeric<size_t> s = width; | 129 if (!checked_stride.IsValid()) |
| 121 DCHECK_EQ(plane, 0); | |
| 122 s *= 4; | |
| 123 if (!s.IsValid()) | |
| 124 return false; | 130 return false; |
| 125 *stride_in_bytes = s.ValueOrDie(); | 131 *stride_in_bytes = checked_stride.ValueOrDie(); |
| 126 return true; | 132 return true; |
| 127 } | 133 case YUV_420: |
| 128 case YUV_420: { | |
| 129 DCHECK_EQ(width % 2, 0u); | 134 DCHECK_EQ(width % 2, 0u); |
| 130 *stride_in_bytes = width / SubsamplingFactor(format, plane); | 135 *stride_in_bytes = width / SubsamplingFactor(format, plane); |
| 131 return true; | 136 return true; |
| 132 } | |
| 133 } | 137 } |
| 138 |
| 134 NOTREACHED(); | 139 NOTREACHED(); |
| 135 return false; | 140 return false; |
| 136 } | 141 } |
| 137 | 142 |
| 138 // static | 143 // static |
| 139 size_t GpuMemoryBufferImpl::SubsamplingFactor( | 144 size_t GpuMemoryBufferImpl::SubsamplingFactor( |
| 140 Format format, | 145 Format format, |
| 141 int plane) { | 146 int plane) { |
| 142 switch (format) { | 147 switch (format) { |
| 143 case ATC: | 148 case ATC: |
| 144 case ATCIA: | 149 case ATCIA: |
| 145 case DXT1: | 150 case DXT1: |
| 146 case DXT5: | 151 case DXT5: |
| 147 case ETC1: | 152 case ETC1: |
| 153 case R_8: |
| 148 case RGBA_8888: | 154 case RGBA_8888: |
| 149 case RGBX_8888: | 155 case RGBX_8888: |
| 150 case BGRA_8888: | 156 case BGRA_8888: |
| 151 return 1; | 157 return 1; |
| 152 case YUV_420: { | 158 case YUV_420: { |
| 153 static size_t factor[] = {1, 2, 2}; | 159 static size_t factor[] = {1, 2, 2}; |
| 154 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); | 160 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 155 return factor[plane]; | 161 return factor[plane]; |
| 156 } | 162 } |
| 157 } | 163 } |
| 158 NOTREACHED(); | 164 NOTREACHED(); |
| 159 return 0; | 165 return 0; |
| 160 } | 166 } |
| 161 | 167 |
| 162 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 168 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
| 163 return format_; | 169 return format_; |
| 164 } | 170 } |
| 165 | 171 |
| 166 bool GpuMemoryBufferImpl::IsMapped() const { | 172 bool GpuMemoryBufferImpl::IsMapped() const { |
| 167 return mapped_; | 173 return mapped_; |
| 168 } | 174 } |
| 169 | 175 |
| 170 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 176 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| 171 return reinterpret_cast<ClientBuffer>(this); | 177 return reinterpret_cast<ClientBuffer>(this); |
| 172 } | 178 } |
| 173 | 179 |
| 174 } // namespace content | 180 } // namespace content |
| OLD | NEW |