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

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

Issue 216873003: Use glTexSubImage2D while binding with external texture for map-image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | 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/scoped_binders.h" 9 #include "ui/gl/scoped_binders.h"
10 10
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (!shared_memory_->Map(size)) { 132 if (!shared_memory_->Map(size)) {
133 DVLOG(0) << "Failed to map shared memory."; 133 DVLOG(0) << "Failed to map shared memory.";
134 return false; 134 return false;
135 } 135 }
136 136
137 DCHECK(shared_memory_->memory()); 137 DCHECK(shared_memory_->memory());
138 138
139 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 139 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
140 defined(USE_OZONE) 140 defined(USE_OZONE)
141 if (target == GL_TEXTURE_EXTERNAL_OES) { 141 if (target == GL_TEXTURE_EXTERNAL_OES) {
142 if (egl_image_ != EGL_NO_IMAGE_KHR) 142 if (egl_image_ == EGL_NO_IMAGE_KHR) {
sohanjg 2014/03/28 12:36:20 Should we add an extra check for egl_texture_id_ b
reveman 2014/03/28 13:34:17 Add a DCHECK_EQ(0, ..) check.
143 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
144
145 if (!egl_texture_id_)
146 glGenTextures(1, &egl_texture_id_); 143 glGenTextures(1, &egl_texture_id_);
147 144
148 { 145 {
146 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
147 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
148 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
150
151 glTexImage2D(GL_TEXTURE_2D,
152 0, // mip level
153 TextureFormat(internalformat_),
154 size_.width(),
155 size_.height(),
156 0, // border
157 DataFormat(internalformat_),
158 DataType(internalformat_),
159 shared_memory_->memory());
160 }
161
162 EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_IMAGE_PRESERVED_KHR,
163 EGL_TRUE, EGL_NONE};
164 // Need to pass current EGL rendering context to eglCreateImageKHR for
165 // target type EGL_GL_TEXTURE_2D_KHR.
166 egl_image_ =
167 eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
168 eglGetCurrentContext(),
169 EGL_GL_TEXTURE_2D_KHR,
170 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
171 attrs);
172 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
173 << "Error creating EGLImage: " << eglGetError();
174
175 glEGLImageTargetTexture2DOES(target, egl_image_);
reveman 2014/03/28 13:34:17 You need to do this in the case below too. You're
176 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
177 } else {
149 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); 178 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 179 glTexSubImage2D(GL_TEXTURE_2D,
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 180 0, // mip level
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 181 0, // x-offset
153 182 0, // y-offset
154 glTexImage2D(GL_TEXTURE_2D, 183 size_.width(),
155 0, // mip level 184 size_.height(),
156 TextureFormat(internalformat_), 185 DataFormat(internalformat_),
157 size_.width(), 186 DataType(internalformat_),
158 size_.height(), 187 shared_memory_->memory());
159 0, // border
160 DataFormat(internalformat_),
161 DataType(internalformat_),
162 shared_memory_->memory());
163 } 188 }
164 189
165 EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_IMAGE_PRESERVED_KHR,
166 EGL_TRUE, EGL_NONE};
167 // Need to pass current EGL rendering context to eglCreateImageKHR for
168 // target type EGL_GL_TEXTURE_2D_KHR.
169 egl_image_ =
170 eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
171 eglGetCurrentContext(),
172 EGL_GL_TEXTURE_2D_KHR,
173 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
174 attrs);
175 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
176 << "Error creating EGLImage: " << eglGetError();
177
178 glEGLImageTargetTexture2DOES(target, egl_image_);
179 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
180
181 shared_memory_->Unmap(); 190 shared_memory_->Unmap();
182 return true; 191 return true;
183 } 192 }
184 #endif 193 #endif
185 194
186 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); 195 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
187 glTexImage2D(target, 196 glTexImage2D(target,
188 0, // mip level 197 0, // mip level
189 TextureFormat(internalformat_), 198 TextureFormat(internalformat_),
190 size_.width(), 199 size_.width(),
191 size_.height(), 200 size_.height(),
192 0, // border 201 0, // border
193 DataFormat(internalformat_), 202 DataFormat(internalformat_),
194 DataType(internalformat_), 203 DataType(internalformat_),
195 shared_memory_->memory()); 204 shared_memory_->memory());
196 205
197 shared_memory_->Unmap(); 206 shared_memory_->Unmap();
198 return true; 207 return true;
199 } 208 }
200 209
201 } // namespace gfx 210 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698