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 | |
57 std::pair<uint32_t, uint32_t> GetIndex(gfx::GpuMemoryBufferId id, | |
58 int client_id) { | |
59 return std::pair<uint32_t, uint32_t>(id, client_id); | |
60 } | |
reveman
2015/07/24 19:13:17
nit: remove this function in favor of just using "
dshwang
2015/07/24 19:57:20
Done.
| |
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:: |
(...skipping 21 matching lines...) Expand all Loading... | |
50 } | 93 } |
51 | 94 |
52 gfx::GpuMemoryBufferHandle | 95 gfx::GpuMemoryBufferHandle |
53 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( | 96 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( |
54 gfx::GpuMemoryBufferId id, | 97 gfx::GpuMemoryBufferId id, |
55 const gfx::Size& size, | 98 const gfx::Size& size, |
56 gfx::GpuMemoryBuffer::Format format, | 99 gfx::GpuMemoryBuffer::Format format, |
57 gfx::GpuMemoryBuffer::Usage usage, | 100 gfx::GpuMemoryBuffer::Usage usage, |
58 int client_id, | 101 int client_id, |
59 gfx::PluginWindowHandle surface_handle) { | 102 gfx::PluginWindowHandle surface_handle) { |
60 if (!ozone_native_pixmap_factory_.CreateGpuMemoryBuffer( | 103 scoped_refptr<ui::NativePixmap> pixmap = |
61 id, size, format, usage, client_id, surface_handle)) { | 104 ui::OzonePlatform::GetInstance() |
105 ->GetSurfaceFactoryOzone() | |
106 ->CreateNativePixmap(surface_handle, size, GetOzoneFormatFor(format), | |
107 GetOzoneUsageFor(usage)); | |
108 if (!pixmap.get()) { | |
109 LOG(ERROR) << "Failed to create pixmap " << size.width() << "x" | |
110 << size.height() << " format " << format << ", usage " << usage; | |
62 return gfx::GpuMemoryBufferHandle(); | 111 return gfx::GpuMemoryBufferHandle(); |
63 } | 112 } |
113 base::AutoLock lock(native_pixmap_map_lock_); | |
114 native_pixmap_map_[GetIndex(id, client_id)] = pixmap; | |
reveman
2015/07/24 19:13:17
nit: add DCHECK to ensure that pixmap with this ke
dshwang
2015/07/24 19:57:20
Done.
| |
115 | |
64 gfx::GpuMemoryBufferHandle handle; | 116 gfx::GpuMemoryBufferHandle handle; |
65 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 117 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
66 handle.id = id; | 118 handle.id = id; |
67 return handle; | 119 return handle; |
68 } | 120 } |
69 | 121 |
70 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( | 122 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( |
71 gfx::GpuMemoryBufferId id, | 123 gfx::GpuMemoryBufferId id, |
72 int client_id) { | 124 int client_id) { |
73 ozone_native_pixmap_factory_.DestroyGpuMemoryBuffer(id, client_id); | 125 base::AutoLock lock(native_pixmap_map_lock_); |
126 native_pixmap_map_.erase(GetIndex(id, client_id)); | |
reveman
2015/07/24 19:13:17
nit: add DCHECK to ensure that pixmap with this ke
dshwang
2015/07/24 19:57:20
Done.
| |
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 ui::NativePixmap* pixmap = nullptr; |
piman
2015/07/24 18:41:25
You need to keep a reference here. Otherwise, as s
reveman
2015/07/24 19:13:17
Maybe fix this by keeping the lock while we create
dshwang
2015/07/24 19:57:20
good point. changed to "scoped_refptr<ui::NativePi
| |
89 handle.id, size, format, internalformat, client_id); | 142 { |
143 base::AutoLock lock(native_pixmap_map_lock_); | |
144 BufferToPixmapMap::iterator it = | |
145 native_pixmap_map_.find(GetIndex(handle.id, client_id)); | |
146 if (it == native_pixmap_map_.end()) { | |
147 return scoped_refptr<gfx::GLImage>(); | |
148 } | |
149 pixmap = it->second.get(); | |
150 } | |
151 return gfx::CreateImageForNativePixmap(pixmap, size, format, internalformat); | |
90 } | 152 } |
91 | 153 |
92 } // namespace content | 154 } // namespace content |
OLD | NEW |