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

Side by Side 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: rebase Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_image_shm.h ('k') | ui/gl/gl_image_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_image_shm.h" 5 #include "ui/gl/gl_image_shm.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/process/process_handle.h" 8 #include "base/process/process_handle.h"
9 #include "ui/gl/gl_bindings.h" 9 #include "ui/gl/gl_bindings.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 12
13 GLImageShm::GLImageShm(gfx::Size size) : size_(size) { 13 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
14 : size_(size),
15 internalformat_(internalformat) {
16 // GL_RGBA8_OES is currently the only supported internalformat.
17 DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
14 } 18 }
15 19
16 GLImageShm::~GLImageShm() { 20 GLImageShm::~GLImageShm() {
17 Destroy(); 21 Destroy();
18 } 22 }
19 23
20 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { 24 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
21 if (!base::SharedMemory::IsHandleValid(buffer.handle)) 25 if (!base::SharedMemory::IsHandleValid(buffer.handle))
22 return false; 26 return false;
23 27
24 base::SharedMemory shared_memory(buffer.handle, true); 28 base::SharedMemory shared_memory(buffer.handle, true);
25 29
26 // Duplicate the handle. 30 // Duplicate the handle.
27 base::SharedMemoryHandle duped_shared_memory_handle; 31 base::SharedMemoryHandle duped_shared_memory_handle;
28 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), 32 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
29 &duped_shared_memory_handle)) { 33 &duped_shared_memory_handle)) {
30 DVLOG(0) << "Failed to duplicate shared memory handle."; 34 DVLOG(0) << "Failed to duplicate shared memory handle.";
31 return false; 35 return false;
32 } 36 }
33 37
34 shared_memory_.reset( 38 shared_memory_.reset(
35 new base::SharedMemory(duped_shared_memory_handle, true)); 39 new base::SharedMemory(duped_shared_memory_handle, true));
36 return true; 40 return true;
37 } 41 }
38 42
39 bool GLImageShm::BindTexImage() { 43 bool GLImageShm::BindTexImage() {
40 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 44 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
41 DCHECK(shared_memory_); 45 DCHECK(shared_memory_);
42 46
43 const int kBytesPerPixel = 4; 47 GLenum internalformat;
44 size_t size = size_.GetArea() * kBytesPerPixel; 48 GLenum format;
49 GLenum type;
50 int bytes_per_pixel;
51 switch (internalformat_) {
52 case GL_RGBA8_OES:
53 internalformat = GL_RGBA;
54 format = GL_RGBA;
55 type = GL_UNSIGNED_BYTE;
56 bytes_per_pixel = 4;
57 break;
58 default:
59 DVLOG(0) << "Invalid format: " << internalformat_;
60 return false;
61 }
62
63 size_t size = size_.GetArea() * bytes_per_pixel;
45 DCHECK(!shared_memory_->memory()); 64 DCHECK(!shared_memory_->memory());
46 if (!shared_memory_->Map(size)) { 65 if (!shared_memory_->Map(size)) {
47 DVLOG(0) << "Failed to map shared memory."; 66 DVLOG(0) << "Failed to map shared memory.";
48 return false; 67 return false;
49 } 68 }
50 69
51 DCHECK(shared_memory_->memory()); 70 DCHECK(shared_memory_->memory());
52 glTexImage2D(GL_TEXTURE_2D, 71 glTexImage2D(GL_TEXTURE_2D,
53 0, // mip level 72 0, // mip level
54 GL_RGBA, 73 internalformat,
55 size_.width(), 74 size_.width(),
56 size_.height(), 75 size_.height(),
57 0, // border 76 0, // border
58 GL_RGBA, 77 format,
59 GL_UNSIGNED_BYTE, 78 type,
60 shared_memory_->memory()); 79 shared_memory_->memory());
61 80
62 shared_memory_->Unmap(); 81 shared_memory_->Unmap();
63 return true; 82 return true;
64 } 83 }
65 84
66 gfx::Size GLImageShm::GetSize() { 85 gfx::Size GLImageShm::GetSize() {
67 return size_; 86 return size_;
68 } 87 }
69 88
70 void GLImageShm::Destroy() { 89 void GLImageShm::Destroy() {
71 } 90 }
72 91
73 void GLImageShm::ReleaseTexImage() { 92 void GLImageShm::ReleaseTexImage() {
74 } 93 }
75 94
76 } // namespace gfx 95 } // namespace gfx
OLDNEW
« no previous file with comments | « 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