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/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::GpuMemoryBuffer::Format format) { | 26 int32 BytesPerPixel(gfx::BufferFormat format) { |
27 switch (format) { | 27 switch (format) { |
28 case gfx::GpuMemoryBuffer::R_8: | 28 case gfx::BufferFormat::R_8: |
29 return 1; | 29 return 1; |
30 case gfx::GpuMemoryBuffer::BGRA_8888: | 30 case gfx::BufferFormat::BGRA_8888: |
31 return 4; | 31 return 4; |
32 case gfx::GpuMemoryBuffer::ATC: | 32 case gfx::BufferFormat::ATC: |
33 case gfx::GpuMemoryBuffer::ATCIA: | 33 case gfx::BufferFormat::ATCIA: |
34 case gfx::GpuMemoryBuffer::DXT1: | 34 case gfx::BufferFormat::DXT1: |
35 case gfx::GpuMemoryBuffer::DXT5: | 35 case gfx::BufferFormat::DXT5: |
36 case gfx::GpuMemoryBuffer::ETC1: | 36 case gfx::BufferFormat::ETC1: |
37 case gfx::GpuMemoryBuffer::RGBA_4444: | 37 case gfx::BufferFormat::RGBA_4444: |
38 case gfx::GpuMemoryBuffer::RGBA_8888: | 38 case gfx::BufferFormat::RGBA_8888: |
39 case gfx::GpuMemoryBuffer::RGBX_8888: | 39 case gfx::BufferFormat::RGBX_8888: |
40 case gfx::GpuMemoryBuffer::YUV_420: | 40 case gfx::BufferFormat::YUV_420: |
41 NOTREACHED(); | 41 NOTREACHED(); |
42 return 0; | 42 return 0; |
43 } | 43 } |
44 | 44 |
45 NOTREACHED(); | 45 NOTREACHED(); |
46 return 0; | 46 return 0; |
47 } | 47 } |
48 | 48 |
49 int32 PixelFormat(gfx::GpuMemoryBuffer::Format format) { | 49 int32 PixelFormat(gfx::BufferFormat format) { |
50 switch (format) { | 50 switch (format) { |
51 case gfx::GpuMemoryBuffer::R_8: | 51 case gfx::BufferFormat::R_8: |
52 return 'L008'; | 52 return 'L008'; |
53 case gfx::GpuMemoryBuffer::BGRA_8888: | 53 case gfx::BufferFormat::BGRA_8888: |
54 return 'BGRA'; | 54 return 'BGRA'; |
55 case gfx::GpuMemoryBuffer::ATC: | 55 case gfx::BufferFormat::ATC: |
56 case gfx::GpuMemoryBuffer::ATCIA: | 56 case gfx::BufferFormat::ATCIA: |
57 case gfx::GpuMemoryBuffer::DXT1: | 57 case gfx::BufferFormat::DXT1: |
58 case gfx::GpuMemoryBuffer::DXT5: | 58 case gfx::BufferFormat::DXT5: |
59 case gfx::GpuMemoryBuffer::ETC1: | 59 case gfx::BufferFormat::ETC1: |
60 case gfx::GpuMemoryBuffer::RGBA_4444: | 60 case gfx::BufferFormat::RGBA_4444: |
61 case gfx::GpuMemoryBuffer::RGBA_8888: | 61 case gfx::BufferFormat::RGBA_8888: |
62 case gfx::GpuMemoryBuffer::RGBX_8888: | 62 case gfx::BufferFormat::RGBX_8888: |
63 case gfx::GpuMemoryBuffer::YUV_420: | 63 case gfx::BufferFormat::YUV_420: |
64 NOTREACHED(); | 64 NOTREACHED(); |
65 return 0; | 65 return 0; |
66 } | 66 } |
67 | 67 |
68 NOTREACHED(); | 68 NOTREACHED(); |
69 return 0; | 69 return 0; |
70 } | 70 } |
71 | 71 |
72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 72 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
73 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::SCANOUT}, | 73 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
74 {gfx::GpuMemoryBuffer::R_8, gfx::GpuMemoryBuffer::PERSISTENT_MAP}, | 74 {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
75 {gfx::GpuMemoryBuffer::R_8, gfx::GpuMemoryBuffer::MAP}, | 75 {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
76 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::PERSISTENT_MAP}, | 76 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
77 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::MAP}}; | 77 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 81 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
82 } | 82 } |
83 | 83 |
84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 84 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
85 } | 85 } |
86 | 86 |
87 // static | 87 // static |
88 bool GpuMemoryBufferFactoryIOSurface::IsGpuMemoryBufferConfigurationSupported( | 88 bool GpuMemoryBufferFactoryIOSurface::IsGpuMemoryBufferConfigurationSupported( |
89 gfx::GpuMemoryBuffer::Format format, | 89 gfx::BufferFormat format, |
90 gfx::GpuMemoryBuffer::Usage usage) { | 90 gfx::BufferUsage usage) { |
91 for (auto& configuration : kSupportedConfigurations) { | 91 for (auto& configuration : kSupportedConfigurations) { |
92 if (configuration.format == format && configuration.usage == usage) | 92 if (configuration.format == format && configuration.usage == usage) |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 return false; | 96 return false; |
97 } | 97 } |
98 | 98 |
99 void GpuMemoryBufferFactoryIOSurface::GetSupportedGpuMemoryBufferConfigurations( | 99 void GpuMemoryBufferFactoryIOSurface::GetSupportedGpuMemoryBufferConfigurations( |
100 std::vector<Configuration>* configurations) { | 100 std::vector<Configuration>* configurations) { |
101 configurations->assign( | 101 configurations->assign( |
102 kSupportedConfigurations, | 102 kSupportedConfigurations, |
103 kSupportedConfigurations + arraysize(kSupportedConfigurations)); | 103 kSupportedConfigurations + arraysize(kSupportedConfigurations)); |
104 } | 104 } |
105 | 105 |
106 gfx::GpuMemoryBufferHandle | 106 gfx::GpuMemoryBufferHandle |
107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 107 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
108 gfx::GpuMemoryBufferId id, | 108 gfx::GpuMemoryBufferId id, |
109 const gfx::Size& size, | 109 const gfx::Size& size, |
110 gfx::GpuMemoryBuffer::Format format, | 110 gfx::BufferFormat format, |
111 gfx::GpuMemoryBuffer::Usage usage, | 111 gfx::BufferUsage usage, |
112 int client_id, | 112 int client_id, |
113 gfx::PluginWindowHandle surface_handle) { | 113 gfx::PluginWindowHandle surface_handle) { |
114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 114 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 115 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
116 0, | 116 0, |
117 &kCFTypeDictionaryKeyCallBacks, | 117 &kCFTypeDictionaryKeyCallBacks, |
118 &kCFTypeDictionaryValueCallBacks)); | 118 &kCFTypeDictionaryValueCallBacks)); |
119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 119 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 120 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 121 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 161 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
162 return this; | 162 return this; |
163 } | 163 } |
164 | 164 |
165 scoped_refptr<gfx::GLImage> | 165 scoped_refptr<gfx::GLImage> |
166 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 166 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
167 const gfx::GpuMemoryBufferHandle& handle, | 167 const gfx::GpuMemoryBufferHandle& handle, |
168 const gfx::Size& size, | 168 const gfx::Size& size, |
169 gfx::GpuMemoryBuffer::Format format, | 169 gfx::BufferFormat format, |
170 unsigned internalformat, | 170 unsigned internalformat, |
171 int client_id) { | 171 int client_id) { |
172 base::AutoLock lock(io_surfaces_lock_); | 172 base::AutoLock lock(io_surfaces_lock_); |
173 | 173 |
174 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | 174 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); |
175 IOSurfaceMapKey key(handle.id, client_id); | 175 IOSurfaceMapKey key(handle.id, client_id); |
176 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 176 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
177 if (it == io_surfaces_.end()) | 177 if (it == io_surfaces_.end()) |
178 return scoped_refptr<gfx::GLImage>(); | 178 return scoped_refptr<gfx::GLImage>(); |
179 | 179 |
180 scoped_refptr<gfx::GLImageIOSurface> image( | 180 scoped_refptr<gfx::GLImageIOSurface> image( |
181 new gfx::GLImageIOSurface(size, internalformat)); | 181 new gfx::GLImageIOSurface(size, internalformat)); |
182 if (!image->Initialize(it->second.get(), format)) | 182 if (!image->Initialize(it->second.get(), format)) |
183 return scoped_refptr<gfx::GLImage>(); | 183 return scoped_refptr<gfx::GLImage>(); |
184 | 184 |
185 return image; | 185 return image; |
186 } | 186 } |
187 | 187 |
188 } // namespace content | 188 } // namespace content |
OLD | NEW |