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 GetSupportedConfigurations( | |
44 std::vector<GpuMemoryBufferFactory::Configuration>* configurations) { | |
45 DCHECK(ui::NativePixmapManager::GetInstance()); | |
reveman
2015/07/23 14:46:12
nit: you don't need a !nullptr DCHECK when you der
dshwang
2015/07/23 16:42:09
Done.
| |
46 std::vector<ui::NativePixmapManager::Configuration> | |
47 native_pixmap_configurations = | |
48 ui::NativePixmapManager::GetInstance() | |
49 ->GetSupportedNativePixmapConfigurations(); | |
50 for (auto& native_pixmap_configuration : native_pixmap_configurations) { | |
51 configurations->push_back( | |
52 {FormatFromOzoneBufferFormat(native_pixmap_configuration.format), | |
53 UsageFromOzoneBufferUsage(native_pixmap_configuration.usage)}); | |
54 } | |
55 } | |
18 | 56 |
19 } // namespace | 57 } // namespace |
20 | 58 |
21 GpuMemoryBufferFactoryOzoneNativePixmap:: | 59 GpuMemoryBufferFactoryOzoneNativePixmap:: |
22 GpuMemoryBufferFactoryOzoneNativePixmap() {} | 60 GpuMemoryBufferFactoryOzoneNativePixmap() {} |
23 | 61 |
24 GpuMemoryBufferFactoryOzoneNativePixmap:: | 62 GpuMemoryBufferFactoryOzoneNativePixmap:: |
25 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} | 63 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} |
26 | 64 |
27 // static | 65 // static |
28 bool GpuMemoryBufferFactoryOzoneNativePixmap:: | 66 bool GpuMemoryBufferFactoryOzoneNativePixmap:: |
29 IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, | 67 IsGpuMemoryBufferConfigurationSupported(gfx::GpuMemoryBuffer::Format format, |
30 gfx::GpuMemoryBuffer::Usage usage) { | 68 gfx::GpuMemoryBuffer::Usage usage) { |
31 for (auto& configuration : kSupportedConfigurations) { | 69 std::vector<Configuration> configurations; |
70 GetSupportedConfigurations(&configurations); | |
71 for (auto& configuration : configurations) { | |
32 if (configuration.format == format && configuration.usage == usage) | 72 if (configuration.format == format && configuration.usage == usage) |
33 return true; | 73 return true; |
34 } | 74 } |
35 | 75 |
36 return false; | 76 return false; |
37 } | 77 } |
38 | 78 |
39 void GpuMemoryBufferFactoryOzoneNativePixmap:: | 79 void GpuMemoryBufferFactoryOzoneNativePixmap:: |
40 GetSupportedGpuMemoryBufferConfigurations( | 80 GetSupportedGpuMemoryBufferConfigurations( |
41 std::vector<Configuration>* configurations) { | 81 std::vector<Configuration>* configurations) { |
42 if (!ui::OzonePlatform::GetInstance() | 82 GetSupportedConfigurations(configurations); |
43 ->GetSurfaceFactoryOzone() | |
44 ->CanCreateNativePixmap(ui::SurfaceFactoryOzone::SCANOUT)) | |
45 return; | |
46 | |
47 configurations->assign( | |
48 kSupportedConfigurations, | |
49 kSupportedConfigurations + arraysize(kSupportedConfigurations)); | |
50 } | 83 } |
51 | 84 |
52 gfx::GpuMemoryBufferHandle | 85 gfx::GpuMemoryBufferHandle |
53 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( | 86 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( |
54 gfx::GpuMemoryBufferId id, | 87 gfx::GpuMemoryBufferId id, |
55 const gfx::Size& size, | 88 const gfx::Size& size, |
56 gfx::GpuMemoryBuffer::Format format, | 89 gfx::GpuMemoryBuffer::Format format, |
57 gfx::GpuMemoryBuffer::Usage usage, | 90 gfx::GpuMemoryBuffer::Usage usage, |
58 int client_id, | 91 int client_id, |
59 gfx::PluginWindowHandle surface_handle) { | 92 gfx::PluginWindowHandle surface_handle) { |
60 if (!ozone_native_pixmap_factory_.CreateGpuMemoryBuffer( | 93 if (!ozone_native_pixmap_factory_.CreateGpuMemoryBuffer( |
reveman
2015/07/23 14:46:12
Can ozone_native_pixmap_factory_ be replaced by Na
dshwang
2015/07/23 16:42:09
No, both have different purpose.
Note this class
reveman
2015/07/23 18:25:23
I don't follow why this needs to be two different
dshwang
2015/07/24 12:19:00
No, this class should have content/gpu pov, not co
reveman
2015/07/24 14:54:07
Please don't do that.
Video encoding changes bein
dshwang
2015/07/24 18:20:18
Ok. However, I cannot understand why moving factor
| |
61 id, size, format, usage, client_id, surface_handle)) { | 94 id, size, format, usage, client_id, surface_handle)) { |
62 return gfx::GpuMemoryBufferHandle(); | 95 return gfx::GpuMemoryBufferHandle(); |
63 } | 96 } |
64 gfx::GpuMemoryBufferHandle handle; | 97 gfx::GpuMemoryBufferHandle handle; |
65 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 98 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
66 handle.id = id; | 99 handle.id = id; |
67 return handle; | 100 return handle; |
68 } | 101 } |
69 | 102 |
70 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( | 103 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( |
(...skipping 12 matching lines...) Expand all Loading... | |
83 const gfx::Size& size, | 116 const gfx::Size& size, |
84 gfx::GpuMemoryBuffer::Format format, | 117 gfx::GpuMemoryBuffer::Format format, |
85 unsigned internalformat, | 118 unsigned internalformat, |
86 int client_id) { | 119 int client_id) { |
87 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); | 120 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); |
88 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( | 121 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( |
89 handle.id, size, format, internalformat, client_id); | 122 handle.id, size, format, internalformat, client_id); |
90 } | 123 } |
91 | 124 |
92 } // namespace content | 125 } // namespace content |
OLD | NEW |