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

Side by Side Diff: ui/gl/gl_image_shm.cc

Issue 198703002: Add GL_TEXTURE_EXTERNAL_OES as supported texture target for CHROMIUM_map_image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Save/restore GL states + nits Created 6 years, 9 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
« ui/gl/gl_image_shm.h ('K') | « ui/gl/gl_image_shm.h ('k') | no next file » | 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_surface_egl.h"
10 10
11 namespace gfx { 11 namespace gfx {
12 12
13 namespace { 13 namespace {
14 14
15 bool ValidFormat(unsigned internalformat) { 15 bool ValidFormat(unsigned internalformat) {
16 switch (internalformat) { 16 switch (internalformat) {
17 case GL_BGRA8_EXT: 17 case GL_BGRA8_EXT:
18 case GL_RGBA8_OES: 18 case GL_RGBA8_OES:
19 return true; 19 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 default: 57 default:
58 NOTREACHED(); 58 NOTREACHED();
59 return 0; 59 return 0;
60 } 60 }
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat) 65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
66 : size_(size), 66 : size_(size),
67 internalformat_(internalformat) { 67 internalformat_(internalformat),
68 } 68 external_texture_id_(0),
69 egl_image_(EGL_NO_IMAGE_KHR) {}
69 70
70 GLImageShm::~GLImageShm() { 71 GLImageShm::~GLImageShm() {
71 Destroy(); 72 Destroy();
72 } 73 }
73 74
74 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { 75 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
75 if (!ValidFormat(internalformat_)) { 76 if (!ValidFormat(internalformat_)) {
76 DVLOG(0) << "Invalid format: " << internalformat_; 77 DVLOG(0) << "Invalid format: " << internalformat_;
77 return false; 78 return false;
78 } 79 }
(...skipping 10 matching lines...) Expand all
89 DVLOG(0) << "Failed to duplicate shared memory handle."; 90 DVLOG(0) << "Failed to duplicate shared memory handle.";
90 return false; 91 return false;
91 } 92 }
92 93
93 shared_memory_.reset( 94 shared_memory_.reset(
94 new base::SharedMemory(duped_shared_memory_handle, true)); 95 new base::SharedMemory(duped_shared_memory_handle, true));
95 return true; 96 return true;
96 } 97 }
97 98
98 void GLImageShm::Destroy() { 99 void GLImageShm::Destroy() {
100 if (egl_image_ != EGL_NO_IMAGE_KHR)
101 eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_);
102 if (external_texture_id_)
103 glDeleteTextures(1, &external_texture_id_);
99 } 104 }
100 105
101 gfx::Size GLImageShm::GetSize() { 106 gfx::Size GLImageShm::GetSize() {
102 return size_; 107 return size_;
103 } 108 }
104 109
105 bool GLImageShm::BindTexImage(unsigned target) { 110 bool GLImageShm::BindTexImage(unsigned target) {
106 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 111 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
107 DCHECK(shared_memory_); 112 DCHECK(shared_memory_);
108 DCHECK(ValidFormat(internalformat_)); 113 DCHECK(ValidFormat(internalformat_));
109 114
110 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); 115 size_t size = size_.GetArea() * BytesPerPixel(internalformat_);
111 DCHECK(!shared_memory_->memory()); 116 DCHECK(!shared_memory_->memory());
112 if (!shared_memory_->Map(size)) { 117 if (!shared_memory_->Map(size)) {
113 DVLOG(0) << "Failed to map shared memory."; 118 DVLOG(0) << "Failed to map shared memory.";
114 return false; 119 return false;
115 } 120 }
116 121
117 DCHECK(shared_memory_->memory()); 122 if (target != GL_TEXTURE_EXTERNAL_OES) {
118 glTexImage2D(target, 123 DCHECK(shared_memory_->memory());
119 0, // mip level 124 glTexImage2D(target,
120 TextureFormat(internalformat_), 125 0, // mip level
121 size_.width(), 126 TextureFormat(internalformat_),
122 size_.height(), 127 size_.width(),
123 0, // border 128 size_.height(),
124 DataFormat(internalformat_), 129 0, // border
125 DataType(internalformat_), 130 DataFormat(internalformat_),
126 shared_memory_->memory()); 131 DataType(internalformat_),
132 shared_memory_->memory());
133 } else {
134 glGenTextures(1, &external_texture_id_);
reveman 2014/03/14 14:06:22 Why did you make external_texture_id_ a member but
sohanjg 2014/03/15 10:03:53 Done. Have reused the creation code. But, they can
127 135
136 // Save current GL states
137 GLint current_texture_id = 0;
138 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &current_texture_id);
139 GLint current_active_texture_unit = 0;
140 glGetIntegerv(GL_ACTIVE_TEXTURE, &current_active_texture_unit);
reveman 2014/03/14 14:06:22 Do you have to change active texture?
sohanjg 2014/03/15 10:03:53 Done. Generally before bindTex we do an activeTex
141
142 glActiveTexture(GL_TEXTURE0);
143 glBindTexture(GL_TEXTURE_2D, external_texture_id_);
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
147
148 DCHECK(shared_memory_->memory());
149 glTexImage2D(GL_TEXTURE_2D,
150 0, // mip level
151 TextureFormat(internalformat_),
152 size_.width(),
153 size_.height(),
154 0, // border
155 DataFormat(internalformat_),
156 DataType(internalformat_),
157 shared_memory_->memory());
158
159 EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
160 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
161 egl_image_ = eglCreateImageKHR(
162 eglGetCurrentDisplay(),
163 eglGetCurrentContext(),
164 EGL_GL_TEXTURE_2D_KHR,
165 reinterpret_cast<EGLClientBuffer>(external_texture_id_),
166 egl_attrib_list);
167 if (egl_image_ == EGL_NO_IMAGE_KHR) {
168 EGLint error = eglGetError();
169 LOG(ERROR) << "Error creating EGLImage: " << error;
170 shared_memory_->Unmap();
171 return false;
172 }
173 glBindTexture(GL_TEXTURE_2D, external_texture_id_);
174 glEGLImageTargetTexture2DOES(target, egl_image_);
175
176 // Restore GL States and release
177 Destroy();
reveman 2014/03/14 14:06:22 Destory is supposed to release all resources. Not
sohanjg 2014/03/15 10:03:53 Done. Added a new ReleaseEGLImageandTexture functi
178 glBindTexture(target, current_texture_id);
179 glActiveTexture(current_active_texture_unit);
180 }
128 shared_memory_->Unmap(); 181 shared_memory_->Unmap();
129 return true; 182 return true;
130 } 183 }
131 184
132 void GLImageShm::ReleaseTexImage(unsigned target) { 185 void GLImageShm::ReleaseTexImage(unsigned target) {
133 } 186 }
134 187
135 void GLImageShm::WillUseTexImage() { 188 void GLImageShm::WillUseTexImage() {
136 } 189 }
137 190
138 void GLImageShm::DidUseTexImage() { 191 void GLImageShm::DidUseTexImage() {
139 } 192 }
140 193
141 } // namespace gfx 194 } // namespace gfx
OLDNEW
« ui/gl/gl_image_shm.h ('K') | « ui/gl/gl_image_shm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698