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

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: comments + consitent use of eglimage create params 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/gl_surface_egl.h"
10 #include "ui/gl/scoped_binders.h"
10 11
11 namespace gfx { 12 namespace gfx {
12 13
13 namespace { 14 namespace {
14 15
15 bool ValidFormat(unsigned internalformat) { 16 bool ValidFormat(unsigned internalformat) {
16 switch (internalformat) { 17 switch (internalformat) {
17 case GL_BGRA8_EXT: 18 case GL_BGRA8_EXT:
18 case GL_RGBA8_OES: 19 case GL_RGBA8_OES:
19 return true; 20 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 default: 58 default:
58 NOTREACHED(); 59 NOTREACHED();
59 return 0; 60 return 0;
60 } 61 }
61 } 62 }
62 63
63 } // namespace 64 } // namespace
64 65
65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat) 66 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
66 : size_(size), 67 : size_(size),
67 internalformat_(internalformat) { 68 internalformat_(internalformat),
68 } 69 egl_texture_id_(0u),
70 egl_image_(EGL_NO_IMAGE_KHR) {}
69 71
70 GLImageShm::~GLImageShm() { 72 GLImageShm::~GLImageShm() {
71 Destroy(); 73 Destroy();
72 } 74 }
73 75
74 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { 76 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
75 if (!ValidFormat(internalformat_)) { 77 if (!ValidFormat(internalformat_)) {
76 DVLOG(0) << "Invalid format: " << internalformat_; 78 DVLOG(0) << "Invalid format: " << internalformat_;
77 return false; 79 return false;
78 } 80 }
(...skipping 10 matching lines...) Expand all
89 DVLOG(0) << "Failed to duplicate shared memory handle."; 91 DVLOG(0) << "Failed to duplicate shared memory handle.";
90 return false; 92 return false;
91 } 93 }
92 94
93 shared_memory_.reset( 95 shared_memory_.reset(
94 new base::SharedMemory(duped_shared_memory_handle, true)); 96 new base::SharedMemory(duped_shared_memory_handle, true));
95 return true; 97 return true;
96 } 98 }
97 99
98 void GLImageShm::Destroy() { 100 void GLImageShm::Destroy() {
101 if (egl_image_ != EGL_NO_IMAGE_KHR) {
102 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
103 egl_image_ = EGL_NO_IMAGE_KHR;
104 }
105 if (egl_texture_id_) {
106 glDeleteTextures(1, &egl_texture_id_);
107 egl_texture_id_ = 0u;
108 }
99 } 109 }
100 110
101 gfx::Size GLImageShm::GetSize() { 111 gfx::Size GLImageShm::GetSize() {
102 return size_; 112 return size_;
103 } 113 }
104 114
105 bool GLImageShm::BindTexImage(unsigned target) { 115 bool GLImageShm::BindTexImage(unsigned target) {
106 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 116 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
107 DCHECK(shared_memory_); 117 DCHECK(shared_memory_);
108 DCHECK(ValidFormat(internalformat_)); 118 DCHECK(ValidFormat(internalformat_));
109 119
110 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); 120 size_t size = size_.GetArea() * BytesPerPixel(internalformat_);
111 DCHECK(!shared_memory_->memory()); 121 DCHECK(!shared_memory_->memory());
112 if (!shared_memory_->Map(size)) { 122 if (!shared_memory_->Map(size)) {
113 DVLOG(0) << "Failed to map shared memory."; 123 DVLOG(0) << "Failed to map shared memory.";
114 return false; 124 return false;
115 } 125 }
116 126
117 DCHECK(shared_memory_->memory()); 127 DCHECK(shared_memory_->memory());
118 glTexImage2D(target, 128 if (target != GL_TEXTURE_EXTERNAL_OES) {
119 0, // mip level 129 glTexImage2D(target,
120 TextureFormat(internalformat_), 130 0, // mip level
121 size_.width(), 131 TextureFormat(internalformat_),
122 size_.height(), 132 size_.width(),
123 0, // border 133 size_.height(),
124 DataFormat(internalformat_), 134 0, // border
125 DataType(internalformat_), 135 DataFormat(internalformat_),
126 shared_memory_->memory()); 136 DataType(internalformat_),
137 shared_memory_->memory());
138 } else {
139 if (!egl_texture_id_)
140 glGenTextures(1, &egl_texture_id_);
127 141
reveman 2014/03/24 16:46:16 try adding this here: if (egl_image_ != EGL_NO_IM
142 {
143 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_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 glTexImage2D(GL_TEXTURE_2D,
149 0, // mip level
150 TextureFormat(internalformat_),
151 size_.width(),
152 size_.height(),
153 0, // border
154 DataFormat(internalformat_),
155 DataType(internalformat_),
156 shared_memory_->memory());
157 }
158
159 EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
reveman 2014/03/24 16:46:16 nit: EGLint attrs[] = {EG...
160 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
161 egl_image_ =
162 eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
163 EGL_NO_CONTEXT,
164 EGL_GL_TEXTURE_2D_KHR,
165 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
166 egl_attrib_list);
167 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
168 << "Error creating EGLImage: " << eglGetError();
169
170 glEGLImageTargetTexture2DOES(target, egl_image_);
reveman 2014/03/24 16:46:16 Add DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), gl
171 }
128 shared_memory_->Unmap(); 172 shared_memory_->Unmap();
173 if (egl_image_ != EGL_NO_IMAGE_KHR) {
reveman 2014/03/24 16:46:16 remove this destruction code.
174 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
175 egl_image_ = EGL_NO_IMAGE_KHR;
176 }
129 return true; 177 return true;
130 } 178 }
131 179
132 void GLImageShm::ReleaseTexImage(unsigned target) { 180 void GLImageShm::ReleaseTexImage(unsigned target) {
133 } 181 }
134 182
135 void GLImageShm::WillUseTexImage() { 183 void GLImageShm::WillUseTexImage() {
136 } 184 }
137 185
138 void GLImageShm::DidUseTexImage() { 186 void GLImageShm::DidUseTexImage() {
139 } 187 }
140 188
141 void GLImageShm::WillModifyTexImage() { 189 void GLImageShm::WillModifyTexImage() {
142 } 190 }
143 191
144 void GLImageShm::DidModifyTexImage() { 192 void GLImageShm::DidModifyTexImage() {
145 } 193 }
146 194
147 } // namespace gfx 195 } // 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