1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright 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/process_handle.h"
#include "ui/gl/gl_bindings.h"
namespace gfx {
GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
: size_(size),
internalformat_(internalformat) {
// GL_RGBA8_OES is currently the only supported internalformat.
DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat);
}
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;
}
void GLImageShm::Destroy() {
}
gfx::Size GLImageShm::GetSize() {
return size_;
}
bool GLImageShm::BindTexImage() {
TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
DCHECK(shared_memory_);
GLenum internalformat;
GLenum format;
GLenum type;
int bytes_per_pixel;
switch (internalformat_) {
case GL_RGBA8_OES:
internalformat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
bytes_per_pixel = 4;
break;
default:
DVLOG(0) << "Invalid format: " << internalformat_;
return false;
}
size_t size = size_.GetArea() * bytes_per_pixel;
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
internalformat,
size_.width(),
size_.height(),
0, // border
format,
type,
shared_memory_->memory());
shared_memory_->Unmap();
return true;
}
void GLImageShm::ReleaseTexImage() {
}
void GLImageShm::WillUseTexImage() {
}
void GLImageShm::DidUseTexImage() {
}
} // namespace gfx
|