| 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 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 NOTREACHED(); | 71 NOTREACHED(); |
| 72 return 0; | 72 return 0; |
| 73 } | 73 } |
| 74 | 74 |
| 75 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 75 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
| 76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
| 77 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, | 77 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
| 78 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, | 78 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
| 79 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, | 79 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
| 80 {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}, |
| 84 }; |
| 81 | 85 |
| 82 } // namespace | 86 } // namespace |
| 83 | 87 |
| 84 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 88 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
| 85 } | 89 } |
| 86 | 90 |
| 87 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 91 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
| 88 } | 92 } |
| 89 | 93 |
| 90 // static | 94 // static |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 } | 111 } |
| 108 | 112 |
| 109 gfx::GpuMemoryBufferHandle | 113 gfx::GpuMemoryBufferHandle |
| 110 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 114 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| 111 gfx::GpuMemoryBufferId id, | 115 gfx::GpuMemoryBufferId id, |
| 112 const gfx::Size& size, | 116 const gfx::Size& size, |
| 113 gfx::BufferFormat format, | 117 gfx::BufferFormat format, |
| 114 gfx::BufferUsage usage, | 118 gfx::BufferUsage usage, |
| 115 int client_id, | 119 int client_id, |
| 116 gfx::PluginWindowHandle surface_handle) { | 120 gfx::PluginWindowHandle surface_handle) { |
| 117 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 121 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| 118 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 122 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 119 0, | 123 &kCFTypeDictionaryKeyCallBacks, |
| 120 &kCFTypeDictionaryKeyCallBacks, | 124 &kCFTypeDictionaryValueCallBacks)); |
| 121 &kCFTypeDictionaryValueCallBacks)); | |
| 122 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 125 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 123 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 126 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 124 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | |
| 125 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 127 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 126 | 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); |
| 152 } else { |
| 153 AddIntegerValue( |
| 154 properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
| 155 } |
| 156 |
| 127 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 157 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 128 if (!io_surface) | 158 if (!io_surface) |
| 129 return gfx::GpuMemoryBufferHandle(); | 159 return gfx::GpuMemoryBufferHandle(); |
| 130 | 160 |
| 131 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | 161 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
| 132 io_surface)) { | 162 io_surface)) { |
| 133 return gfx::GpuMemoryBufferHandle(); | 163 return gfx::GpuMemoryBufferHandle(); |
| 134 } | 164 } |
| 135 | 165 |
| 136 { | 166 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 212 |
| 183 scoped_refptr<gfx::GLImageIOSurface> image( | 213 scoped_refptr<gfx::GLImageIOSurface> image( |
| 184 new gfx::GLImageIOSurface(size, internalformat)); | 214 new gfx::GLImageIOSurface(size, internalformat)); |
| 185 if (!image->Initialize(it->second.get(), format)) | 215 if (!image->Initialize(it->second.get(), format)) |
| 186 return scoped_refptr<gfx::GLImage>(); | 216 return scoped_refptr<gfx::GLImage>(); |
| 187 | 217 |
| 188 return image; | 218 return image; |
| 189 } | 219 } |
| 190 | 220 |
| 191 } // namespace content | 221 } // namespace content |
| OLD | NEW |