| 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/gfx/buffer_format_util.h" | 10 #include "ui/gfx/buffer_format_util.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 case gfx::BufferFormat::RGBA_8888: | 92 case gfx::BufferFormat::RGBA_8888: |
| 93 case gfx::BufferFormat::BGRX_8888: | 93 case gfx::BufferFormat::BGRX_8888: |
| 94 case gfx::BufferFormat::BGRA_8888: | 94 case gfx::BufferFormat::BGRA_8888: |
| 95 case gfx::BufferFormat::UYVY_422: | 95 case gfx::BufferFormat::UYVY_422: |
| 96 return 1; | 96 return 1; |
| 97 case gfx::BufferFormat::YUV_420: { | 97 case gfx::BufferFormat::YUV_420: { |
| 98 static size_t factor[] = {1, 2, 2}; | 98 static size_t factor[] = {1, 2, 2}; |
| 99 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); | 99 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 100 return factor[plane]; | 100 return factor[plane]; |
| 101 } | 101 } |
| 102 case gfx::BufferFormat::YUV_420_BIPLANAR: { |
| 103 static size_t factor[] = {1, 2}; |
| 104 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor)); |
| 105 return factor[plane]; |
| 106 } |
| 102 } | 107 } |
| 103 NOTREACHED(); | 108 NOTREACHED(); |
| 104 return 0; | 109 return 0; |
| 105 } | 110 } |
| 106 | 111 |
| 107 // static | 112 // static |
| 108 bool GpuMemoryBufferImpl::RowSizeInBytes(size_t width, | 113 bool GpuMemoryBufferImpl::RowSizeInBytes(size_t width, |
| 109 gfx::BufferFormat format, | 114 gfx::BufferFormat format, |
| 110 int plane, | 115 int plane, |
| 111 size_t* size_in_bytes) { | 116 size_t* size_in_bytes) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 140 case gfx::BufferFormat::BGRA_8888: | 145 case gfx::BufferFormat::BGRA_8888: |
| 141 checked_size *= 4; | 146 checked_size *= 4; |
| 142 if (!checked_size.IsValid()) | 147 if (!checked_size.IsValid()) |
| 143 return false; | 148 return false; |
| 144 *size_in_bytes = checked_size.ValueOrDie(); | 149 *size_in_bytes = checked_size.ValueOrDie(); |
| 145 return true; | 150 return true; |
| 146 case gfx::BufferFormat::YUV_420: | 151 case gfx::BufferFormat::YUV_420: |
| 147 DCHECK_EQ(width % 2, 0u); | 152 DCHECK_EQ(width % 2, 0u); |
| 148 *size_in_bytes = width / SubsamplingFactor(format, plane); | 153 *size_in_bytes = width / SubsamplingFactor(format, plane); |
| 149 return true; | 154 return true; |
| 155 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 156 DCHECK_EQ(width % 2, 0u); |
| 157 *size_in_bytes = width; |
| 158 return true; |
| 150 } | 159 } |
| 151 NOTREACHED(); | 160 NOTREACHED(); |
| 152 return false; | 161 return false; |
| 153 } | 162 } |
| 154 | 163 |
| 155 // static | 164 // static |
| 156 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, | 165 bool GpuMemoryBufferImpl::BufferSizeInBytes(const gfx::Size& size, |
| 157 gfx::BufferFormat format, | 166 gfx::BufferFormat format, |
| 158 size_t* size_in_bytes) { | 167 size_t* size_in_bytes) { |
| 159 base::CheckedNumeric<size_t> checked_size = 0; | 168 base::CheckedNumeric<size_t> checked_size = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 184 | 193 |
| 185 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { | 194 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { |
| 186 return id_; | 195 return id_; |
| 187 } | 196 } |
| 188 | 197 |
| 189 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 198 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| 190 return reinterpret_cast<ClientBuffer>(this); | 199 return reinterpret_cast<ClientBuffer>(this); |
| 191 } | 200 } |
| 192 | 201 |
| 193 } // namespace content | 202 } // namespace content |
| OLD | NEW |