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

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: creating eglimage and texture everytime during bindteximage + comments 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_egl.cc ('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/scoped_binders.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 default: 57 default:
58 NOTREACHED(); 58 NOTREACHED();
59 return 0; 59 return 0;
60 } 60 }
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat) 65 GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat)
66 : size_(size), 66 : size_(size),
67 internalformat_(internalformat) { 67 internalformat_(internalformat),
68 } 68 egl_texture_id_(0u),
69 egl_image_(EGL_NO_IMAGE_KHR) {}
69 70
70 GLImageShm::~GLImageShm() { 71 GLImageShm::~GLImageShm() {
71 Destroy(); 72 Destroy();
72 } 73 }
73 74
74 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { 75 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
75 if (!ValidFormat(internalformat_)) { 76 if (!ValidFormat(internalformat_)) {
76 DVLOG(0) << "Invalid format: " << internalformat_; 77 DVLOG(0) << "Invalid format: " << internalformat_;
77 return false; 78 return false;
78 } 79 }
(...skipping 10 matching lines...) Expand all
89 DVLOG(0) << "Failed to duplicate shared memory handle."; 90 DVLOG(0) << "Failed to duplicate shared memory handle.";
90 return false; 91 return false;
91 } 92 }
92 93
93 shared_memory_.reset( 94 shared_memory_.reset(
94 new base::SharedMemory(duped_shared_memory_handle, true)); 95 new base::SharedMemory(duped_shared_memory_handle, true));
95 return true; 96 return true;
96 } 97 }
97 98
98 void GLImageShm::Destroy() { 99 void GLImageShm::Destroy() {
100 if (egl_image_ != EGL_NO_IMAGE_KHR) {
101 eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_);
reveman 2014/03/22 12:38:57 GLSurfaceEGL::GetHardwareDisplay()
102 egl_image_ = EGL_NO_IMAGE_KHR;
103 }
104 if (egl_texture_id_) {
105 glDeleteTextures(1, &egl_texture_id_);
106 egl_texture_id_ = 0;
reveman 2014/03/22 12:38:57 nit: s/0/0u/ to match the assign in ctor
107 }
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 DCHECK(shared_memory_->memory());
118 glTexImage2D(target, 127 if (target != GL_TEXTURE_EXTERNAL_OES) {
reveman 2014/03/22 12:38:57 nit: reversing these if-clauses might improve read
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, &egl_texture_id_);
reveman 2014/03/22 12:38:57 Why did you change this? Do you really need to gen
127 139
140 {
141 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
145
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());
155 }
reveman 2014/03/22 12:38:57 thanks for making the intended scope of the binder
156
157 EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
reveman 2014/03/22 12:38:57 nit: maybe rename to "attrs" to be consistent with
158 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
159 egl_image_ =
160 eglCreateImageKHR(eglGetCurrentDisplay(),
reveman 2014/03/22 12:38:57 GLSurfaceEGL::GetHardwareDisplay()
161 eglGetCurrentContext(),
reveman 2014/03/22 12:38:57 and NO_CONTEXT if possible. if that doesn't work,
162 EGL_GL_TEXTURE_2D_KHR,
163 reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
164 egl_attrib_list);
165 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
166 << "Error creating EGLImage: " << eglGetError();
167
168 glEGLImageTargetTexture2DOES(target, egl_image_);
169 }
128 shared_memory_->Unmap(); 170 shared_memory_->Unmap();
129 return true; 171 return true;
130 } 172 }
131 173
132 void GLImageShm::ReleaseTexImage(unsigned target) { 174 void GLImageShm::ReleaseTexImage(unsigned target) {
133 } 175 }
134 176
135 void GLImageShm::WillUseTexImage() { 177 void GLImageShm::WillUseTexImage() {
136 } 178 }
137 179
138 void GLImageShm::DidUseTexImage() { 180 void GLImageShm::DidUseTexImage() { Destroy(); }
reveman 2014/03/22 12:38:57 Please don't use Destroy here. That's confusing an
139 }
140 181
141 void GLImageShm::WillModifyTexImage() { 182 void GLImageShm::WillModifyTexImage() {
142 } 183 }
143 184
144 void GLImageShm::DidModifyTexImage() { 185 void GLImageShm::DidModifyTexImage() {
145 } 186 }
146 187
147 } // namespace gfx 188 } // namespace gfx
OLDNEW
« ui/gl/gl_image_egl.cc ('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