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

Unified Diff: ui/gl/gl_image_shm.cc

Issue 20017005: gpu: Refactor GpuMemoryBuffer framework for multi-process support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
Index: ui/gl/gl_image_shm.cc
diff --git a/ui/gl/gl_image_shm.cc b/ui/gl/gl_image_shm.cc
new file mode 100644
index 0000000000000000000000000000000000000000..835fb7ac64d05e974520b45c041c09e3d675ee97
--- /dev/null
+++ b/ui/gl/gl_image_shm.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2013 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_shm.h"
+
+#include "base/debug/trace_event.h"
+#include "base/process_util.h"
+#include "ui/gl/gl_bindings.h"
+
+namespace gfx {
+
+GLImageShm::GLImageShm(gfx::Size size) : size_(size) {
+}
+
+GLImageShm::~GLImageShm() {
+ Destroy();
+}
+
+bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
+ if (!base::SharedMemory::IsHandleValid(buffer.handle))
+ return false;
+
+ base::SharedMemory shared_memory(buffer.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;
+ }
+
+ shared_memory_.reset(
+ new base::SharedMemory(duped_shared_memory_handle, true));
+ return true;
+}
+
+bool GLImageShm::BindTexImage() {
+ TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
+ DCHECK(shared_memory_);
+
+ const int kBytesPerPixel = 4;
+ size_t size = size_.GetArea() * kBytesPerPixel;
+ DCHECK(!shared_memory_->memory());
+ if (!shared_memory_->Map(size)) {
+ DVLOG(0) << "Failed to map shared memory.";
+ return false;
+ }
+
+ DCHECK(shared_memory_->memory());
+ glTexImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ GL_RGBA8_OES,
+ size_.width(),
+ size_.height(),
+ 0, // border
+ GL_BGRA,
+ GL_UNSIGNED_BYTE,
+ shared_memory_->memory());
+
+ shared_memory_->Unmap();
+ return true;
+}
+
+gfx::Size GLImageShm::GetSize() {
+ return size_;
+}
+
+void GLImageShm::Destroy() {
+}
+
+void GLImageShm::ReleaseTexImage() {
+}
+
+} // namespace gfx
« ui/gfx/gpu_memory_buffer.h ('K') | « ui/gl/gl_image_shm.h ('k') | ui/gl/gl_image_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698