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

Side by Side Diff: content/common/gpu/gpu_memory_buffer_factory_io_surface.cc

Issue 1282313002: Add YUV_420_BIPLANAR to gfx::BufferFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmb-planes
Patch Set: Enable it on Mac Created 5 years, 4 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 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/mac/io_surface_manager.h" 12 #include "content/common/mac/io_surface_manager.h"
13 #include "ui/gl/gl_image_io_surface.h" 13 #include "ui/gl/gl_image_io_surface.h"
14 14
15 namespace content { 15 namespace content {
16 namespace { 16 namespace {
17 17
18 void AddIntegerValue(CFMutableDictionaryRef dictionary, 18 void AddIntegerValue(CFMutableDictionaryRef dictionary,
19 const CFStringRef key, 19 const CFStringRef key,
20 int32 value) { 20 int32 value) {
21 base::ScopedCFTypeRef<CFNumberRef> number( 21 base::ScopedCFTypeRef<CFNumberRef> number(
22 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); 22 CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
23 CFDictionaryAddValue(dictionary, key, number.get()); 23 CFDictionaryAddValue(dictionary, key, number.get());
24 } 24 }
25 25
26 int32 BytesPerPixel(gfx::BufferFormat format) { 26 int32 BytesPerPixel(gfx::BufferFormat format) {
27 switch (format) { 27 switch (format) {
28 case gfx::BufferFormat::R_8: 28 case gfx::BufferFormat::R_8:
29 case gfx::BufferFormat::YUV_420_BIPLANAR:
29 return 1; 30 return 1;
30 case gfx::BufferFormat::BGRA_8888: 31 case gfx::BufferFormat::BGRA_8888:
31 return 4; 32 return 4;
32 case gfx::BufferFormat::ATC: 33 case gfx::BufferFormat::ATC:
33 case gfx::BufferFormat::ATCIA: 34 case gfx::BufferFormat::ATCIA:
34 case gfx::BufferFormat::DXT1: 35 case gfx::BufferFormat::DXT1:
35 case gfx::BufferFormat::DXT5: 36 case gfx::BufferFormat::DXT5:
36 case gfx::BufferFormat::ETC1: 37 case gfx::BufferFormat::ETC1:
37 case gfx::BufferFormat::RGBA_4444: 38 case gfx::BufferFormat::RGBA_4444:
38 case gfx::BufferFormat::RGBA_8888: 39 case gfx::BufferFormat::RGBA_8888:
39 case gfx::BufferFormat::RGBX_8888: 40 case gfx::BufferFormat::RGBX_8888:
40 case gfx::BufferFormat::YUV_420: 41 case gfx::BufferFormat::YUV_420:
41 NOTREACHED(); 42 NOTREACHED();
42 return 0; 43 return 0;
43 } 44 }
44 45
45 NOTREACHED(); 46 NOTREACHED();
46 return 0; 47 return 0;
47 } 48 }
48 49
49 int32 PixelFormat(gfx::BufferFormat format) { 50 int32 PixelFormat(gfx::BufferFormat format) {
50 switch (format) { 51 switch (format) {
51 case gfx::BufferFormat::R_8: 52 case gfx::BufferFormat::R_8:
52 return 'L008'; 53 return 'L008';
53 case gfx::BufferFormat::BGRA_8888: 54 case gfx::BufferFormat::BGRA_8888:
54 return 'BGRA'; 55 return 'BGRA';
56 case gfx::BufferFormat::YUV_420_BIPLANAR:
57 return '420v';
55 case gfx::BufferFormat::ATC: 58 case gfx::BufferFormat::ATC:
56 case gfx::BufferFormat::ATCIA: 59 case gfx::BufferFormat::ATCIA:
57 case gfx::BufferFormat::DXT1: 60 case gfx::BufferFormat::DXT1:
58 case gfx::BufferFormat::DXT5: 61 case gfx::BufferFormat::DXT5:
59 case gfx::BufferFormat::ETC1: 62 case gfx::BufferFormat::ETC1:
60 case gfx::BufferFormat::RGBA_4444: 63 case gfx::BufferFormat::RGBA_4444:
61 case gfx::BufferFormat::RGBA_8888: 64 case gfx::BufferFormat::RGBA_8888:
62 case gfx::BufferFormat::RGBX_8888: 65 case gfx::BufferFormat::RGBX_8888:
63 case gfx::BufferFormat::YUV_420: 66 case gfx::BufferFormat::YUV_420:
64 NOTREACHED(); 67 NOTREACHED();
65 return 0; 68 return 0;
66 } 69 }
67 70
68 NOTREACHED(); 71 NOTREACHED();
69 return 0; 72 return 0;
70 } 73 }
71 74
72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { 75 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = {
73 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, 76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT},
74 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, 77 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP},
75 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, 78 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP},
76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, 79 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP},
77 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; 80 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP},
81 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP},
82 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP},
83 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::SCANOUT},
reveman 2015/08/10 22:40:55 SCANOUT is supported by some other formats too, co
Andre 2015/08/11 03:50:46 Done, removed the SCANOUT usage from this patch. I
84 };
78 85
79 } // namespace 86 } // namespace
80 87
81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { 88 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
82 } 89 }
83 90
84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { 91 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() {
85 } 92 }
86 93
87 // static 94 // static
(...skipping 16 matching lines...) Expand all
104 } 111 }
105 112
106 gfx::GpuMemoryBufferHandle 113 gfx::GpuMemoryBufferHandle
107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( 114 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
108 gfx::GpuMemoryBufferId id, 115 gfx::GpuMemoryBufferId id,
109 const gfx::Size& size, 116 const gfx::Size& size,
110 gfx::BufferFormat format, 117 gfx::BufferFormat format,
111 gfx::BufferUsage usage, 118 gfx::BufferUsage usage,
112 int client_id, 119 int client_id,
113 gfx::PluginWindowHandle surface_handle) { 120 gfx::PluginWindowHandle surface_handle) {
114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; 121 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, 122 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
116 0, 123 &kCFTypeDictionaryKeyCallBacks,
117 &kCFTypeDictionaryKeyCallBacks, 124 &kCFTypeDictionaryValueCallBacks));
118 &kCFTypeDictionaryValueCallBacks));
119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); 125 AddIntegerValue(properties, kIOSurfaceWidth, size.width());
120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); 126 AddIntegerValue(properties, kIOSurfaceHeight, size.height());
121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format));
122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); 127 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format));
123 128
129 if (format == gfx::BufferFormat::YUV_420_BIPLANAR) {
130 // This format has 2 planes, Y and interleaved UV.
131 base::ScopedCFTypeRef<CFMutableDictionaryRef> y_plane(
132 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
133 &kCFTypeDictionaryKeyCallBacks,
134 &kCFTypeDictionaryValueCallBacks));
135 AddIntegerValue(y_plane, kIOSurfacePlaneWidth, size.width());
136 AddIntegerValue(y_plane, kIOSurfacePlaneHeight, size.height());
137 AddIntegerValue(y_plane, kIOSurfacePlaneBytesPerElement, 1);
138
139 base::ScopedCFTypeRef<CFMutableDictionaryRef> uv_plane(
140 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
141 &kCFTypeDictionaryKeyCallBacks,
142 &kCFTypeDictionaryValueCallBacks));
143 AddIntegerValue(uv_plane, kIOSurfacePlaneWidth, size.width() / 2);
144 AddIntegerValue(uv_plane, kIOSurfacePlaneHeight, size.height() / 2);
145 AddIntegerValue(uv_plane, kIOSurfacePlaneBytesPerElement, 2);
146
147 base::ScopedCFTypeRef<CFMutableArrayRef> planes(
148 CFArrayCreateMutable(kCFAllocatorDefault, 2, &kCFTypeArrayCallBacks));
149 CFArrayAppendValue(planes, y_plane);
150 CFArrayAppendValue(planes, uv_plane);
151 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes);
reveman 2015/08/10 22:40:55 Could we refactor this code to set kIOSurfacePlane
Andre 2015/08/11 03:50:46 Done.
152 } else {
153 AddIntegerValue(
154 properties, kIOSurfaceBytesPerElement, BytesPerPixel(format));
155 }
156
124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); 157 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties));
125 if (!io_surface) 158 if (!io_surface)
126 return gfx::GpuMemoryBufferHandle(); 159 return gfx::GpuMemoryBufferHandle();
127 160
128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, 161 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id,
129 io_surface)) { 162 io_surface)) {
130 return gfx::GpuMemoryBufferHandle(); 163 return gfx::GpuMemoryBufferHandle();
131 } 164 }
132 165
133 { 166 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 212
180 scoped_refptr<gfx::GLImageIOSurface> image( 213 scoped_refptr<gfx::GLImageIOSurface> image(
181 new gfx::GLImageIOSurface(size, internalformat)); 214 new gfx::GLImageIOSurface(size, internalformat));
182 if (!image->Initialize(it->second.get(), format)) 215 if (!image->Initialize(it->second.get(), format))
183 return scoped_refptr<gfx::GLImage>(); 216 return scoped_refptr<gfx::GLImage>();
184 217
185 return image; 218 return image;
186 } 219 }
187 220
188 } // namespace content 221 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698