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 "ui/gl/gl_image_io_surface.h" | 5 #include "ui/gl/gl_image_io_surface.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/trace_event/memory_allocator_dump.h" | 11 #include "base/trace_event/memory_allocator_dump.h" |
12 #include "base/trace_event/memory_dump_manager.h" | 12 #include "base/trace_event/memory_dump_manager.h" |
13 #include "base/trace_event/process_memory_dump.h" | 13 #include "base/trace_event/process_memory_dump.h" |
14 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
15 #include "ui/gl/gl_context.h" | 15 #include "ui/gl/gl_context.h" |
16 | 16 |
17 // Note that this must be included after gl_bindings.h to avoid conflicts. | 17 // Note that this must be included after gl_bindings.h to avoid conflicts. |
18 #include <OpenGL/CGLIOSurface.h> | 18 #include <OpenGL/CGLIOSurface.h> |
19 #include <Quartz/Quartz.h> | 19 #include <Quartz/Quartz.h> |
20 | 20 |
21 namespace gfx { | 21 using gfx::BufferFormat; |
| 22 |
| 23 namespace gl { |
22 namespace { | 24 namespace { |
23 | 25 |
24 using WidgetToLayerMap = std::map<AcceleratedWidget, CALayer*>; | 26 using WidgetToLayerMap = std::map<gfx::AcceleratedWidget, CALayer*>; |
25 base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map; | 27 base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map; |
26 | 28 |
27 bool ValidInternalFormat(unsigned internalformat) { | 29 bool ValidInternalFormat(unsigned internalformat) { |
28 switch (internalformat) { | 30 switch (internalformat) { |
29 case GL_R8: | 31 case GL_R8: |
30 case GL_BGRA_EXT: | 32 case GL_BGRA_EXT: |
31 case GL_RGB: | 33 case GL_RGB: |
32 case GL_RGB_YCBCR_422_CHROMIUM: | 34 case GL_RGB_YCBCR_422_CHROMIUM: |
33 return true; | 35 return true; |
34 default: | 36 default: |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 NOTREACHED(); | 140 NOTREACHED(); |
139 return 0; | 141 return 0; |
140 } | 142 } |
141 | 143 |
142 NOTREACHED(); | 144 NOTREACHED(); |
143 return 0; | 145 return 0; |
144 } | 146 } |
145 | 147 |
146 } // namespace | 148 } // namespace |
147 | 149 |
148 GLImageIOSurface::GLImageIOSurface(const Size& size, unsigned internalformat) | 150 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, |
| 151 unsigned internalformat) |
149 : size_(size), | 152 : size_(size), |
150 internalformat_(internalformat), | 153 internalformat_(internalformat), |
151 format_(BufferFormat::RGBA_8888) {} | 154 format_(BufferFormat::RGBA_8888) {} |
152 | 155 |
153 GLImageIOSurface::~GLImageIOSurface() { | 156 GLImageIOSurface::~GLImageIOSurface() { |
154 DCHECK(thread_checker_.CalledOnValidThread()); | 157 DCHECK(thread_checker_.CalledOnValidThread()); |
155 DCHECK(!io_surface_); | 158 DCHECK(!io_surface_); |
156 } | 159 } |
157 | 160 |
158 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, | 161 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, |
159 GenericSharedMemoryId io_surface_id, | 162 gfx::GenericSharedMemoryId io_surface_id, |
160 BufferFormat format) { | 163 BufferFormat format) { |
161 DCHECK(thread_checker_.CalledOnValidThread()); | 164 DCHECK(thread_checker_.CalledOnValidThread()); |
162 DCHECK(!io_surface_); | 165 DCHECK(!io_surface_); |
163 | 166 |
164 if (!ValidInternalFormat(internalformat_)) { | 167 if (!ValidInternalFormat(internalformat_)) { |
165 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 168 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
166 return false; | 169 return false; |
167 } | 170 } |
168 | 171 |
169 if (!ValidFormat(format)) { | 172 if (!ValidFormat(format)) { |
170 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 173 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
171 return false; | 174 return false; |
172 } | 175 } |
173 | 176 |
174 format_ = format; | 177 format_ = format; |
175 io_surface_.reset(io_surface, base::scoped_policy::RETAIN); | 178 io_surface_.reset(io_surface, base::scoped_policy::RETAIN); |
176 io_surface_id_ = io_surface_id; | 179 io_surface_id_ = io_surface_id; |
177 return true; | 180 return true; |
178 } | 181 } |
179 | 182 |
180 void GLImageIOSurface::Destroy(bool have_context) { | 183 void GLImageIOSurface::Destroy(bool have_context) { |
181 DCHECK(thread_checker_.CalledOnValidThread()); | 184 DCHECK(thread_checker_.CalledOnValidThread()); |
182 io_surface_.reset(); | 185 io_surface_.reset(); |
183 } | 186 } |
184 | 187 |
185 Size GLImageIOSurface::GetSize() { | 188 gfx::Size GLImageIOSurface::GetSize() { |
186 return size_; | 189 return size_; |
187 } | 190 } |
188 | 191 |
189 unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; } | 192 unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; } |
190 | 193 |
191 bool GLImageIOSurface::BindTexImage(unsigned target) { | 194 bool GLImageIOSurface::BindTexImage(unsigned target) { |
192 DCHECK(thread_checker_.CalledOnValidThread()); | 195 DCHECK(thread_checker_.CalledOnValidThread()); |
193 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 196 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
194 // This might be supported in the future. For now, perform strict | 197 // This might be supported in the future. For now, perform strict |
195 // validation so we know what's going on. | 198 // validation so we know what's going on. |
196 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; | 199 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; |
197 return false; | 200 return false; |
198 } | 201 } |
199 | 202 |
200 CGLContextObj cgl_context = | 203 CGLContextObj cgl_context = |
201 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); | 204 static_cast<CGLContextObj>(gfx::GLContext::GetCurrent()->GetHandle()); |
202 | 205 |
203 DCHECK(io_surface_); | 206 DCHECK(io_surface_); |
204 CGLError cgl_error = | 207 CGLError cgl_error = |
205 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), | 208 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), |
206 size_.width(), size_.height(), DataFormat(format_), | 209 size_.width(), size_.height(), DataFormat(format_), |
207 DataType(format_), io_surface_.get(), 0); | 210 DataType(format_), io_surface_.get(), 0); |
208 if (cgl_error != kCGLNoError) { | 211 if (cgl_error != kCGLNoError) { |
209 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; | 212 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; |
210 return false; | 213 return false; |
211 } | 214 } |
212 | 215 |
213 return true; | 216 return true; |
214 } | 217 } |
215 | 218 |
216 bool GLImageIOSurface::CopyTexImage(unsigned target) { | 219 bool GLImageIOSurface::CopyTexImage(unsigned target) { |
217 return false; | 220 return false; |
218 } | 221 } |
219 | 222 |
220 bool GLImageIOSurface::CopyTexSubImage(unsigned target, | 223 bool GLImageIOSurface::CopyTexSubImage(unsigned target, |
221 const Point& offset, | 224 const gfx::Point& offset, |
222 const Rect& rect) { | 225 const gfx::Rect& rect) { |
223 return false; | 226 return false; |
224 } | 227 } |
225 | 228 |
226 bool GLImageIOSurface::ScheduleOverlayPlane(AcceleratedWidget widget, | 229 bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
227 int z_order, | 230 int z_order, |
228 OverlayTransform transform, | 231 gfx::OverlayTransform transform, |
229 const Rect& bounds_rect, | 232 const gfx::Rect& bounds_rect, |
230 const RectF& crop_rect) { | 233 const gfx::RectF& crop_rect) { |
231 NOTREACHED(); | 234 NOTREACHED(); |
232 return false; | 235 return false; |
233 } | 236 } |
234 | 237 |
235 void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 238 void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
236 uint64_t process_tracing_id, | 239 uint64_t process_tracing_id, |
237 const std::string& dump_name) { | 240 const std::string& dump_name) { |
238 // IOSurfaceGetAllocSize will return 0 if io_surface_ is invalid. In this case | 241 // IOSurfaceGetAllocSize will return 0 if io_surface_ is invalid. In this case |
239 // we log 0 for consistency with other GLImage memory dump functions. | 242 // we log 0 for consistency with other GLImage memory dump functions. |
240 size_t size_bytes = IOSurfaceGetAllocSize(io_surface_); | 243 size_t size_bytes = IOSurfaceGetAllocSize(io_surface_); |
241 | 244 |
242 base::trace_event::MemoryAllocatorDump* dump = | 245 base::trace_event::MemoryAllocatorDump* dump = |
243 pmd->CreateAllocatorDump(dump_name); | 246 pmd->CreateAllocatorDump(dump_name); |
244 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 247 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
245 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 248 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
246 static_cast<uint64_t>(size_bytes)); | 249 static_cast<uint64_t>(size_bytes)); |
247 | 250 |
248 auto guid = | 251 auto guid = |
249 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); | 252 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); |
250 pmd->CreateSharedGlobalAllocatorDump(guid); | 253 pmd->CreateSharedGlobalAllocatorDump(guid); |
251 pmd->AddOwnershipEdge(dump->guid(), guid); | 254 pmd->AddOwnershipEdge(dump->guid(), guid); |
252 } | 255 } |
253 | 256 |
254 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { | 257 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { |
255 return io_surface_; | 258 return io_surface_; |
256 } | 259 } |
257 | 260 |
258 // static | 261 // static |
259 void GLImageIOSurface::SetLayerForWidget(AcceleratedWidget widget, | 262 void GLImageIOSurface::SetLayerForWidget(gfx::AcceleratedWidget widget, |
260 CALayer* layer) { | 263 CALayer* layer) { |
261 if (layer) | 264 if (layer) |
262 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); | 265 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); |
263 else | 266 else |
264 g_widget_to_layer_map.Pointer()->erase(widget); | 267 g_widget_to_layer_map.Pointer()->erase(widget); |
265 } | 268 } |
266 | 269 |
267 } // namespace gfx | 270 } // namespace gfx |
OLD | NEW |