| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // static | 73 // static |
| 74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | 74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
| 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> checked_stride = width; |
| 84 switch (format) { | 84 switch (format) { |
| 85 case ATCIA: | 85 case GpuMemoryBuffer::R_8: |
| 86 case DXT5: | 86 checked_stride += 3; |
| 87 if (!checked_stride.IsValid()) |
| 88 return false; |
| 89 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; |
| 90 return true; |
| 91 case GpuMemoryBuffer::ATCIA: |
| 92 case GpuMemoryBuffer::DXT5: |
| 87 *stride_in_bytes = width; | 93 *stride_in_bytes = width; |
| 88 return true; | 94 return true; |
| 89 case ATC: | 95 case GpuMemoryBuffer::ATC: |
| 90 case DXT1: | 96 case GpuMemoryBuffer::DXT1: |
| 91 case ETC1: | 97 case GpuMemoryBuffer::ETC1: |
| 92 DCHECK_EQ(width % 2, 0U); | 98 DCHECK_EQ(width % 2, 0u); |
| 93 s /= 2; | 99 *stride_in_bytes = width / 2; |
| 94 if (!s.IsValid()) | 100 return true; |
| 101 case GpuMemoryBuffer::RGBA_8888: |
| 102 case GpuMemoryBuffer::RGBX_8888: |
| 103 case GpuMemoryBuffer::BGRA_8888: |
| 104 checked_stride *= 4; |
| 105 if (!checked_stride.IsValid()) |
| 95 return false; | 106 return false; |
| 96 | 107 *stride_in_bytes = checked_stride.ValueOrDie(); |
| 97 *stride_in_bytes = s.ValueOrDie(); | |
| 98 return true; | |
| 99 case RGBA_8888: | |
| 100 case RGBX_8888: | |
| 101 case BGRA_8888: | |
| 102 s *= 4; | |
| 103 if (!s.IsValid()) | |
| 104 return false; | |
| 105 | |
| 106 *stride_in_bytes = s.ValueOrDie(); | |
| 107 return true; | 108 return true; |
| 108 } | 109 } |
| 109 | |
| 110 NOTREACHED(); | 110 NOTREACHED(); |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // static | 114 // static |
| 115 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( | 115 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( |
| 116 gfx::GpuMemoryBuffer::Format format) { | 116 gfx::GpuMemoryBuffer::Format format) { |
| 117 switch (format) { | 117 switch (format) { |
| 118 case gfx::GpuMemoryBuffer::Format::ATC: | 118 case gfx::GpuMemoryBuffer::Format::ATC: |
| 119 case gfx::GpuMemoryBuffer::Format::ATCIA: | 119 case gfx::GpuMemoryBuffer::Format::ATCIA: |
| 120 case gfx::GpuMemoryBuffer::Format::DXT1: | 120 case gfx::GpuMemoryBuffer::Format::DXT1: |
| 121 case gfx::GpuMemoryBuffer::Format::DXT5: | 121 case gfx::GpuMemoryBuffer::Format::DXT5: |
| 122 case gfx::GpuMemoryBuffer::Format::ETC1: | 122 case gfx::GpuMemoryBuffer::Format::ETC1: |
| 123 case gfx::GpuMemoryBuffer::Format::R_8: |
| 123 case gfx::GpuMemoryBuffer::Format::RGBA_8888: | 124 case gfx::GpuMemoryBuffer::Format::RGBA_8888: |
| 124 case gfx::GpuMemoryBuffer::Format::RGBX_8888: | 125 case gfx::GpuMemoryBuffer::Format::RGBX_8888: |
| 125 case gfx::GpuMemoryBuffer::Format::BGRA_8888: | 126 case gfx::GpuMemoryBuffer::Format::BGRA_8888: |
| 126 return 1; | 127 return 1; |
| 127 default: | 128 default: |
| 128 NOTREACHED(); | 129 NOTREACHED(); |
| 129 return 0; | 130 return 0; |
| 130 } | 131 } |
| 131 } | 132 } |
| 132 | 133 |
| 133 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 134 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
| 134 return format_; | 135 return format_; |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool GpuMemoryBufferImpl::IsMapped() const { | 138 bool GpuMemoryBufferImpl::IsMapped() const { |
| 138 return mapped_; | 139 return mapped_; |
| 139 } | 140 } |
| 140 | 141 |
| 141 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 142 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
| 142 return reinterpret_cast<ClientBuffer>(this); | 143 return reinterpret_cast<ClientBuffer>(this); |
| 143 } | 144 } |
| 144 | 145 |
| 145 } // namespace content | 146 } // namespace content |
| OLD | NEW |