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_ozone_native_pixmap.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gl/gl_image.h" | 8 #include "ui/gl/gl_image.h" |
9 #include "ui/ozone/public/ozone_platform.h" | 9 #include "ui/ozone/public/native_pixmap_manager.h" |
10 #include "ui/ozone/public/surface_factory_ozone.h" | |
11 | 10 |
12 namespace content { | 11 namespace content { |
13 namespace { | 12 namespace { |
14 | 13 |
15 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { | 14 gfx::GpuMemoryBuffer::Format FormatFromOzoneBufferFormat( |
16 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::SCANOUT}, | 15 ui::SurfaceFactoryOzone::BufferFormat ozone_format) { |
17 {gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT}}; | 16 switch (ozone_format) { |
17 case ui::SurfaceFactoryOzone::BGRA_8888: | |
18 return gfx::GpuMemoryBuffer::BGRA_8888; | |
19 case ui::SurfaceFactoryOzone::RGBX_8888: | |
20 return gfx::GpuMemoryBuffer::RGBX_8888; | |
21 case ui::SurfaceFactoryOzone::UNKNOWN: | |
22 NOTREACHED(); | |
23 break; | |
24 } | |
25 NOTREACHED(); | |
26 return gfx::GpuMemoryBuffer::BGRA_8888; | |
27 } | |
28 | |
29 gfx::GpuMemoryBuffer::Usage UsageFromOzoneBufferUsage( | |
30 ui::SurfaceFactoryOzone::BufferUsage ozone_usage) { | |
31 switch (ozone_usage) { | |
32 case ui::SurfaceFactoryOzone::MAP: | |
33 return gfx::GpuMemoryBuffer::MAP; | |
34 case ui::SurfaceFactoryOzone::PERSISTENT_MAP: | |
35 return gfx::GpuMemoryBuffer::PERSISTENT_MAP; | |
36 case ui::SurfaceFactoryOzone::SCANOUT: | |
37 return gfx::GpuMemoryBuffer::SCANOUT; | |
38 } | |
39 NOTREACHED(); | |
40 return gfx::GpuMemoryBuffer::MAP; | |
41 } | |
42 | |
43 void ConvertConfigurations( | |
44 const std::vector<ui::NativePixmapManager::Configuration>& | |
45 ozone_configurations, | |
46 std::vector<GpuMemoryBufferFactory::Configuration>* configurations) { | |
reveman
2015/07/22 16:59:55
not sure this helper function is worth much. just
dshwang
2015/07/23 14:02:28
Done.
| |
47 for (auto& ozone_conf : ozone_configurations) { | |
reveman
2015/07/22 16:59:55
nit: s/ozone_conf/ozone_configuration/ or maybe na
dshwang
2015/07/23 14:02:28
Done.
| |
48 configurations->push_back({FormatFromOzoneBufferFormat(ozone_conf.format), | |
49 UsageFromOzoneBufferUsage(ozone_conf.usage)}); | |
50 } | |
51 } | |
52 | |
53 void GetSupportedConfigurations( | |
54 std::vector<GpuMemoryBufferFactory::Configuration>* configurations) { | |
55 DCHECK(ui::NativePixmapManager::GetInstance()); | |
56 std::vector<ui::NativePixmapManager::Configuration> ozone_configurations = | |
57 ui::NativePixmapManager::GetInstance() | |
58 ->GetSupportedNativePixmapConfigurations(); | |
59 ConvertConfigurations(ozone_configurations, configurations); | |
60 } | |
18 | 61 |
19 } // namespace | 62 } // namespace |
20 | 63 |
21 GpuMemoryBufferFactoryOzoneNativePixmap:: | 64 GpuMemoryBufferFactoryOzoneNativePixmap:: |
22 GpuMemoryBufferFactoryOzoneNativePixmap() {} | 65 GpuMemoryBufferFactoryOzoneNativePixmap() {} |
23 | 66 |
24 GpuMemoryBufferFactoryOzoneNativePixmap:: | 67 GpuMemoryBufferFactoryOzoneNativePixmap:: |
25 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} | 68 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} |
26 | 69 |
27 // static | 70 // static |
28 bool GpuMemoryBufferFactoryOzoneNativePixmap:: | 71 bool GpuMemoryBufferFactoryOzoneNativePixmap:: |
29 IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, | 72 IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, |
30 gfx::GpuMemoryBuffer::Usage usage) { | 73 gfx::GpuMemoryBuffer::Usage usage) { |
31 for (auto& configuration : kSupportedConfigurations) { | 74 std::vector<Configuration> configurations; |
75 GetSupportedConfigurations(&configurations); | |
76 for (auto& configuration : configurations) { | |
32 if (configuration.format == format && configuration.usage == usage) | 77 if (configuration.format == format && configuration.usage == usage) |
33 return true; | 78 return true; |
34 } | 79 } |
35 | 80 |
36 return false; | 81 return false; |
37 } | 82 } |
38 | 83 |
39 void GpuMemoryBufferFactoryOzoneNativePixmap:: | 84 void GpuMemoryBufferFactoryOzoneNativePixmap:: |
40 GetSupportedGpuMemoryBufferConfigurations( | 85 GetSupportedGpuMemoryBufferConfigurations( |
41 std::vector<Configuration>* configurations) { | 86 std::vector<Configuration>* configurations) { |
42 if (!ui::OzonePlatform::GetInstance() | 87 GetSupportedConfigurations(configurations); |
43 ->GetSurfaceFactoryOzone() | |
44 ->CanCreateNativePixmap(ui::SurfaceFactoryOzone::SCANOUT)) | |
45 return; | |
46 | |
47 configurations->assign( | |
48 kSupportedConfigurations, | |
49 kSupportedConfigurations + arraysize(kSupportedConfigurations)); | |
50 } | 88 } |
51 | 89 |
52 gfx::GpuMemoryBufferHandle | 90 gfx::GpuMemoryBufferHandle |
53 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( | 91 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( |
54 gfx::GpuMemoryBufferId id, | 92 gfx::GpuMemoryBufferId id, |
55 const gfx::Size& size, | 93 const gfx::Size& size, |
56 gfx::GpuMemoryBuffer::Format format, | 94 gfx::GpuMemoryBuffer::Format format, |
57 gfx::GpuMemoryBuffer::Usage usage, | 95 gfx::GpuMemoryBuffer::Usage usage, |
58 int client_id, | 96 int client_id, |
59 gfx::PluginWindowHandle surface_handle) { | 97 gfx::PluginWindowHandle surface_handle) { |
(...skipping 23 matching lines...) Expand all Loading... | |
83 const gfx::Size& size, | 121 const gfx::Size& size, |
84 gfx::GpuMemoryBuffer::Format format, | 122 gfx::GpuMemoryBuffer::Format format, |
85 unsigned internalformat, | 123 unsigned internalformat, |
86 int client_id) { | 124 int client_id) { |
87 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_BUFFER); | 125 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_BUFFER); |
88 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( | 126 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( |
89 handle.id, size, format, internalformat, client_id); | 127 handle.id, size, format, internalformat, client_id); |
90 } | 128 } |
91 | 129 |
92 } // namespace content | 130 } // namespace content |
OLD | NEW |