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 4d233c6fbf688..f9630a3cb5f6d 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 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 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; + } } scoped_refptr image(