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 auto result = native_pixmaps_.insert( | |
110 std::make_pair(BufferToPixmapMapKey(id, client_id), pixmap)); | |
111 DCHECK(result.second) << "pixmap with this key must not exist"; | |
reveman
2015/07/29 14:16:41
This is fine but I typically prefer to isolate DCH
dshwang
2015/07/29 15:15:04
oh, that's good idea. Done.
| |
112 | |
64 gfx::GpuMemoryBufferHandle handle; | 113 gfx::GpuMemoryBufferHandle handle; |
65 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 114 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
66 handle.id = id; | 115 handle.id = id; |
67 return handle; | 116 return handle; |
68 } | 117 } |
69 | 118 |
70 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( | 119 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( |
71 gfx::GpuMemoryBufferId id, | 120 gfx::GpuMemoryBufferId id, |
72 int client_id) { | 121 int client_id) { |
73 ozone_native_pixmap_factory_.DestroyGpuMemoryBuffer(id, client_id); | 122 base::AutoLock lock(native_pixmaps_lock_); |
123 auto it = native_pixmaps_.find(BufferToPixmapMapKey(id, client_id)); | |
124 DCHECK(it != native_pixmaps_.end()) << "pixmap with this key must exist"; | |
125 native_pixmaps_.erase(it); | |
74 } | 126 } |
75 | 127 |
76 gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { | 128 gpu::ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { |
77 return this; | 129 return this; |
78 } | 130 } |
79 | 131 |
80 scoped_refptr<gfx::GLImage> | 132 scoped_refptr<gfx::GLImage> |
81 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( | 133 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( |
82 const gfx::GpuMemoryBufferHandle& handle, | 134 const gfx::GpuMemoryBufferHandle& handle, |
83 const gfx::Size& size, | 135 const gfx::Size& size, |
84 gfx::GpuMemoryBuffer::Format format, | 136 gfx::GpuMemoryBuffer::Format format, |
85 unsigned internalformat, | 137 unsigned internalformat, |
86 int client_id) { | 138 int client_id) { |
87 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); | 139 DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); |
88 return ozone_native_pixmap_factory_.CreateImageForGpuMemoryBuffer( | 140 scoped_refptr<ui::NativePixmap> pixmap; |
89 handle.id, size, format, internalformat, client_id); | 141 { |
142 base::AutoLock lock(native_pixmaps_lock_); | |
143 BufferToPixmapMap::iterator it = | |
144 native_pixmaps_.find(BufferToPixmapMapKey(handle.id, client_id)); | |
145 if (it == native_pixmaps_.end()) { | |
146 return nullptr; | |
147 } | |
148 pixmap = it->second; | |
149 } | |
150 | |
151 scoped_refptr<gfx::GLImageOzoneNativePixmap> image( | |
152 new gfx::GLImageOzoneNativePixmap(size, internalformat)); | |
153 if (!image->Initialize(pixmap, format)) { | |
154 LOG(ERROR) << "Failed to create GLImage"; | |
155 return nullptr; | |
156 } | |
157 return image; | |
90 } | 158 } |
91 | 159 |
92 } // namespace content | 160 } // namespace content |
OLD | NEW |