| 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" | |
| 9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
| 10 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 11 | 10 |
| 12 #if defined(OS_MACOSX) | 11 #if defined(OS_MACOSX) |
| 13 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 12 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
| 14 #endif | 13 #endif |
| 15 | 14 |
| 16 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
| 17 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" | 16 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" |
| 18 #endif | 17 #endif |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 // static | 72 // static |
| 74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | 73 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
| 75 ClientBuffer buffer) { | 74 ClientBuffer buffer) { |
| 76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 75 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
| 77 } | 76 } |
| 78 | 77 |
| 79 // static | 78 // static |
| 80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 79 size_t GpuMemoryBufferImpl::BytesPerPixel(Format format) { |
| 81 Format format, | |
| 82 size_t* stride_in_bytes) { | |
| 83 base::CheckedNumeric<size_t> s = width; | |
| 84 switch (format) { | 80 switch (format) { |
| 85 case RGBA_8888: | 81 case RGBA_8888: |
| 86 case RGBX_8888: | 82 case RGBX_8888: |
| 87 case BGRA_8888: | 83 case BGRA_8888: |
| 88 s *= 4; | 84 return 4; |
| 89 if (!s.IsValid()) | |
| 90 return false; | |
| 91 | |
| 92 *stride_in_bytes = s.ValueOrDie(); | |
| 93 return true; | |
| 94 } | 85 } |
| 95 | 86 |
| 96 NOTREACHED(); | 87 NOTREACHED(); |
| 97 return false; | 88 return 0; |
| 98 } | 89 } |
| 99 | 90 |
| 100 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 91 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
| 101 return format_; | 92 return format_; |
| 102 } | 93 } |
| 103 | 94 |
| 104 bool GpuMemoryBufferImpl::IsMapped() const { | 95 bool GpuMemoryBufferImpl::IsMapped() const { |
| 105 return mapped_; | 96 return mapped_; |
| 106 } | 97 } |
| 107 | 98 |
| 108 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 99 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| 109 return reinterpret_cast<ClientBuffer>(this); | 100 return reinterpret_cast<ClientBuffer>(this); |
| 110 } | 101 } |
| 111 | 102 |
| 112 } // namespace content | 103 } // namespace content |
| OLD | NEW |