OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/gpu_memory_buffer_factory_io_surface.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | |
12 #include "content/common/mac/io_surface_manager.h" | 13 #include "content/common/mac/io_surface_manager.h" |
14 #include "ui/gfx/buffer_format_util.h" | |
13 #include "ui/gl/gl_image_io_surface.h" | 15 #include "ui/gl/gl_image_io_surface.h" |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 namespace { | 18 namespace { |
17 | 19 |
18 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 20 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
19 const CFStringRef key, | 21 const CFStringRef key, |
20 int32 value) { | 22 int32 value) { |
21 base::ScopedCFTypeRef<CFNumberRef> number( | 23 base::ScopedCFTypeRef<CFNumberRef> number( |
22 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 24 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
23 CFDictionaryAddValue(dictionary, key, number.get()); | 25 CFDictionaryAddValue(dictionary, key, number.get()); |
24 } | 26 } |
25 | 27 |
26 int32 BytesPerPixel(gfx::BufferFormat format) { | 28 int32 BytesPerElement(gfx::BufferFormat format, size_t plane) { |
reveman
2015/08/11 19:10:10
nit: s/size_t/int/
Andre
2015/08/11 19:46:22
Done.
| |
27 switch (format) { | 29 switch (format) { |
28 case gfx::BufferFormat::R_8: | 30 case gfx::BufferFormat::R_8: |
29 return 1; | 31 return 1; |
reveman
2015/08/11 19:10:10
nit: DCHECK_EQ(plane, 0)
Andre
2015/08/11 19:46:21
Done.
| |
30 case gfx::BufferFormat::BGRA_8888: | 32 case gfx::BufferFormat::BGRA_8888: |
31 return 4; | 33 return 4; |
reveman
2015/08/11 19:10:10
nit: DCHECK_EQ(plane, 0)
Andre
2015/08/11 19:46:21
Done.
| |
34 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
35 DCHECK_LT(plane, 2u); | |
36 return plane == 0 ? 1 : 2; | |
reveman
2015/08/11 19:10:10
nit: for consistency with ::SubsamplingFactor:
st
Andre
2015/08/11 19:46:21
Done.
| |
32 case gfx::BufferFormat::ATC: | 37 case gfx::BufferFormat::ATC: |
33 case gfx::BufferFormat::ATCIA: | 38 case gfx::BufferFormat::ATCIA: |
34 case gfx::BufferFormat::DXT1: | 39 case gfx::BufferFormat::DXT1: |
35 case gfx::BufferFormat::DXT5: | 40 case gfx::BufferFormat::DXT5: |
36 case gfx::BufferFormat::ETC1: | 41 case gfx::BufferFormat::ETC1: |
37 case gfx::BufferFormat::RGBA_4444: | 42 case gfx::BufferFormat::RGBA_4444: |
38 case gfx::BufferFormat::RGBA_8888: | 43 case gfx::BufferFormat::RGBA_8888: |
39 case gfx::BufferFormat::RGBX_8888: | 44 case gfx::BufferFormat::RGBX_8888: |
40 case gfx::BufferFormat::YUV_420: | 45 case gfx::BufferFormat::YUV_420: |
41 NOTREACHED(); | 46 NOTREACHED(); |
42 return 0; | 47 return 0; |
43 } | 48 } |
44 | 49 |
45 NOTREACHED(); | 50 NOTREACHED(); |
46 return 0; | 51 return 0; |
47 } | 52 } |
48 | 53 |
49 int32 PixelFormat(gfx::BufferFormat format) { | 54 int32 PixelFormat(gfx::BufferFormat format) { |
50 switch (format) { | 55 switch (format) { |
51 case gfx::BufferFormat::R_8: | 56 case gfx::BufferFormat::R_8: |
52 return 'L008'; | 57 return 'L008'; |
53 case gfx::BufferFormat::BGRA_8888: | 58 case gfx::BufferFormat::BGRA_8888: |
54 return 'BGRA'; | 59 return 'BGRA'; |
60 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
61 return '420v'; | |
55 case gfx::BufferFormat::ATC: | 62 case gfx::BufferFormat::ATC: |
56 case gfx::BufferFormat::ATCIA: | 63 case gfx::BufferFormat::ATCIA: |
57 case gfx::BufferFormat::DXT1: | 64 case gfx::BufferFormat::DXT1: |
58 case gfx::BufferFormat::DXT5: | 65 case gfx::BufferFormat::DXT5: |
59 case gfx::BufferFormat::ETC1: | 66 case gfx::BufferFormat::ETC1: |
60 case gfx::BufferFormat::RGBA_4444: | 67 case gfx::BufferFormat::RGBA_4444: |
61 case gfx::BufferFormat::RGBA_8888: | 68 case gfx::BufferFormat::RGBA_8888: |
62 case gfx::BufferFormat::RGBX_8888: | 69 case gfx::BufferFormat::RGBX_8888: |
63 case gfx::BufferFormat::YUV_420: | 70 case gfx::BufferFormat::YUV_420: |
64 NOTREACHED(); | 71 NOTREACHED(); |
65 return 0; | 72 return 0; |
66 } | 73 } |
67 | 74 |
68 NOTREACHED(); | 75 NOTREACHED(); |
69 return 0; | 76 return 0; |
70 } | 77 } |
71 | 78 |
72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 79 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
73 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 80 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
74 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, | 81 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
75 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, | 82 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, | 83 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
77 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; | 84 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}, |
85 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP}, | |
86 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP}, | |
87 }; | |
78 | 88 |
79 } // namespace | 89 } // namespace |
80 | 90 |
81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 91 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
82 } | 92 } |
83 | 93 |
84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 94 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
85 } | 95 } |
86 | 96 |
87 // static | 97 // static |
(...skipping 16 matching lines...) Expand all Loading... | |
104 } | 114 } |
105 | 115 |
106 gfx::GpuMemoryBufferHandle | 116 gfx::GpuMemoryBufferHandle |
107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 117 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
108 gfx::GpuMemoryBufferId id, | 118 gfx::GpuMemoryBufferId id, |
109 const gfx::Size& size, | 119 const gfx::Size& size, |
110 gfx::BufferFormat format, | 120 gfx::BufferFormat format, |
111 gfx::BufferUsage usage, | 121 gfx::BufferUsage usage, |
112 int client_id, | 122 int client_id, |
113 gfx::PluginWindowHandle surface_handle) { | 123 gfx::PluginWindowHandle surface_handle) { |
114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 124 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 125 DCHECK_GT(num_planes, 0u); |
reveman
2015/08/11 19:10:10
nit: not sure this DCHECK is necessary. NumberOfPl
Andre
2015/08/11 19:46:21
Removed.
| |
116 0, | 126 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
117 &kCFTypeDictionaryKeyCallBacks, | 127 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
118 &kCFTypeDictionaryValueCallBacks)); | 128 |
129 for (size_t plane = 0; plane < num_planes; ++plane) { | |
130 size_t factor = GpuMemoryBufferImpl::SubsamplingFactor(format, plane); | |
131 | |
132 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( | |
133 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
134 &kCFTypeDictionaryKeyCallBacks, | |
135 &kCFTypeDictionaryValueCallBacks)); | |
136 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor); | |
137 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor); | |
138 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, | |
139 BytesPerElement(format, plane)); | |
140 | |
141 CFArrayAppendValue(planes, plane_info); | |
142 } | |
143 | |
144 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( | |
145 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
146 &kCFTypeDictionaryKeyCallBacks, | |
147 &kCFTypeDictionaryValueCallBacks)); | |
119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 148 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 149 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | |
122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 150 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
151 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); | |
123 | 152 |
124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 153 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
125 if (!io_surface) | 154 if (!io_surface) |
126 return gfx::GpuMemoryBufferHandle(); | 155 return gfx::GpuMemoryBufferHandle(); |
127 | 156 |
128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | 157 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
129 io_surface)) { | 158 io_surface)) { |
130 return gfx::GpuMemoryBufferHandle(); | 159 return gfx::GpuMemoryBufferHandle(); |
131 } | 160 } |
132 | 161 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 208 |
180 scoped_refptr<gfx::GLImageIOSurface> image( | 209 scoped_refptr<gfx::GLImageIOSurface> image( |
181 new gfx::GLImageIOSurface(size, internalformat)); | 210 new gfx::GLImageIOSurface(size, internalformat)); |
182 if (!image->Initialize(it->second.get(), format)) | 211 if (!image->Initialize(it->second.get(), format)) |
183 return scoped_refptr<gfx::GLImage>(); | 212 return scoped_refptr<gfx::GLImage>(); |
184 | 213 |
185 return image; | 214 return image; |
186 } | 215 } |
187 | 216 |
188 } // namespace content | 217 } // namespace content |
OLD | NEW |