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 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, | 26 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, |
27 const gfx::Size& size, | 27 const gfx::Size& size, |
28 Format format, | 28 Format format, |
29 const DestructionCallback& callback) | 29 const DestructionCallback& callback) |
30 : id_(id), | 30 : id_(id), |
31 size_(size), | 31 size_(size), |
32 format_(format), | 32 format_(format), |
33 num_planes_(NumberOfPlanesForGpuMemoryBufferFormat(format)), | |
33 callback_(callback), | 34 callback_(callback), |
34 mapped_(false), | 35 mapped_(false), |
35 destruction_sync_point_(0) { | 36 destruction_sync_point_(0) { |
36 } | 37 } |
37 | 38 |
38 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { | 39 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { |
39 callback_.Run(destruction_sync_point_); | 40 callback_.Run(destruction_sync_point_); |
40 } | 41 } |
41 | 42 |
42 // static | 43 // static |
(...skipping 30 matching lines...) Expand all Loading... | |
73 // static | 74 // static |
74 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | 75 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( |
75 ClientBuffer buffer) { | 76 ClientBuffer buffer) { |
76 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | 77 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); |
77 } | 78 } |
78 | 79 |
79 // static | 80 // static |
80 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, | 81 bool GpuMemoryBufferImpl::StrideInBytes(size_t width, |
81 Format format, | 82 Format format, |
82 size_t* stride_in_bytes) { | 83 size_t* stride_in_bytes) { |
83 base::CheckedNumeric<size_t> s = width; | 84 base::CheckedNumeric<uint32> s = width; |
reveman
2015/03/23 22:24:01
Is this change needed?
emircan
2015/03/24 16:52:27
I was trying to change the function signature to w
| |
84 switch (format) { | 85 switch (format) { |
85 case ATCIA: | 86 case ATCIA: |
86 case DXT5: | 87 case DXT5: |
87 *stride_in_bytes = width; | 88 *stride_in_bytes = width; |
88 return true; | 89 return true; |
89 case ATC: | 90 case ATC: |
90 case DXT1: | 91 case DXT1: |
91 case ETC1: | 92 case ETC1: |
92 DCHECK_EQ(width % 2, 0U); | 93 DCHECK_EQ(width % 2, 0U); |
93 s /= 2; | 94 s /= 2; |
(...skipping 10 matching lines...) Expand all Loading... | |
104 return false; | 105 return false; |
105 | 106 |
106 *stride_in_bytes = s.ValueOrDie(); | 107 *stride_in_bytes = s.ValueOrDie(); |
107 return true; | 108 return true; |
108 } | 109 } |
109 | 110 |
110 NOTREACHED(); | 111 NOTREACHED(); |
111 return false; | 112 return false; |
112 } | 113 } |
113 | 114 |
115 size_t GpuMemoryBufferImpl::GetNumberOfPlanes() const { | |
116 return num_planes_; | |
117 } | |
118 | |
114 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { | 119 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { |
115 return format_; | 120 return format_; |
116 } | 121 } |
117 | 122 |
118 bool GpuMemoryBufferImpl::IsMapped() const { | 123 bool GpuMemoryBufferImpl::IsMapped() const { |
119 return mapped_; | 124 return mapped_; |
120 } | 125 } |
121 | 126 |
122 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | 127 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { |
123 return reinterpret_cast<ClientBuffer>(this); | 128 return reinterpret_cast<ClientBuffer>(this); |
124 } | 129 } |
125 | 130 |
131 // static | |
132 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( | |
133 gfx::GpuMemoryBuffer::Format format) { | |
134 switch (format) { | |
135 case gfx::GpuMemoryBuffer::Format::ATC: | |
136 case gfx::GpuMemoryBuffer::Format::ATCIA: | |
137 case gfx::GpuMemoryBuffer::Format::DXT1: | |
138 case gfx::GpuMemoryBuffer::Format::DXT5: | |
139 case gfx::GpuMemoryBuffer::Format::ETC1: | |
140 case gfx::GpuMemoryBuffer::Format::RGBA_8888: | |
141 case gfx::GpuMemoryBuffer::Format::RGBX_8888: | |
142 case gfx::GpuMemoryBuffer::Format::BGRA_8888: | |
143 return 1; | |
144 default: | |
145 NOTREACHED(); | |
146 return 0; | |
147 } | |
148 } | |
149 | |
126 } // namespace content | 150 } // namespace content |
OLD | NEW |