Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, |
| 81 Format format, | 81 Format format, |
| 82 size_t* stride_in_bytes) { | 82 size_t* stride_in_bytes) { |
| 83 base::CheckedNumeric<size_t> s = width; | 83 base::CheckedNumeric<size_t> s = width; |
| 84 switch (format) { | 84 switch (format) { |
| 85 case ATCIA: | |
| 86 case DXT5: | |
| 87 *stride_in_bytes = width; | |
| 88 return true; | |
| 89 case ATC: | |
| 90 case DXT1: | |
| 91 case ETC1: | |
| 92 DCHECK_EQ(width % 2, 0U); | |
|
piman
2015/02/19 23:52:04
Could we add a DCHECK, somewhere on the client sid
christiank
2015/02/20 08:32:14
I agree, sounds like a good idea. Fixed.
| |
| 93 s /= 2; | |
| 94 if (!s.IsValid()) | |
| 95 return false; | |
| 96 | |
| 97 *stride_in_bytes = s.ValueOrDie(); | |
| 98 return true; | |
| 85 case RGBA_8888: | 99 case RGBA_8888: |
| 86 case RGBX_8888: | 100 case RGBX_8888: |
| 87 case BGRA_8888: | 101 case BGRA_8888: |
| 88 s *= 4; | 102 s *= 4; |
| 89 if (!s.IsValid()) | 103 if (!s.IsValid()) |
| 90 return false; | 104 return false; |
| 91 | 105 |
| 92 *stride_in_bytes = s.ValueOrDie(); | 106 *stride_in_bytes = s.ValueOrDie(); |
| 93 return true; | 107 return true; |
| 94 } | 108 } |
| 95 | 109 |
| 96 NOTREACHED(); | 110 NOTREACHED(); |
| 97 return false; | 111 return false; |
| 98 } | 112 } |
| 99 | 113 |
| 100 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 114 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
| 101 return format_; | 115 return format_; |
| 102 } | 116 } |
| 103 | 117 |
| 104 bool GpuMemoryBufferImpl::IsMapped() const { | 118 bool GpuMemoryBufferImpl::IsMapped() const { |
| 105 return mapped_; | 119 return mapped_; |
| 106 } | 120 } |
| 107 | 121 |
| 108 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 122 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| 109 return reinterpret_cast<ClientBuffer>(this); | 123 return reinterpret_cast<ClientBuffer>(this); |
| 110 } | 124 } |
| 111 | 125 |
| 112 } // namespace content | 126 } // namespace content |
| OLD | NEW |