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 "ui/gl/gl_image_ozone_native_pixmap.h" |
8 #include "ui/gl/gl_image.h" | |
9 #include "ui/ozone/public/ozone_platform.h" | 8 #include "ui/ozone/public/ozone_platform.h" |
10 #include "ui/ozone/public/surface_factory_ozone.h" | 9 #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 const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
16 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::SCANOUT}, | 15 {gfx::GpuMemoryBuffer::BGRA_8888, gfx::GpuMemoryBuffer::SCANOUT}, |
17 {gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT}}; | 16 {gfx::GpuMemoryBuffer::RGBX_8888, gfx::GpuMemoryBuffer::SCANOUT}}; |
18 | 17 |
18 ui::SurfaceFactoryOzone::BufferFormat GetOzoneFormatFor( | |
19 gfx::GpuMemoryBuffer::Format format) { | |
20 switch (format) { | |
21 case gfx::GpuMemoryBuffer::BGRA_8888: | |
22 return ui::SurfaceFactoryOzone::BGRA_8888; | |
23 case gfx::GpuMemoryBuffer::RGBX_8888: | |
24 return ui::SurfaceFactoryOzone::RGBX_8888; | |
25 case gfx::GpuMemoryBuffer::ATC: | |
26 case gfx::GpuMemoryBuffer::ATCIA: | |
27 case gfx::GpuMemoryBuffer::DXT1: | |
28 case gfx::GpuMemoryBuffer::DXT5: | |
29 case gfx::GpuMemoryBuffer::ETC1: | |
30 case gfx::GpuMemoryBuffer::R_8: | |
31 case gfx::GpuMemoryBuffer::RGBA_4444: | |
32 case gfx::GpuMemoryBuffer::RGBA_8888: | |
33 case gfx::GpuMemoryBuffer::YUV_420: | |
34 NOTREACHED(); | |
35 return ui::SurfaceFactoryOzone::BGRA_8888; | |
36 } | |
37 | |
38 NOTREACHED(); | |
39 return ui::SurfaceFactoryOzone::BGRA_8888; | |
40 } | |
41 | |
42 ui::SurfaceFactoryOzone::BufferUsage GetOzoneUsageFor( | |
43 gfx::GpuMemoryBuffer::Usage usage) { | |
44 switch (usage) { | |
45 case gfx::GpuMemoryBuffer::MAP: | |
46 return ui::SurfaceFactoryOzone::MAP; | |
47 case gfx::GpuMemoryBuffer::PERSISTENT_MAP: | |
48 return ui::SurfaceFactoryOzone::PERSISTENT_MAP; | |
49 case gfx::GpuMemoryBuffer::SCANOUT: | |
50 return ui::SurfaceFactoryOzone::SCANOUT; | |
51 } | |
52 | |
53 NOTREACHED(); | |
54 return ui::SurfaceFactoryOzone::MAP; | |
55 } | |
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:: |
(...skipping 21 matching lines...) Expand all Loading... | |
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) { |
60 if (!ozone_native_pixmap_factory_.CreateGpuMemoryBuffer( | 98 scoped_refptr<ui::NativePixmap> pixmap = |
61 id, size, format, usage, client_id, surface_handle)) { | 99 ui::OzonePlatform::GetInstance() |
100 ->GetSurfaceFactoryOzone() | |
101 ->CreateNativePixmap(surface_handle, size, GetOzoneFormatFor(format), | |
102 GetOzoneUsageFor(usage)); | |
103 if (!pixmap.get()) { | |
104 LOG(ERROR) << "Failed to create pixmap " << size.width() << "x" | |
105 << size.height() << " format " << format << ", usage " << usage; | |
62 return gfx::GpuMemoryBufferHandle(); | 106 return gfx::GpuMemoryBufferHandle(); |
63 } | 107 } |
108 base::AutoLock lock(native_pixmaps_lock_); | |
109 NativePixmapMapKey key(id, client_id); | |
110 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end()) | |
111 << "pixmap with this key must not exist"; | |
112 native_pixmaps_[key] = pixmap; | |
113 | |
64 gfx::GpuMemoryBufferHandle handle; | 114 gfx::GpuMemoryBufferHandle handle; |
65 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 115 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
66 handle.id = id; | 116 handle.id = id; |
67 return handle; | 117 return handle; |
68 } | 118 } |
69 | 119 |
70 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( | 120 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( |
71 gfx::GpuMemoryBufferId id, | 121 gfx::GpuMemoryBufferId id, |
72 int client_id) { | 122 int client_id) { |
73 ozone_native_pixmap_factory_.DestroyGpuMemoryBuffer(id, client_id); | 123 base::AutoLock lock(native_pixmaps_lock_); |
124 auto it = native_pixmaps_.find(NativePixmapMapKey(id, client_id)); | |
125 DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist"; | |
reveman
2015/07/29 15:28:14
nit: maybe do the same as above here:
NativePixmap
dshwang
2015/07/29 15:35:27
Thx, but I think before and after is identical. an
| |
126 native_pixmaps_.erase(it); | |
74 } | 127 } |
75 | 128 |
76 gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { | 129 gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { |
77 return this; | 130 return this; |
78 } | 131 } |
79 | 132 |
80 scoped_refptr<gfx::GLImage> | 133 scoped_refptr<gfx::GLImage> |
81 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( | 134 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( |
82 const gfx::GpuMemoryBufferHandle& handle, | 135 const gfx::GpuMemoryBufferHandle& handle, |
83 const gfx::Size& size, | 136 const gfx::Size& size, |
84 gfx::GpuMemoryBuffer::Format format, | 137 gfx::GpuMemoryBuffer::Format format, |
85 unsigned internalformat, | 138 unsigned internalformat, |
86 int client_id) { | 139 int client_id) { |
87 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); | 140 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); |
88 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( | 141 scoped_refptr<ui::NativePixmap> pixmap; |
89 handle.id, size, format, internalformat, client_id); | 142 { |
143 base::AutoLock lock(native_pixmaps_lock_); | |
144 NativePixmapMap::iterator it = | |
145 native_pixmaps_.find(NativePixmapMapKey(handle.id, client_id)); | |
146 if (it == native_pixmaps_.end()) { | |
147 return nullptr; | |
148 } | |
149 pixmap = it->second; | |
150 } | |
151 | |
152 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | |
153 new gfx::GLImageOzoneNativePixmap(size, internalformat)); | |
154 if (!image->Initialize(pixmap.get(), format)) { | |
155 LOG(ERROR) << "Failed to create GLImage"; | |
156 return nullptr; | |
157 } | |
158 return image; | |
90 } | 159 } |
91 | 160 |
92 } // namespace content | 161 } // namespace content |
OLD | NEW |