OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" | |
6 | |
7 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | |
8 #include "ui/gl/gl_image_io_surface.h" | |
9 | |
10 namespace content { | |
11 namespace { | |
12 | |
13 void AddBooleanValue(CFMutableDictionaryRef dictionary, | |
14 const CFStringRef key, | |
15 bool value) { | |
16 CFDictionaryAddValue( | |
piman
2014/09/25 20:46:27
nit: do we need an include for this (IWYU) ?
reveman
2014/09/25 21:13:23
Done.
| |
17 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); | |
18 } | |
19 | |
20 void AddIntegerValue(CFMutableDictionaryRef dictionary, | |
21 const CFStringRef key, | |
22 int32 value) { | |
23 base::ScopedCFTypeRef<CFNumberRef> number( | |
24 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | |
25 CFDictionaryAddValue(dictionary, key, number.get()); | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | |
31 } | |
32 | |
33 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | |
34 } | |
35 | |
36 gfx::GpuMemoryBufferHandle | |
37 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | |
38 const gfx::GpuMemoryBufferId& id, | |
39 const gfx::Size& size, | |
40 unsigned internalformat) { | |
41 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | |
piman
2014/09/25 20:46:27
nit: and this?
reveman
2014/09/25 21:13:23
Done.
| |
42 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | |
43 0, | |
44 &kCFTypeDictionaryKeyCallBacks, | |
45 &kCFTypeDictionaryValueCallBacks)); | |
46 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | |
47 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | |
48 AddIntegerValue(properties, | |
49 kIOSurfaceBytesPerElement, | |
50 GpuMemoryBufferImpl::BytesPerPixel(internalformat)); | |
51 AddIntegerValue(properties, | |
52 kIOSurfacePixelFormat, | |
53 GpuMemoryBufferImplIOSurface::PixelFormat(internalformat)); | |
54 // TODO(reveman): Remove this when using a mach_port_t to transfer | |
55 // IOSurface to browser and renderer process. crbug.com/323304 | |
56 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | |
57 | |
58 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | |
59 if (!io_surface) | |
60 return gfx::GpuMemoryBufferHandle(); | |
61 | |
62 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | |
63 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | |
64 io_surfaces_[key] = io_surface; | |
65 | |
66 gfx::GpuMemoryBufferHandle handle; | |
67 handle.type = gfx::IO_SURFACE_BUFFER; | |
68 handle.global_id = id; | |
69 handle.io_surface_id = IOSurfaceGetID(io_surface); | |
70 return handle; | |
71 } | |
72 | |
73 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | |
74 const gfx::GpuMemoryBufferId& id) { | |
75 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | |
76 IOSurfaceMap::iterator it = io_surfaces_.find(key); | |
77 if (it != io_surfaces_.end()) | |
78 io_surfaces_.erase(it); | |
79 } | |
80 | |
81 scoped_refptr<gfx::GLImage> | |
82 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | |
83 const gfx::GpuMemoryBufferId& id, | |
84 const gfx::Size& size, | |
85 unsigned internalformat) { | |
86 IOSurfaceMapKey key(id.primary_id, id.secondary_id); | |
87 IOSurfaceMap::iterator it = io_surfaces_.find(key); | |
88 if (it == io_surfaces_.end()) | |
89 return scoped_refptr<gfx::GLImage>(); | |
90 | |
91 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); | |
92 if (!image->Initialize(it->second.get())) | |
93 return scoped_refptr<gfx::GLImage>(); | |
94 | |
95 return image; | |
96 } | |
97 | |
98 } // namespace content | |
OLD | NEW |