Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl.cc

Issue 1062853002: Add gfx::GpuMemoryBuffer::YUV_420 and GpuMemoryBufferImplSharedMemory support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 } 71 }
72 72
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,
81 Format format,
82 size_t* stride_in_bytes) {
83 base::CheckedNumeric<size_t> s = width;
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);
93 s /= 2;
94 if (!s.IsValid())
95 return false;
96
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 }
109
110 NOTREACHED();
111 return false;
112 }
113
114 // static
115 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat( 80 size_t GpuMemoryBufferImpl::NumberOfPlanesForGpuMemoryBufferFormat(
116 gfx::GpuMemoryBuffer::Format format) { 81 gfx::GpuMemoryBuffer::Format format) {
117 switch (format) { 82 switch (format) {
118 case gfx::GpuMemoryBuffer::Format::ATC: 83 case gfx::GpuMemoryBuffer::Format::ATC:
119 case gfx::GpuMemoryBuffer::Format::ATCIA: 84 case gfx::GpuMemoryBuffer::Format::ATCIA:
120 case gfx::GpuMemoryBuffer::Format::DXT1: 85 case gfx::GpuMemoryBuffer::Format::DXT1:
121 case gfx::GpuMemoryBuffer::Format::DXT5: 86 case gfx::GpuMemoryBuffer::Format::DXT5:
122 case gfx::GpuMemoryBuffer::Format::ETC1: 87 case gfx::GpuMemoryBuffer::Format::ETC1:
123 case gfx::GpuMemoryBuffer::Format::RGBA_8888: 88 case gfx::GpuMemoryBuffer::Format::RGBA_8888:
124 case gfx::GpuMemoryBuffer::Format::RGBX_8888: 89 case gfx::GpuMemoryBuffer::Format::RGBX_8888:
125 case gfx::GpuMemoryBuffer::Format::BGRA_8888: 90 case gfx::GpuMemoryBuffer::Format::BGRA_8888:
126 return 1; 91 return 1;
127 default: 92 case gfx::GpuMemoryBuffer::Format::YUV_420:
128 NOTREACHED(); 93 return 3;
129 return 0;
130 } 94 }
95 NOTREACHED();
96 return 0;
97 }
98
99 // static
100 bool GpuMemoryBufferImpl::StrideInBytes(size_t width,
101 Format format,
102 int plane,
103 size_t* stride_in_bytes) {
104 switch (format) {
105 case ATCIA:
106 case DXT5:
107 DCHECK_EQ(plane, 0);
108 *stride_in_bytes = width;
109 return true;
110 case ATC:
111 case DXT1:
112 case ETC1:
113 DCHECK_EQ(plane, 0);
114 DCHECK_EQ(width % 2, 0U);
115 *stride_in_bytes = width / 2;
116 return true;
117 case RGBA_8888:
118 case RGBX_8888:
119 case BGRA_8888: {
120 base::CheckedNumeric<size_t> s = width;
121 DCHECK_EQ(plane, 0);
122 s *= 4;
123 if (!s.IsValid())
124 return false;
125 *stride_in_bytes = s.ValueOrDie();
126 return true;
127 }
128 case YUV_420: {
129 DCHECK_EQ(width % 2, 0u);
130 *stride_in_bytes = width / SubsamplingFactor(format, plane);
131 return true;
132 }
133 }
134 NOTREACHED();
135 return false;
136 }
137
138 // static
139 size_t GpuMemoryBufferImpl::SubsamplingFactor(
140 gfx::GpuMemoryBuffer::Format format,
141 int plane) {
142 switch (format) {
143 case gfx::GpuMemoryBuffer::ATC:
144 case gfx::GpuMemoryBuffer::ATCIA:
145 case gfx::GpuMemoryBuffer::DXT1:
146 case gfx::GpuMemoryBuffer::DXT5:
147 case gfx::GpuMemoryBuffer::ETC1:
148 case gfx::GpuMemoryBuffer::RGBA_8888:
149 case gfx::GpuMemoryBuffer::RGBX_8888:
150 case gfx::GpuMemoryBuffer::BGRA_8888:
151 return 1;
152 case gfx::GpuMemoryBuffer::YUV_420: {
153 static size_t factor[] = {1, 2, 2};
154 DCHECK_LT(static_cast<size_t>(plane), arraysize(factor));
155 return factor[plane];
156 }
157 }
158 NOTREACHED();
159 return 0;
160 }
161
162 // static
163 bool GpuMemoryBufferImpl::TotalBufferSizeInBytes(
164 const gfx::Size& size,
165 gfx::GpuMemoryBuffer::Format format,
166 size_t* total_size_in_bytes) {
167 base::CheckedNumeric<size_t> size_in_bytes = 0u;
168 for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format); ++i) {
169 size_t stride_in_bytes = 0;
170 if (!StrideInBytes(size.width(), format, i, &stride_in_bytes))
171 return false;
172 size_in_bytes +=
173 stride_in_bytes * (size.height() / SubsamplingFactor(format, i));
reveman 2015/04/07 19:03:25 This multiplication can overflow. You need another
emircan 2015/04/07 20:08:12 Done.
174 if (!size_in_bytes.IsValid())
175 return false;
176 }
177 *total_size_in_bytes = size_in_bytes.ValueOrDie();
178 return true;
131 } 179 }
132 180
133 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const { 181 gfx::GpuMemoryBuffer::Format GpuMemoryBufferImpl::GetFormat() const {
134 return format_; 182 return format_;
135 } 183 }
136 184
137 bool GpuMemoryBufferImpl::IsMapped() const { 185 bool GpuMemoryBufferImpl::IsMapped() const {
138 return mapped_; 186 return mapped_;
139 } 187 }
140 188
141 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { 189 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() {
142 return reinterpret_cast<ClientBuffer>(this); 190 return reinterpret_cast<ClientBuffer>(this);
143 } 191 }
144 192
145 } // namespace content 193 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698