Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc

Issue 2188893002: gpu: Avoid creating two native pixmaps for the same buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698