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

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: mac build break 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
« no previous file with comments | « 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/scoped_binders.h"
10
11 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
12 defined(USE_OZONE)
13 #include "ui/gl/gl_surface_egl.h"
14 #endif
10 15
11 namespace gfx { 16 namespace gfx {
12 17
13 namespace { 18 namespace {
14 19
15 bool ValidFormat(unsigned internalformat) { 20 bool ValidFormat(unsigned internalformat) {
16 switch (internalformat) { 21 switch (internalformat) {
17 case GL_BGRA8_EXT: 22 case GL_BGRA8_EXT:
18 case GL_RGBA8_OES: 23 case GL_RGBA8_OES:
19 return true; 24 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 default: 62 default:
58 NOTREACHED(); 63 NOTREACHED();
59 return 0; 64 return 0;
60 } 65 }
61 } 66 }
62 67
63 } // namespace 68 } // namespace
64 69
65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat) 70 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
66 : size_(size), 71 : size_(size),
67 internalformat_(internalformat) { 72 internalformat_(internalformat)
73 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
74 defined(USE_OZONE)
75 , egl_texture_id_(0u)
76 , egl_image_(EGL_NO_IMAGE_KHR)
77 #endif
78 {
68 } 79 }
69 80
70 GLImageShm::~GLImageShm() { 81 GLImageShm::~GLImageShm() {
71 Destroy(); 82 Destroy();
72 } 83 }
73 84
74 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { 85 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
75 if (!ValidFormat(internalformat_)) { 86 if (!ValidFormat(internalformat_)) {
76 DVLOG(0) << "Invalid format: " << internalformat_; 87 DVLOG(0) << "Invalid format: " << internalformat_;
77 return false; 88 return false;
(...skipping 11 matching lines...) Expand all
89 DVLOG(0) << "Failed to duplicate shared memory handle."; 100 DVLOG(0) << "Failed to duplicate shared memory handle.";
90 return false; 101 return false;
91 } 102 }
92 103
93 shared_memory_.reset( 104 shared_memory_.reset(
94 new base::SharedMemory(duped_shared_memory_handle, true)); 105 new base::SharedMemory(duped_shared_memory_handle, true));
95 return true; 106 return true;
96 } 107 }
97 108
98 void GLImageShm::Destroy() { 109 void GLImageShm::Destroy() {
110 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
111 defined(USE_OZONE)
112 if (egl_image_ != EGL_NO_IMAGE_KHR) {
113 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
114 egl_image_ = EGL_NO_IMAGE_KHR;
115 }
116 if (egl_texture_id_) {
117 glDeleteTextures(1, &egl_texture_id_);
118 egl_texture_id_ = 0u;
119 }
120 #endif
99 } 121 }
100 122
101 gfx::Size GLImageShm::GetSize() { 123 gfx::Size GLImageShm::GetSize() {
102 return size_; 124 return size_;
103 } 125 }
104 126
105 bool GLImageShm::BindTexImage(unsigned target) { 127 bool GLImageShm::BindTexImage(unsigned target) {
106 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 128 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
107 DCHECK(shared_memory_); 129 DCHECK(shared_memory_);
108 DCHECK(ValidFormat(internalformat_)); 130 DCHECK(ValidFormat(internalformat_));
109 131
110 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); 132 size_t size = size_.GetArea() * BytesPerPixel(internalformat_);
111 DCHECK(!shared_memory_->memory()); 133 DCHECK(!shared_memory_->memory());
112 if (!shared_memory_->Map(size)) { 134 if (!shared_memory_->Map(size)) {
113 DVLOG(0) << "Failed to map shared memory."; 135 DVLOG(0) << "Failed to map shared memory.";
114 return false; 136 return false;
115 } 137 }
116 138
117 DCHECK(shared_memory_->memory()); 139 DCHECK(shared_memory_->memory());
140
141 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
142 defined(USE_OZONE)
143 if (target == GL_TEXTURE_EXTERNAL_OES) {
144 if (egl_image_ != EGL_NO_IMAGE_KHR)
145 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
146
147 if (!egl_texture_id_)
148 glGenTextures(1, &egl_texture_id_);
149
150 {
151 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
155
156 glTexImage2D(GL_TEXTURE_2D,
157 0, // mip level
158 TextureFormat(internalformat_),
159 size_.width(),
160 size_.height(),
161 0, // border
162 DataFormat(internalformat_),
163 DataType(internalformat_),
164 shared_memory_->memory());
165 }
166
167 EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
168 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
169 // Need to pass current EGL rendering context to eglCreateImageKHR for
170 // target type EGL_GL_TEXTURE_2D_KHR.
171 egl_image_ =
172 eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
173 eglGetCurrentContext(),
174 EGL_GL_TEXTURE_2D_KHR,
175 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
176 attrs);
177 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
178 << "Error creating EGLImage: " << eglGetError();
179
180 glEGLImageTargetTexture2DOES(target, egl_image_);
181 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
182
183 shared_memory_->Unmap();
184 return true;
185 }
186 #endif
187
188 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
118 glTexImage2D(target, 189 glTexImage2D(target,
119 0, // mip level 190 0, // mip level
120 TextureFormat(internalformat_), 191 TextureFormat(internalformat_),
121 size_.width(), 192 size_.width(),
122 size_.height(), 193 size_.height(),
123 0, // border 194 0, // border
124 DataFormat(internalformat_), 195 DataFormat(internalformat_),
125 DataType(internalformat_), 196 DataType(internalformat_),
126 shared_memory_->memory()); 197 shared_memory_->memory());
127 198
(...skipping 10 matching lines...) Expand all
138 void GLImageShm::DidUseTexImage() { 209 void GLImageShm::DidUseTexImage() {
139 } 210 }
140 211
141 void GLImageShm::WillModifyTexImage() { 212 void GLImageShm::WillModifyTexImage() {
142 } 213 }
143 214
144 void GLImageShm::DidModifyTexImage() { 215 void GLImageShm::DidModifyTexImage() {
145 } 216 }
146 217
147 } // namespace gfx 218 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_shm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698