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

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

Issue 1389133002: content: Use type-parameterized tests for GpuMemoryBuffer implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add blankline Created 5 years, 2 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
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 case gfx::BufferFormat::BGRX_8888: 76 case gfx::BufferFormat::BGRX_8888:
77 case gfx::BufferFormat::YUV_420: 77 case gfx::BufferFormat::YUV_420:
78 NOTREACHED(); 78 NOTREACHED();
79 return 0; 79 return 0;
80 } 80 }
81 81
82 NOTREACHED(); 82 NOTREACHED();
83 return 0; 83 return 0;
84 } 84 }
85 85
86 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = {
87 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT},
88 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP},
89 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP},
90 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP},
91 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP},
92 {gfx::BufferFormat::UYVY_422, gfx::BufferUsage::MAP},
93 {gfx::BufferFormat::UYVY_422, gfx::BufferUsage::PERSISTENT_MAP},
94 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP},
95 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP},
96 };
97
98 } // namespace 86 } // namespace
99 87
100 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { 88 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() {
101 } 89 }
102 90
103 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { 91 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() {
104 } 92 }
105 93
106 // static 94 // static
107 bool GpuMemoryBufferFactoryIOSurface::IsGpuMemoryBufferConfigurationSupported( 95 bool GpuMemoryBufferFactoryIOSurface::IsGpuMemoryBufferConfigurationSupported(
108 gfx::BufferFormat format, 96 gfx::BufferFormat format,
109 gfx::BufferUsage usage) { 97 gfx::BufferUsage usage) {
110 for (auto& configuration : kSupportedConfigurations) { 98 switch (usage) {
111 if (configuration.format == format && configuration.usage == usage) 99 case gfx::BufferUsage::SCANOUT:
112 return true; 100 return format == gfx::BufferFormat::BGRA_8888;
101 case gfx::BufferUsage::MAP:
102 case gfx::BufferUsage::PERSISTENT_MAP:
103 return format == gfx::BufferFormat::R_8 ||
104 format == gfx::BufferFormat::BGRA_8888 ||
105 format == gfx::BufferFormat::UYVY_422 ||
106 format == gfx::BufferFormat::YUV_420_BIPLANAR;
113 } 107 }
114 108 NOTREACHED();
115 return false; 109 return false;
116 } 110 }
117 111
118 void GpuMemoryBufferFactoryIOSurface::GetSupportedGpuMemoryBufferConfigurations( 112 // static
119 std::vector<Configuration>* configurations) { 113 IOSurfaceRef GpuMemoryBufferFactoryIOSurface::CreateIOSurface(
120 configurations->assign(
121 kSupportedConfigurations,
122 kSupportedConfigurations + arraysize(kSupportedConfigurations));
123 }
124
125 gfx::GpuMemoryBufferHandle
126 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
127 gfx::GpuMemoryBufferId id,
128 const gfx::Size& size, 114 const gfx::Size& size,
129 gfx::BufferFormat format, 115 gfx::BufferFormat format) {
130 gfx::BufferUsage usage,
131 int client_id,
132 gfx::PluginWindowHandle surface_handle) {
133 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 116 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
134 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( 117 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable(
135 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); 118 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks));
136 119
137 for (size_t plane = 0; plane < num_planes; ++plane) { 120 for (size_t plane = 0; plane < num_planes; ++plane) {
138 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); 121 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane);
139 122
140 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( 123 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info(
141 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 124 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
142 &kCFTypeDictionaryKeyCallBacks, 125 &kCFTypeDictionaryKeyCallBacks,
143 &kCFTypeDictionaryValueCallBacks)); 126 &kCFTypeDictionaryValueCallBacks));
144 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor); 127 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor);
145 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor); 128 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor);
146 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, 129 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement,
147 BytesPerElement(format, plane)); 130 BytesPerElement(format, plane));
148 131
149 CFArrayAppendValue(planes, plane_info); 132 CFArrayAppendValue(planes, plane_info);
150 } 133 }
151 134
152 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( 135 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
153 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 136 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
154 &kCFTypeDictionaryKeyCallBacks, 137 &kCFTypeDictionaryKeyCallBacks,
155 &kCFTypeDictionaryValueCallBacks)); 138 &kCFTypeDictionaryValueCallBacks));
156 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); 139 AddIntegerValue(properties, kIOSurfaceWidth, size.width());
157 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); 140 AddIntegerValue(properties, kIOSurfaceHeight, size.height());
158 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); 141 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format));
159 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); 142 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes);
160 143
161 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); 144 return IOSurfaceCreate(properties);
145 }
146
147 gfx::GpuMemoryBufferHandle
148 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
149 gfx::GpuMemoryBufferId id,
150 const gfx::Size& size,
151 gfx::BufferFormat format,
152 gfx::BufferUsage usage,
153 int client_id,
154 gfx::PluginWindowHandle surface_handle) {
155 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(CreateIOSurface(size, format));
162 if (!io_surface) 156 if (!io_surface)
163 return gfx::GpuMemoryBufferHandle(); 157 return gfx::GpuMemoryBufferHandle();
164 158
165 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, 159 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id,
166 io_surface)) { 160 io_surface)) {
167 return gfx::GpuMemoryBufferHandle(); 161 return gfx::GpuMemoryBufferHandle();
168 } 162 }
169 163
170 { 164 {
171 base::AutoLock lock(io_surfaces_lock_); 165 base::AutoLock lock(io_surfaces_lock_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 210
217 scoped_refptr<gfx::GLImageIOSurface> image( 211 scoped_refptr<gfx::GLImageIOSurface> image(
218 new gfx::GLImageIOSurface(handle.id, size, internalformat)); 212 new gfx::GLImageIOSurface(handle.id, size, internalformat));
219 if (!image->Initialize(it->second.get(), format)) 213 if (!image->Initialize(it->second.get(), format))
220 return scoped_refptr<gfx::GLImage>(); 214 return scoped_refptr<gfx::GLImage>();
221 215
222 return image; 216 return image;
223 } 217 }
224 218
225 } // namespace content 219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698