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

Unified Diff: ui/gl/gl_image_shared_memory.cc

Issue 331723003: gpu: Remove Create/DeleteImage IPC by adding an X11_PIXMAP_BUFFER GpuMemoryBuffer type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | « ui/gl/gl_image_shared_memory.h ('k') | ui/gl/gl_image_shm.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_image_shared_memory.cc
diff --git a/ui/gl/gl_image_shared_memory.cc b/ui/gl/gl_image_shared_memory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7c578ba8baaf4b9f646e15ea37c47c770fa54ba7
--- /dev/null
+++ b/ui/gl/gl_image_shared_memory.cc
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gl/gl_image_shared_memory.h"
+
+#include "base/logging.h"
+#include "base/process/process_handle.h"
+
+namespace gfx {
+
+GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size,
+ unsigned internalformat)
+ : GLImageMemory(size, internalformat) {
+}
+
+GLImageSharedMemory::~GLImageSharedMemory() {
+ Destroy();
+}
+
+bool GLImageSharedMemory::Initialize(const gfx::GpuMemoryBufferHandle& handle) {
+ if (!HasValidFormat())
+ return false;
+
+ if (!base::SharedMemory::IsHandleValid(handle.handle))
+ return false;
+
+ base::SharedMemory shared_memory(handle.handle, true);
+
+ // Duplicate the handle.
+ base::SharedMemoryHandle duped_shared_memory_handle;
+ if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
+ &duped_shared_memory_handle)) {
+ DVLOG(0) << "Failed to duplicate shared memory handle.";
+ return false;
+ }
+
+ scoped_ptr<base::SharedMemory> duped_shared_memory(
+ new base::SharedMemory(duped_shared_memory_handle, true));
+
+ if (!duped_shared_memory->Map(Bytes())) {
+ DVLOG(0) << "Failed to map shared memory.";
+ return false;
+ }
+
+ DCHECK(!shared_memory_);
+ shared_memory_ = duped_shared_memory.Pass();
+ GLImageMemory::Initialize(
+ static_cast<unsigned char*>(shared_memory_->memory()));
+ return true;
+}
+
+void GLImageSharedMemory::Destroy() {
+ GLImageMemory::Destroy();
+ shared_memory_.reset();
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gl/gl_image_shared_memory.h ('k') | ui/gl/gl_image_shm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698