Chromium Code Reviews| Index: gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
| diff --git a/gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc b/gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
| index 4d233c6fbf688892c18f1206d8e64f4d099e4b6d..f9630a3cb5f6d9576949f09525657e3afa59aef0 100644 |
| --- a/gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
| +++ b/gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc |
| @@ -75,14 +75,29 @@ GpuMemoryBufferFactoryOzoneNativePixmap::CreateImageForGpuMemoryBuffer( |
| int client_id, |
| SurfaceHandle surface_handle) { |
| DCHECK_EQ(handle.type, gfx::OZONE_NATIVE_PIXMAP); |
| - scoped_refptr<ui::NativePixmap> pixmap = |
| - ui::OzonePlatform::GetInstance() |
| - ->GetSurfaceFactoryOzone() |
| - ->CreateNativePixmapFromHandle(surface_handle, size, format, |
| - handle.native_pixmap_handle); |
| - if (!pixmap.get()) { |
| - DLOG(ERROR) << "Failed to create pixmap from handle"; |
| - return nullptr; |
| + |
| + scoped_refptr<ui::NativePixmap> pixmap; |
| + |
| + // If CreateGpuMemoryBuffer was used to allocate this buffer then avoid |
| + // creating a new native pixmap for it. |
| + { |
| + base::AutoLock lock(native_pixmaps_lock_); |
| + NativePixmapMapKey key(handle.id.id, client_id); |
| + auto it = native_pixmaps_.find(key); |
| + if (it != native_pixmaps_.end()) |
| + pixmap = it->second; |
| + } |
| + |
| + // Create new pixmap from handle if one doesn't already exist. |
| + if (!pixmap) { |
| + pixmap = ui::OzonePlatform::GetInstance() |
| + ->GetSurfaceFactoryOzone() |
| + ->CreateNativePixmapFromHandle(surface_handle, size, format, |
| + handle.native_pixmap_handle); |
| + if (!pixmap.get()) { |
| + DLOG(ERROR) << "Failed to create pixmap from handle"; |
| + return nullptr; |
| + } |
|
piman
2016/07/27 22:42:14
Should we add pixmap to the map in this case, so t
reveman
2016/07/27 23:13:25
The client is in control over handle.id in this ca
|
| } |
| scoped_refptr<ui::GLImageOzoneNativePixmap> image( |