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

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: rebased 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) {
143 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); 143 DCHECK_EQ(0u, egl_texture_id_);
144
145 if (!egl_texture_id_)
146 glGenTextures(1, &egl_texture_id_); 144 glGenTextures(1, &egl_texture_id_);
147 145
148 { 146 {
147 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
148
149 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
152 glTexImage2D(GL_TEXTURE_2D,
153 0, // mip level
154 TextureFormat(internalformat_),
155 size_.width(),
156 size_.height(),
157 0, // border
158 DataFormat(internalformat_),
159 DataType(internalformat_),
160 shared_memory_->memory());
161 }
162
163 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, 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 } else {
149 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); 175 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
153 176
154 glTexImage2D(GL_TEXTURE_2D, 177 glTexSubImage2D(GL_TEXTURE_2D,
155 0, // mip level 178 0, // mip level
156 TextureFormat(internalformat_), 179 0, // x-offset
157 size_.width(), 180 0, // y-offset
158 size_.height(), 181 size_.width(),
159 0, // border 182 size_.height(),
160 DataFormat(internalformat_), 183 DataFormat(internalformat_),
161 DataType(internalformat_), 184 DataType(internalformat_),
162 shared_memory_->memory()); 185 shared_memory_->memory());
163 } 186 }
164 187
165 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
166 // Need to pass current EGL rendering context to eglCreateImageKHR for
167 // target type EGL_GL_TEXTURE_2D_KHR.
168 egl_image_ =
169 eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
170 eglGetCurrentContext(),
171 EGL_GL_TEXTURE_2D_KHR,
172 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
173 attrs);
174 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
175 << "Error creating EGLImage: " << eglGetError();
176
177 glEGLImageTargetTexture2DOES(target, egl_image_); 188 glEGLImageTargetTexture2DOES(target, egl_image_);
178 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 189 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
179 190
180 shared_memory_->Unmap(); 191 shared_memory_->Unmap();
181 return true; 192 return true;
182 } 193 }
183 #endif 194 #endif
184 195
185 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); 196 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
186 glTexImage2D(target, 197 glTexImage2D(target,
187 0, // mip level 198 0, // mip level
188 TextureFormat(internalformat_), 199 TextureFormat(internalformat_),
189 size_.width(), 200 size_.width(),
190 size_.height(), 201 size_.height(),
191 0, // border 202 0, // border
192 DataFormat(internalformat_), 203 DataFormat(internalformat_),
193 DataType(internalformat_), 204 DataType(internalformat_),
194 shared_memory_->memory()); 205 shared_memory_->memory());
195 206
196 shared_memory_->Unmap(); 207 shared_memory_->Unmap();
197 return true; 208 return true;
198 } 209 }
199 210
200 } // namespace gfx 211 } // 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