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