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 "gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.h" | 5 #include "gpu/ipc/service/gpu_memory_buffer_factory_native_pixmap.h" |
6 | 6 |
7 #include "ui/gfx/client_native_pixmap.h" | 7 #include "ui/gfx/client_native_pixmap.h" |
8 #include "ui/gfx/native_pixmap.h" | 8 #include "ui/gfx/native_pixmap.h" |
9 #include "ui/gl/gl_image_native_pixmap.h" | 9 #include "ui/gl/gl_image_native_pixmap.h" |
10 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" | 10 |
| 11 #if defined(USE_OZONE) |
11 #include "ui/ozone/public/ozone_platform.h" | 12 #include "ui/ozone/public/ozone_platform.h" |
12 #include "ui/ozone/public/surface_factory_ozone.h" | 13 #include "ui/ozone/public/surface_factory_ozone.h" |
| 14 #endif |
13 | 15 |
14 namespace gpu { | 16 namespace gpu { |
15 | 17 |
16 GpuMemoryBufferFactoryOzoneNativePixmap:: | 18 GpuMemoryBufferFactoryNativePixmap::GpuMemoryBufferFactoryNativePixmap() {} |
17 GpuMemoryBufferFactoryOzoneNativePixmap() {} | |
18 | 19 |
19 GpuMemoryBufferFactoryOzoneNativePixmap:: | 20 GpuMemoryBufferFactoryNativePixmap::~GpuMemoryBufferFactoryNativePixmap() {} |
20 ~GpuMemoryBufferFactoryOzoneNativePixmap() {} | |
21 | 21 |
22 gfx::GpuMemoryBufferHandle | 22 gfx::GpuMemoryBufferHandle |
23 GpuMemoryBufferFactoryOzoneNativePixmap::CreateGpuMemoryBuffer( | 23 GpuMemoryBufferFactoryNativePixmap::CreateGpuMemoryBuffer( |
24 gfx::GpuMemoryBufferId id, | 24 gfx::GpuMemoryBufferId id, |
25 const gfx::Size& size, | 25 const gfx::Size& size, |
26 gfx::BufferFormat format, | 26 gfx::BufferFormat format, |
27 gfx::BufferUsage usage, | 27 gfx::BufferUsage usage, |
28 int client_id, | 28 int client_id, |
29 SurfaceHandle surface_handle) { | 29 SurfaceHandle surface_handle) { |
| 30 #if defined(USE_OZONE) |
30 scoped_refptr<gfx::NativePixmap> pixmap = | 31 scoped_refptr<gfx::NativePixmap> pixmap = |
31 ui::OzonePlatform::GetInstance() | 32 ui::OzonePlatform::GetInstance() |
32 ->GetSurfaceFactoryOzone() | 33 ->GetSurfaceFactoryOzone() |
33 ->CreateNativePixmap(surface_handle, size, format, usage); | 34 ->CreateNativePixmap(surface_handle, size, format, usage); |
34 if (!pixmap.get()) { | 35 if (!pixmap.get()) { |
35 DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " | 36 DLOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " |
36 << static_cast<int>(format) << ", usage " | 37 << static_cast<int>(format) << ", usage " |
37 << static_cast<int>(usage); | 38 << static_cast<int>(usage); |
38 return gfx::GpuMemoryBufferHandle(); | 39 return gfx::GpuMemoryBufferHandle(); |
39 } | 40 } |
40 | 41 |
41 gfx::GpuMemoryBufferHandle new_handle; | 42 gfx::GpuMemoryBufferHandle new_handle; |
42 new_handle.type = gfx::NATIVE_PIXMAP; | 43 new_handle.type = gfx::NATIVE_PIXMAP; |
43 new_handle.id = id; | 44 new_handle.id = id; |
44 new_handle.native_pixmap_handle = pixmap->ExportHandle(); | 45 new_handle.native_pixmap_handle = pixmap->ExportHandle(); |
45 | 46 |
46 // TODO(reveman): Remove this once crbug.com/628334 has been fixed. | 47 // TODO(reveman): Remove this once crbug.com/628334 has been fixed. |
47 { | 48 { |
48 base::AutoLock lock(native_pixmaps_lock_); | 49 base::AutoLock lock(native_pixmaps_lock_); |
49 NativePixmapMapKey key(id.id, client_id); | 50 NativePixmapMapKey key(id.id, client_id); |
50 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end()); | 51 DCHECK(native_pixmaps_.find(key) == native_pixmaps_.end()); |
51 native_pixmaps_[key] = pixmap; | 52 native_pixmaps_[key] = pixmap; |
52 } | 53 } |
53 | 54 |
54 return new_handle; | 55 return new_handle; |
| 56 #else |
| 57 NOTIMPLEMENTED(); |
| 58 return gfx::GpuMemoryBufferHandle(); |
| 59 #endif |
55 } | 60 } |
56 | 61 |
57 void GpuMemoryBufferFactoryOzoneNativePixmap::DestroyGpuMemoryBuffer( | 62 void GpuMemoryBufferFactoryNativePixmap::DestroyGpuMemoryBuffer( |
58 gfx::GpuMemoryBufferId id, | 63 gfx::GpuMemoryBufferId id, |
59 int client_id) { | 64 int client_id) { |
60 base::AutoLock lock(native_pixmaps_lock_); | 65 base::AutoLock lock(native_pixmaps_lock_); |
61 NativePixmapMapKey key(id.id, client_id); | 66 NativePixmapMapKey key(id.id, client_id); |
62 native_pixmaps_.erase(key); | 67 native_pixmaps_.erase(key); |
63 } | 68 } |
64 | 69 |
65 ImageFactory* GpuMemoryBufferFactoryOzoneNativePixmap::AsImageFactory() { | 70 ImageFactory* GpuMemoryBufferFactoryNativePixmap::AsImageFactory() { |
66 return this; | 71 return this; |
67 } | 72 } |
68 | 73 |
69 scoped_refptr<gl::GLImage> | 74 scoped_refptr<gl::GLImage> |
70 GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( | 75 GpuMemoryBufferFactoryNativePixmap::CreateImageForGpuMemoryBuffer( |
71 const gfx::GpuMemoryBufferHandle& handle, | 76 const gfx::GpuMemoryBufferHandle& handle, |
72 const gfx::Size& size, | 77 const gfx::Size& size, |
73 gfx::BufferFormat format, | 78 gfx::BufferFormat format, |
74 unsigned internalformat, | 79 unsigned internalformat, |
75 int client_id, | 80 int client_id, |
76 SurfaceHandle surface_handle) { | 81 SurfaceHandle surface_handle) { |
77 DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP); | 82 DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP); |
78 | 83 |
79 scoped_refptr<gfx::NativePixmap> pixmap; | 84 scoped_refptr<gfx::NativePixmap> pixmap; |
80 | 85 |
81 // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid | 86 // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid |
82 // creating a new native pixmap for it. | 87 // creating a new native pixmap for it. |
83 { | 88 { |
84 base::AutoLock lock(native_pixmaps_lock_); | 89 base::AutoLock lock(native_pixmaps_lock_); |
85 NativePixmapMapKey key(handle.id.id, client_id); | 90 NativePixmapMapKey key(handle.id.id, client_id); |
86 auto it = native_pixmaps_.find(key); | 91 auto it = native_pixmaps_.find(key); |
87 if (it != native_pixmaps_.end()) | 92 if (it != native_pixmaps_.end()) |
88 pixmap = it->second; | 93 pixmap = it->second; |
89 } | 94 } |
90 | 95 |
91 // Create new pixmap from handle if one doesn't already exist. | 96 // Create new pixmap from handle if one doesn't already exist. |
92 if (!pixmap) { | 97 if (!pixmap) { |
| 98 #if defined(USE_OZONE) |
93 pixmap = ui::OzonePlatform::GetInstance() | 99 pixmap = ui::OzonePlatform::GetInstance() |
94 ->GetSurfaceFactoryOzone() | 100 ->GetSurfaceFactoryOzone() |
95 ->CreateNativePixmapFromHandle(surface_handle, size, format, | 101 ->CreateNativePixmapFromHandle(surface_handle, size, format, |
96 handle.native_pixmap_handle); | 102 handle.native_pixmap_handle); |
| 103 #else |
| 104 // TODO(j.isorce): implement this to enable glCreateImageCHROMIUM on Linux. |
| 105 // On going in http://codereview.chromium.org/2705213005, crbug.com/584248. |
| 106 NOTIMPLEMENTED(); |
| 107 #endif |
97 if (!pixmap.get()) { | 108 if (!pixmap.get()) { |
98 DLOG(ERROR) << "Failed to create pixmap from handle"; | 109 DLOG(ERROR) << "Failed to create pixmap from handle"; |
99 return nullptr; | 110 return nullptr; |
100 } | 111 } |
101 } else { | 112 } else { |
102 for (const auto& fd : handle.native_pixmap_handle.fds) { | 113 for (const auto& fd : handle.native_pixmap_handle.fds) { |
103 // Close the fd by wrapping it in a ScopedFD and letting it fall | 114 // Close the fd by wrapping it in a ScopedFD and letting it fall |
104 // out of scope. | 115 // out of scope. |
105 base::ScopedFD scoped_fd(fd.fd); | 116 base::ScopedFD scoped_fd(fd.fd); |
106 } | 117 } |
107 } | 118 } |
108 | 119 |
109 scoped_refptr<gl::GLImageNativePixmap> image( | 120 scoped_refptr<gl::GLImageNativePixmap> image( |
110 new gl::GLImageNativePixmap(size, internalformat)); | 121 new gl::GLImageNativePixmap(size, internalformat)); |
111 if (!image->Initialize(pixmap.get(), format)) { | 122 if (!image->Initialize(pixmap.get(), format)) { |
112 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " | 123 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " |
113 << static_cast<int>(format); | 124 << static_cast<int>(format); |
114 return nullptr; | 125 return nullptr; |
115 } | 126 } |
116 return image; | 127 return image; |
117 } | 128 } |
118 | 129 |
119 scoped_refptr<gl::GLImage> | 130 scoped_refptr<gl::GLImage> |
120 GpuMemoryBufferFactoryOzoneNativePixmap::CreateAnonymousImage( | 131 GpuMemoryBufferFactoryNativePixmap::CreateAnonymousImage( |
121 const gfx::Size& size, | 132 const gfx::Size& size, |
122 gfx::BufferFormat format, | 133 gfx::BufferFormat format, |
123 unsigned internalformat) { | 134 unsigned internalformat) { |
124 scoped_refptr<gfx::NativePixmap> pixmap = | 135 scoped_refptr<gfx::NativePixmap> pixmap; |
125 ui::OzonePlatform::GetInstance() | 136 #if defined(USE_OZONE) |
126 ->GetSurfaceFactoryOzone() | 137 pixmap = ui::OzonePlatform::GetInstance() |
127 ->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format, | 138 ->GetSurfaceFactoryOzone() |
128 gfx::BufferUsage::SCANOUT); | 139 ->CreateNativePixmap(gpu::kNullSurfaceHandle, size, format, |
| 140 gfx::BufferUsage::SCANOUT); |
| 141 #else |
| 142 NOTIMPLEMENTED(); |
| 143 #endif |
129 if (!pixmap.get()) { | 144 if (!pixmap.get()) { |
130 LOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " | 145 LOG(ERROR) << "Failed to create pixmap " << size.ToString() << " format " |
131 << static_cast<int>(format); | 146 << static_cast<int>(format); |
132 return nullptr; | 147 return nullptr; |
133 } | 148 } |
134 scoped_refptr<gl::GLImageNativePixmap> image( | 149 scoped_refptr<gl::GLImageNativePixmap> image( |
135 new gl::GLImageNativePixmap(size, internalformat)); | 150 new gl::GLImageNativePixmap(size, internalformat)); |
136 if (!image->Initialize(pixmap.get(), format)) { | 151 if (!image->Initialize(pixmap.get(), format)) { |
137 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " | 152 LOG(ERROR) << "Failed to create GLImage " << size.ToString() << " format " |
138 << static_cast<int>(format); | 153 << static_cast<int>(format); |
139 return nullptr; | 154 return nullptr; |
140 } | 155 } |
141 return image; | 156 return image; |
142 } | 157 } |
143 | 158 |
144 unsigned GpuMemoryBufferFactoryOzoneNativePixmap::RequiredTextureType() { | 159 unsigned GpuMemoryBufferFactoryNativePixmap::RequiredTextureType() { |
145 return GL_TEXTURE_EXTERNAL_OES; | 160 return GL_TEXTURE_EXTERNAL_OES; |
146 } | 161 } |
147 | 162 |
148 } // namespace gpu | 163 } // namespace gpu |
OLD | NEW |