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

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: 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 gfx::BufferFormat format, 108 gfx::BufferFormat format,
109 gfx::BufferUsage usage) { 109 gfx::BufferUsage usage) {
110 for (auto& configuration : kSupportedConfigurations) { 110 for (auto& configuration : kSupportedConfigurations) {
111 if (configuration.format == format && configuration.usage == usage) 111 if (configuration.format == format && configuration.usage == usage)
112 return true; 112 return true;
113 } 113 }
114 114
115 return false; 115 return false;
116 } 116 }
117 117
118 void GpuMemoryBufferFactoryIOSurface::GetSupportedGpuMemoryBufferConfigurations( 118 // static
119 std::vector<Configuration>* configurations) { 119 IOSurfaceRef GpuMemoryBufferFactoryIOSurface
120 configurations->assign( 120 : CreateIOSurface(const gfx::Size& size, gfx::BufferFormat format) {
121 kSupportedConfigurations,
122 kSupportedConfigurations + arraysize(kSupportedConfigurations));
123 }
124
125 gfx::GpuMemoryBufferHandle
126 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
127 gfx::GpuMemoryBufferId id,
128 const gfx::Size& size,
129 gfx::BufferFormat format,
130 gfx::BufferUsage usage,
131 int client_id,
132 gfx::PluginWindowHandle surface_handle) {
133 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); 121 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format);
134 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( 122 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable(
135 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); 123 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks));
136 124
137 for (size_t plane = 0; plane < num_planes; ++plane) { 125 for (size_t plane = 0; plane < num_planes; ++plane) {
138 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); 126 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane);
139 127
140 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( 128 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info(
141 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 129 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
142 &kCFTypeDictionaryKeyCallBacks, 130 &kCFTypeDictionaryKeyCallBacks,
143 &kCFTypeDictionaryValueCallBacks)); 131 &kCFTypeDictionaryValueCallBacks));
144 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor); 132 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor);
145 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor); 133 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor);
146 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, 134 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement,
147 BytesPerElement(format, plane)); 135 BytesPerElement(format, plane));
148 136
149 CFArrayAppendValue(planes, plane_info); 137 CFArrayAppendValue(planes, plane_info);
150 } 138 }
151 139
152 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( 140 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
153 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, 141 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
154 &kCFTypeDictionaryKeyCallBacks, 142 &kCFTypeDictionaryKeyCallBacks,
155 &kCFTypeDictionaryValueCallBacks)); 143 &kCFTypeDictionaryValueCallBacks));
156 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); 144 AddIntegerValue(properties, kIOSurfaceWidth, size.width());
157 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); 145 AddIntegerValue(properties, kIOSurfaceHeight, size.height());
158 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); 146 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format));
159 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); 147 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes);
160 148
161 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); 149 return IOSurfaceCreate(properties);
150 }
151
152 gfx::GpuMemoryBufferHandle
153 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer(
154 gfx::GpuMemoryBufferId id,
155 const gfx::Size& size,
156 gfx::BufferFormat format,
157 gfx::BufferUsage usage,
158 int client_id,
159 gfx::PluginWindowHandle surface_handle) {
160 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(CreateIOSurface(size, format));
162 if (!io_surface) 161 if (!io_surface)
163 return gfx::GpuMemoryBufferHandle(); 162 return gfx::GpuMemoryBufferHandle();
164 163
165 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, 164 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id,
166 io_surface)) { 165 io_surface)) {
167 return gfx::GpuMemoryBufferHandle(); 166 return gfx::GpuMemoryBufferHandle();
168 } 167 }
169 168
170 { 169 {
171 base::AutoLock lock(io_surfaces_lock_); 170 base::AutoLock lock(io_surfaces_lock_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 215
217 scoped_refptr<gfx::GLImageIOSurface> image( 216 scoped_refptr<gfx::GLImageIOSurface> image(
218 new gfx::GLImageIOSurface(handle.id, size, internalformat)); 217 new gfx::GLImageIOSurface(handle.id, size, internalformat));
219 if (!image->Initialize(it->second.get(), format)) 218 if (!image->Initialize(it->second.get(), format))
220 return scoped_refptr<gfx::GLImage>(); 219 return scoped_refptr<gfx::GLImage>();
221 220
222 return image; 221 return image;
223 } 222 }
224 223
225 } // namespace content 224 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698