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 "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | 5 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gl/gl_image_egl.h" | 8 #include "ui/gl/gl_image_egl.h" |
9 #include "ui/gl/gl_image_linux_dma_buffer.h" | 9 #include "ui/gl/gl_image_linux_dma_buffer.h" |
10 #include "ui/ozone/public/native_pixmap.h" | 10 #include "ui/ozone/public/native_pixmap.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 return false; | 66 return false; |
67 pixmap_ = pixmap; | 67 pixmap_ = pixmap; |
68 return true; | 68 return true; |
69 } | 69 } |
70 | 70 |
71 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 71 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
72 int z_order, | 72 int z_order, |
73 gfx::OverlayTransform transform, | 73 gfx::OverlayTransform transform, |
74 const gfx::Rect& bounds_rect, | 74 const gfx::Rect& bounds_rect, |
75 const gfx::RectF& crop_rect) override { | 75 const gfx::RectF& crop_rect) override { |
76 DCHECK_EQ(pixmap_->GetBufferUsage(), NativePixmap::SCANOUT); | |
76 return pixmap_ && | 77 return pixmap_ && |
77 pixmap_->ScheduleOverlayPlane(widget, z_order, transform, | 78 pixmap_->ScheduleOverlayPlane(widget, z_order, transform, |
78 bounds_rect, crop_rect); | 79 bounds_rect, crop_rect); |
79 } | 80 } |
80 | 81 |
81 protected: | 82 protected: |
82 ~GLImageOzoneNativePixmapDmaBuf() override {} | 83 ~GLImageOzoneNativePixmapDmaBuf() override {} |
83 | 84 |
84 private: | 85 private: |
85 scoped_refptr<NativePixmap> pixmap_; | 86 scoped_refptr<NativePixmap> pixmap_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 } // namespace | 172 } // namespace |
172 | 173 |
173 GpuMemoryBufferFactoryOzoneNativeBuffer:: | 174 GpuMemoryBufferFactoryOzoneNativeBuffer:: |
174 GpuMemoryBufferFactoryOzoneNativeBuffer() { | 175 GpuMemoryBufferFactoryOzoneNativeBuffer() { |
175 } | 176 } |
176 | 177 |
177 GpuMemoryBufferFactoryOzoneNativeBuffer:: | 178 GpuMemoryBufferFactoryOzoneNativeBuffer:: |
178 ~GpuMemoryBufferFactoryOzoneNativeBuffer() { | 179 ~GpuMemoryBufferFactoryOzoneNativeBuffer() { |
179 } | 180 } |
180 | 181 |
181 bool GpuMemoryBufferFactoryOzoneNativeBuffer::CreateGpuMemoryBuffer( | 182 gfx::GpuMemoryBufferHandle |
183 GpuMemoryBufferFactoryOzoneNativeBuffer::CreateGpuMemoryBuffer( | |
182 gfx::GpuMemoryBufferId id, | 184 gfx::GpuMemoryBufferId id, |
183 const gfx::Size& size, | 185 const gfx::Size& size, |
184 gfx::GpuMemoryBuffer::Format format, | 186 gfx::GpuMemoryBuffer::Format format, |
185 gfx::GpuMemoryBuffer::Usage usage, | 187 gfx::GpuMemoryBuffer::Usage usage, |
186 int client_id, | 188 int client_id, |
187 gfx::PluginWindowHandle surface_handle) { | 189 gfx::PluginWindowHandle surface_handle) { |
188 scoped_refptr<NativePixmap> pixmap = | 190 scoped_refptr<NativePixmap> pixmap = |
189 OzonePlatform::GetInstance() | 191 OzonePlatform::GetInstance() |
190 ->GetSurfaceFactoryOzone() | 192 ->GetSurfaceFactoryOzone() |
191 ->CreateNativePixmap(surface_handle, size, GetOzoneFormatFor(format), | 193 ->CreateNativePixmap(surface_handle, size, GetOzoneFormatFor(format), |
192 GetOzoneUsageFor(usage)); | 194 GetOzoneUsageFor(usage)); |
193 if (!pixmap.get()) { | 195 if (!pixmap.get()) { |
194 LOG(ERROR) << "Failed to create pixmap " << size.width() << "x" | 196 LOG(ERROR) << "Failed to create pixmap " << size.width() << "x" |
195 << size.height() << " format " << format << ", usage " << usage; | 197 << size.height() << " format " << format << ", usage " << usage; |
196 return false; | 198 return gfx::GpuMemoryBufferHandle(); |
197 } | 199 } |
200 | |
201 gfx::GpuMemoryBufferHandle handle; | |
202 handle.type = gfx::OZONE_NATIVE_BUFFER; | |
203 handle.id = id; | |
204 if (usage == gfx::GpuMemoryBuffer::MAP) { | |
205 handle.handle = | |
206 OzonePlatform::GetInstance()->GetSurfaceFactoryOzone()->ExportDmaBuf( | |
spang
2015/07/24 22:08:25
What's the reason to have a SurfaceFactoryOzone::E
dshwang
2015/07/28 15:23:12
good point! Done.
| |
207 surface_handle, pixmap); | |
208 DCHECK(handle.handle.fd > 0) << "Fail to export dma_buf."; | |
209 } | |
210 | |
198 base::AutoLock lock(native_pixmap_map_lock_); | 211 base::AutoLock lock(native_pixmap_map_lock_); |
199 native_pixmap_map_[GetIndex(id, client_id)] = pixmap; | 212 native_pixmap_map_[GetIndex(id, client_id)] = pixmap; |
200 return true; | 213 return handle; |
201 } | 214 } |
202 | 215 |
203 void GpuMemoryBufferFactoryOzoneNativeBuffer::DestroyGpuMemoryBuffer( | 216 void GpuMemoryBufferFactoryOzoneNativeBuffer::DestroyGpuMemoryBuffer( |
204 gfx::GpuMemoryBufferId id, | 217 gfx::GpuMemoryBufferId id, |
205 int client_id) { | 218 int client_id) { |
206 base::AutoLock lock(native_pixmap_map_lock_); | 219 base::AutoLock lock(native_pixmap_map_lock_); |
207 native_pixmap_map_.erase(GetIndex(id, client_id)); | 220 native_pixmap_map_.erase(GetIndex(id, client_id)); |
208 } | 221 } |
209 | 222 |
210 scoped_refptr<gfx::GLImage> | 223 scoped_refptr<gfx::GLImage> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 new GLImageOzoneNativePixmapDmaBuf(size, internalformat); | 264 new GLImageOzoneNativePixmapDmaBuf(size, internalformat); |
252 if (!image->Initialize(pixmap.get(), format)) { | 265 if (!image->Initialize(pixmap.get(), format)) { |
253 return scoped_refptr<gfx::GLImage>(); | 266 return scoped_refptr<gfx::GLImage>(); |
254 } | 267 } |
255 return image; | 268 return image; |
256 } | 269 } |
257 return new GLImageOzoneOverlayOnlyPassThrough(pixmap, size, internalformat); | 270 return new GLImageOzoneOverlayOnlyPassThrough(pixmap, size, internalformat); |
258 } | 271 } |
259 | 272 |
260 } // namespace ui | 273 } // namespace ui |
OLD | NEW |