Chromium Code Reviews| 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 BytesPerPixel(gfx::BufferFormat format) { |
| 27 switch (format) { | 29 switch (format) { |
| 28 case gfx::BufferFormat::R_8: | 30 case gfx::BufferFormat::R_8: |
| 31 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
| 29 return 1; | 32 return 1; |
| 30 case gfx::BufferFormat::BGRA_8888: | 33 case gfx::BufferFormat::BGRA_8888: |
| 31 return 4; | 34 return 4; |
| 32 case gfx::BufferFormat::ATC: | 35 case gfx::BufferFormat::ATC: |
| 33 case gfx::BufferFormat::ATCIA: | 36 case gfx::BufferFormat::ATCIA: |
| 34 case gfx::BufferFormat::DXT1: | 37 case gfx::BufferFormat::DXT1: |
| 35 case gfx::BufferFormat::DXT5: | 38 case gfx::BufferFormat::DXT5: |
| 36 case gfx::BufferFormat::ETC1: | 39 case gfx::BufferFormat::ETC1: |
| 37 case gfx::BufferFormat::RGBA_4444: | 40 case gfx::BufferFormat::RGBA_4444: |
| 38 case gfx::BufferFormat::RGBA_8888: | 41 case gfx::BufferFormat::RGBA_8888: |
| 39 case gfx::BufferFormat::RGBX_8888: | 42 case gfx::BufferFormat::RGBX_8888: |
| 40 case gfx::BufferFormat::YUV_420: | 43 case gfx::BufferFormat::YUV_420: |
| 41 NOTREACHED(); | 44 NOTREACHED(); |
| 42 return 0; | 45 return 0; |
| 43 } | 46 } |
| 44 | 47 |
| 45 NOTREACHED(); | 48 NOTREACHED(); |
| 46 return 0; | 49 return 0; |
| 47 } | 50 } |
| 48 | 51 |
| 49 int32 PixelFormat(gfx::BufferFormat format) { | 52 int32 PixelFormat(gfx::BufferFormat format) { |
| 50 switch (format) { | 53 switch (format) { |
| 51 case gfx::BufferFormat::R_8: | 54 case gfx::BufferFormat::R_8: |
| 52 return 'L008'; | 55 return 'L008'; |
| 53 case gfx::BufferFormat::BGRA_8888: | 56 case gfx::BufferFormat::BGRA_8888: |
| 54 return 'BGRA'; | 57 return 'BGRA'; |
| 58 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
| 59 return '420v'; | |
| 55 case gfx::BufferFormat::ATC: | 60 case gfx::BufferFormat::ATC: |
| 56 case gfx::BufferFormat::ATCIA: | 61 case gfx::BufferFormat::ATCIA: |
| 57 case gfx::BufferFormat::DXT1: | 62 case gfx::BufferFormat::DXT1: |
| 58 case gfx::BufferFormat::DXT5: | 63 case gfx::BufferFormat::DXT5: |
| 59 case gfx::BufferFormat::ETC1: | 64 case gfx::BufferFormat::ETC1: |
| 60 case gfx::BufferFormat::RGBA_4444: | 65 case gfx::BufferFormat::RGBA_4444: |
| 61 case gfx::BufferFormat::RGBA_8888: | 66 case gfx::BufferFormat::RGBA_8888: |
| 62 case gfx::BufferFormat::RGBX_8888: | 67 case gfx::BufferFormat::RGBX_8888: |
| 63 case gfx::BufferFormat::YUV_420: | 68 case gfx::BufferFormat::YUV_420: |
| 64 NOTREACHED(); | 69 NOTREACHED(); |
| 65 return 0; | 70 return 0; |
| 66 } | 71 } |
| 67 | 72 |
| 68 NOTREACHED(); | 73 NOTREACHED(); |
| 69 return 0; | 74 return 0; |
| 70 } | 75 } |
| 71 | 76 |
| 72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 77 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
| 73 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 78 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
| 74 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, | 79 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
| 75 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, | 80 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
| 76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, | 81 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
| 77 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; | 82 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}, |
| 83 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP}, | |
| 84 {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP}, | |
| 85 }; | |
| 78 | 86 |
| 79 } // namespace | 87 } // namespace |
| 80 | 88 |
| 81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 89 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
| 82 } | 90 } |
| 83 | 91 |
| 84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 92 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
| 85 } | 93 } |
| 86 | 94 |
| 87 // static | 95 // static |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 104 } | 112 } |
| 105 | 113 |
| 106 gfx::GpuMemoryBufferHandle | 114 gfx::GpuMemoryBufferHandle |
| 107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 115 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| 108 gfx::GpuMemoryBufferId id, | 116 gfx::GpuMemoryBufferId id, |
| 109 const gfx::Size& size, | 117 const gfx::Size& size, |
| 110 gfx::BufferFormat format, | 118 gfx::BufferFormat format, |
| 111 gfx::BufferUsage usage, | 119 gfx::BufferUsage usage, |
| 112 int client_id, | 120 int client_id, |
| 113 gfx::PluginWindowHandle surface_handle) { | 121 gfx::PluginWindowHandle surface_handle) { |
| 114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 122 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| 115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 123 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 116 0, | 124 &kCFTypeDictionaryKeyCallBacks, |
| 117 &kCFTypeDictionaryKeyCallBacks, | 125 &kCFTypeDictionaryValueCallBacks)); |
| 118 &kCFTypeDictionaryValueCallBacks)); | |
| 119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 126 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 127 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | |
| 122 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 128 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| 123 | 129 |
| 130 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); | |
| 131 DCHECK_GT(num_planes, 0u); | |
| 132 if (num_planes == 1) { | |
|
reveman
2015/08/11 08:20:08
This is unfortunate. What happens if we remove thi
Andre
2015/08/11 18:15:44
Done.
I removed the if statement, and it seems to
| |
| 133 AddIntegerValue( | |
| 134 properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | |
| 135 } else { | |
| 136 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( | |
| 137 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); | |
| 138 | |
| 139 for (size_t plane = 0; plane < num_planes; ++plane) { | |
| 140 size_t factor = GpuMemoryBufferImpl::SubsamplingFactor(format, plane); | |
| 141 gfx::Size plane_size(size.width() / factor, size.height() / factor); | |
| 142 size_t row_size; | |
| 143 bool valid_row_size = GpuMemoryBufferImpl::RowSizeInBytes( | |
| 144 size.width(), format, plane, &row_size); | |
| 145 DCHECK(valid_row_size); | |
| 146 | |
| 147 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( | |
| 148 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
| 149 &kCFTypeDictionaryKeyCallBacks, | |
| 150 &kCFTypeDictionaryValueCallBacks)); | |
| 151 AddIntegerValue(plane_info, kIOSurfacePlaneWidth, plane_size.width()); | |
| 152 AddIntegerValue(plane_info, kIOSurfacePlaneHeight, plane_size.height()); | |
| 153 AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, | |
| 154 row_size / plane_size.width()); | |
|
reveman
2015/08/11 08:20:08
Instead of using RowSizeInBytes here, can we repla
Andre
2015/08/11 18:15:44
Great idea, done.
| |
| 155 | |
| 156 CFArrayAppendValue(planes, plane_info); | |
| 157 } | |
| 158 | |
| 159 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); | |
| 160 } | |
| 161 | |
| 124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 162 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| 125 if (!io_surface) | 163 if (!io_surface) |
| 126 return gfx::GpuMemoryBufferHandle(); | 164 return gfx::GpuMemoryBufferHandle(); |
| 127 | 165 |
| 128 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | 166 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
| 129 io_surface)) { | 167 io_surface)) { |
| 130 return gfx::GpuMemoryBufferHandle(); | 168 return gfx::GpuMemoryBufferHandle(); |
| 131 } | 169 } |
| 132 | 170 |
| 133 { | 171 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 | 217 |
| 180 scoped_refptr<gfx::GLImageIOSurface> image( | 218 scoped_refptr<gfx::GLImageIOSurface> image( |
| 181 new gfx::GLImageIOSurface(size, internalformat)); | 219 new gfx::GLImageIOSurface(size, internalformat)); |
| 182 if (!image->Initialize(it->second.get(), format)) | 220 if (!image->Initialize(it->second.get(), format)) |
| 183 return scoped_refptr<gfx::GLImage>(); | 221 return scoped_refptr<gfx::GLImage>(); |
| 184 | 222 |
| 185 return image; | 223 return image; |
| 186 } | 224 } |
| 187 | 225 |
| 188 } // namespace content | 226 } // namespace content |
| OLD | NEW |