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, int plane) { |
27 switch (format) { | 29 switch (format) { |
28 case gfx::BufferFormat::R_8: | 30 case gfx::BufferFormat::R_8: |
| 31 DCHECK_EQ(plane, 0); |
29 return 1; | 32 return 1; |
30 case gfx::BufferFormat::BGRA_8888: | 33 case gfx::BufferFormat::BGRA_8888: |
| 34 DCHECK_EQ(plane, 0); |
31 return 4; | 35 return 4; |
| 36 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 37 static int32 bytes_per_element[] = {1, 2}; |
| 38 DCHECK_LT(static_cast<size_t>(plane), arraysize(bytes_per_element)); |
| 39 return bytes_per_element[plane]; |
32 case gfx::BufferFormat::ATC: | 40 case gfx::BufferFormat::ATC: |
33 case gfx::BufferFormat::ATCIA: | 41 case gfx::BufferFormat::ATCIA: |
34 case gfx::BufferFormat::DXT1: | 42 case gfx::BufferFormat::DXT1: |
35 case gfx::BufferFormat::DXT5: | 43 case gfx::BufferFormat::DXT5: |
36 case gfx::BufferFormat::ETC1: | 44 case gfx::BufferFormat::ETC1: |
37 case gfx::BufferFormat::RGBA_4444: | 45 case gfx::BufferFormat::RGBA_4444: |
38 case gfx::BufferFormat::RGBA_8888: | 46 case gfx::BufferFormat::RGBA_8888: |
39 case gfx::BufferFormat::RGBX_8888: | 47 case gfx::BufferFormat::RGBX_8888: |
40 case gfx::BufferFormat::YUV_420: | 48 case gfx::BufferFormat::YUV_420: |
41 NOTREACHED(); | 49 NOTREACHED(); |
42 return 0; | 50 return 0; |
43 } | 51 } |
44 | 52 |
45 NOTREACHED(); | 53 NOTREACHED(); |
46 return 0; | 54 return 0; |
47 } | 55 } |
48 | 56 |
49 int32 PixelFormat(gfx::BufferFormat format) { | 57 int32 PixelFormat(gfx::BufferFormat format) { |
50 switch (format) { | 58 switch (format) { |
51 case gfx::BufferFormat::R_8: | 59 case gfx::BufferFormat::R_8: |
52 return 'L008'; | 60 return 'L008'; |
53 case gfx::BufferFormat::BGRA_8888: | 61 case gfx::BufferFormat::BGRA_8888: |
54 return 'BGRA'; | 62 return 'BGRA'; |
| 63 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 64 return '420v'; |
55 case gfx::BufferFormat::ATC: | 65 case gfx::BufferFormat::ATC: |
56 case gfx::BufferFormat::ATCIA: | 66 case gfx::BufferFormat::ATCIA: |
57 case gfx::BufferFormat::DXT1: | 67 case gfx::BufferFormat::DXT1: |
58 case gfx::BufferFormat::DXT5: | 68 case gfx::BufferFormat::DXT5: |
59 case gfx::BufferFormat::ETC1: | 69 case gfx::BufferFormat::ETC1: |
60 case gfx::BufferFormat::RGBA_4444: | 70 case gfx::BufferFormat::RGBA_4444: |
61 case gfx::BufferFormat::RGBA_8888: | 71 case gfx::BufferFormat::RGBA_8888: |
62 case gfx::BufferFormat::RGBX_8888: | 72 case gfx::BufferFormat::RGBX_8888: |
63 case gfx::BufferFormat::YUV_420: | 73 case gfx::BufferFormat::YUV_420: |
64 NOTREACHED(); | 74 NOTREACHED(); |
65 return 0; | 75 return 0; |
66 } | 76 } |
67 | 77 |
68 NOTREACHED(); | 78 NOTREACHED(); |
69 return 0; | 79 return 0; |
70 } | 80 } |
71 | 81 |
72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 82 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
73 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 83 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
74 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, | 84 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
75 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, | 85 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, | 86 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
77 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; | 87 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}, |
| 88 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP}, |
| 89 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP}, |
| 90 }; |
78 | 91 |
79 } // namespace | 92 } // namespace |
80 | 93 |
81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 94 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
82 } | 95 } |
83 | 96 |
84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 97 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
85 } | 98 } |
86 | 99 |
87 // static | 100 // static |
(...skipping 16 matching lines...) Expand all Loading... |
104 } | 117 } |
105 | 118 |
106 gfx::GpuMemoryBufferHandle | 119 gfx::GpuMemoryBufferHandle |
107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 120 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
108 gfx::GpuMemoryBufferId id, | 121 gfx::GpuMemoryBufferId id, |
109 const gfx::Size& size, | 122 const gfx::Size& size, |
110 gfx::BufferFormat format, | 123 gfx::BufferFormat format, |
111 gfx::BufferUsage usage, | 124 gfx::BufferUsage usage, |
112 int client_id, | 125 int client_id, |
113 gfx::PluginWindowHandle surface_handle) { | 126 gfx::PluginWindowHandle surface_handle) { |
114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 127 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 128 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
116 0, | 129 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
117 &kCFTypeDictionaryKeyCallBacks, | 130 |
118 &kCFTypeDictionaryValueCallBacks)); | 131 for (size_t plane = 0; plane < num_planes; ++plane) { |
| 132 size_t factor = GpuMemoryBufferImpl::SubsamplingFactor(format, plane); |
| 133 |
| 134 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( |
| 135 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 136 &kCFTypeDictionaryKeyCallBacks, |
| 137 &kCFTypeDictionaryValueCallBacks)); |
| 138 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor); |
| 139 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor); |
| 140 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, |
| 141 BytesPerElement(format, plane)); |
| 142 |
| 143 CFArrayAppendValue(planes, plane_info); |
| 144 } |
| 145 |
| 146 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| 147 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 148 &kCFTypeDictionaryKeyCallBacks, |
| 149 &kCFTypeDictionaryValueCallBacks)); |
119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 150 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 151 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | |
122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 152 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 153 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
123 | 154 |
124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 155 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
125 if (!io_surface) | 156 if (!io_surface) |
126 return gfx::GpuMemoryBufferHandle(); | 157 return gfx::GpuMemoryBufferHandle(); |
127 | 158 |
128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | 159 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
129 io_surface)) { | 160 io_surface)) { |
130 return gfx::GpuMemoryBufferHandle(); | 161 return gfx::GpuMemoryBufferHandle(); |
131 } | 162 } |
132 | 163 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 210 |
180 scoped_refptr<gfx::GLImageIOSurface> image( | 211 scoped_refptr<gfx::GLImageIOSurface> image( |
181 new gfx::GLImageIOSurface(size, internalformat)); | 212 new gfx::GLImageIOSurface(size, internalformat)); |
182 if (!image->Initialize(it->second.get(), format)) | 213 if (!image->Initialize(it->second.get(), format)) |
183 return scoped_refptr<gfx::GLImage>(); | 214 return scoped_refptr<gfx::GLImage>(); |
184 | 215 |
185 return image; | 216 return image; |
186 } | 217 } |
187 | 218 |
188 } // namespace content | 219 } // namespace content |
OLD | NEW |