Skip to content

Commit

Permalink
gpu: Avoid creating two native pixmaps for the same buffer.
Browse files Browse the repository at this point in the history
For buffers allocated using CreateGpuMemoryBuffer, avoid
creating a second native pixmap for the same buffer as that
results in the associated GEM handle being closed twice.

BUG=631268
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2188893002
Cr-Commit-Position: refs/heads/master@{#408268}
  • Loading branch information
reveman-chromium authored and Commit bot committed Jul 27, 2016
1 parent 98a9636 commit 770b48e
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

scoped_refptr<ui::GLImageOzoneNativePixmap> image(
Expand Down

0 comments on commit 770b48e

Please sign in to comment.