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

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: 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Duplicate the handle. 85 // Duplicate the handle.
86 base::SharedMemoryHandle duped_shared_memory_handle; 86 base::SharedMemoryHandle duped_shared_memory_handle;
87 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), 87 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
88 &duped_shared_memory_handle)) { 88 &duped_shared_memory_handle)) {
89 DVLOG(0) << "Failed to duplicate shared memory handle."; 89 DVLOG(0) << "Failed to duplicate shared memory handle.";
90 return false; 90 return false;
91 } 91 }
92 92
93 shared_memory_.reset( 93 shared_memory_.reset(
94 new base::SharedMemory(duped_shared_memory_handle, true)); 94 new base::SharedMemory(duped_shared_memory_handle, true));
95
96 // Setup fallback option (for OES texture).
97 texture_id_ = 0;
98 egl_imagekhr_ = EGL_NO_IMAGE_KHR;
reveman 2014/03/13 15:52:40 please initialize these in the ctor instead.
99
95 return true; 100 return true;
96 } 101 }
97 102
98 void GLImageShm::Destroy() { 103 void GLImageShm::Destroy() {
104 if (egl_imagekhr_ != EGL_NO_IMAGE_KHR)
105 eglDestroyImageKHR(eglGetCurrentDisplay(), egl_imagekhr_);
106 if (texture_id_)
107 glDeleteTextures(1, &texture_id_);
99 } 108 }
100 109
101 gfx::Size GLImageShm::GetSize() { 110 gfx::Size GLImageShm::GetSize() {
102 return size_; 111 return size_;
103 } 112 }
104 113
105 bool GLImageShm::BindTexImage(unsigned target) { 114 bool GLImageShm::BindTexImage(unsigned target) {
106 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 115 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
107 DCHECK(shared_memory_); 116 DCHECK(shared_memory_);
108 DCHECK(ValidFormat(internalformat_)); 117 DCHECK(ValidFormat(internalformat_));
109 118
110 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); 119 size_t size = size_.GetArea() * BytesPerPixel(internalformat_);
111 DCHECK(!shared_memory_->memory()); 120 DCHECK(!shared_memory_->memory());
112 if (!shared_memory_->Map(size)) { 121 if (!shared_memory_->Map(size)) {
113 DVLOG(0) << "Failed to map shared memory."; 122 DVLOG(0) << "Failed to map shared memory.";
114 return false; 123 return false;
115 } 124 }
116 125
117 DCHECK(shared_memory_->memory()); 126 if (target == GL_TEXTURE_2D) {
reveman 2014/03/13 15:52:40 this should be "target != GL_TEXTURE_EXTERNAL_OES"
118 glTexImage2D(target, 127 DCHECK(shared_memory_->memory());
119 0, // mip level 128 glTexImage2D(target,
120 TextureFormat(internalformat_), 129 0, // mip level
121 size_.width(), 130 TextureFormat(internalformat_),
122 size_.height(), 131 size_.width(),
123 0, // border 132 size_.height(),
124 DataFormat(internalformat_), 133 0, // border
125 DataType(internalformat_), 134 DataFormat(internalformat_),
126 shared_memory_->memory()); 135 DataType(internalformat_),
136 shared_memory_->memory());
137 } else {
138 glGenTextures(1, &texture_id_);
reveman 2014/03/13 15:52:40 you're leaking textures and egl images by doing th
139 glActiveTexture(GL_TEXTURE0);
140 glBindTexture(GL_TEXTURE_2D, texture_id_);
reveman 2014/03/13 15:52:40 all the GL state you change in this function need
141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
127 144
145 DCHECK(shared_memory_->memory());
146 glTexImage2D(GL_TEXTURE_2D,
147 0, // mip level
148 TextureFormat(internalformat_),
149 size_.width(),
150 size_.height(),
151 0, // border
152 DataFormat(internalformat_),
153 DataType(internalformat_),
154 shared_memory_->memory());
reveman 2014/03/13 15:52:40 this is exactly the same as above. can you refacto
155
156 EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
157 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
158 egl_imagekhr_ =
159 eglCreateImageKHR(eglGetCurrentDisplay(),
160 eglGetCurrentContext(),
161 EGL_GL_TEXTURE_2D_KHR,
162 reinterpret_cast<EGLClientBuffer>(texture_id_),
163 egl_attrib_list);
164 if (egl_imagekhr_ == EGL_NO_IMAGE_KHR) {
165 EGLint error = eglGetError();
166 LOG(ERROR) << "Error creating EGLImage: " << error;
167 return false;
reveman 2014/03/13 15:52:40 shared_memory_->Unmap() is never called when you r
168 }
169 glBindTexture(GL_TEXTURE_2D, texture_id_);
170 glEGLImageTargetTexture2DOES(target, egl_imagekhr_);
171 }
128 shared_memory_->Unmap(); 172 shared_memory_->Unmap();
129 return true; 173 return true;
130 } 174 }
131 175
132 void GLImageShm::ReleaseTexImage(unsigned target) { 176 void GLImageShm::ReleaseTexImage(unsigned target) {
133 } 177 }
134 178
135 void GLImageShm::WillUseTexImage() { 179 void GLImageShm::WillUseTexImage() {
136 } 180 }
137 181
138 void GLImageShm::DidUseTexImage() { 182 void GLImageShm::DidUseTexImage() {
139 } 183 }
140 184
141 } // namespace gfx 185 } // 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