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

Side by Side Diff: ui/gl/gl_image_egl.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: nvidia workaround patch 2 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_egl.h" 5 #include "ui/gl/gl_image_egl.h"
6 6
7 #include "ui/gl/gl_bindings.h" 7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_surface_egl.h" 8 #include "ui/gl/gl_surface_egl.h"
9 #include "ui/gl/scoped_binders.h"
9 10
10 namespace gfx { 11 namespace gfx {
11 12
12 GLImageEGL::GLImageEGL(gfx::Size size) 13 GLImageEGL::GLImageEGL(gfx::Size size)
13 : egl_image_(EGL_NO_IMAGE_KHR), 14 : egl_image_(EGL_NO_IMAGE_KHR),
14 size_(size), 15 size_(size),
15 release_after_use_(false), 16 release_after_use_(false),
16 in_use_(false), 17 in_use_(false),
17 target_(0) { 18 target_(0),
18 } 19 egl_image_for_unbind_(EGL_NO_IMAGE_KHR),
20 texture_id_(0) {}
19 21
20 GLImageEGL::~GLImageEGL() { 22 GLImageEGL::~GLImageEGL() {
21 Destroy(); 23 Destroy();
22 } 24 }
23 25
24 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { 26 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) {
25 DCHECK(buffer.native_buffer); 27 DCHECK(buffer.native_buffer);
26 EGLint attrs[] = { 28 EGLint attrs[] = {
27 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, 29 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
28 EGL_NONE, 30 EGL_NONE,
29 }; 31 };
30 egl_image_ = eglCreateImageKHR( 32 egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
31 GLSurfaceEGL::GetHardwareDisplay(), 33 EGL_NO_CONTEXT,
32 EGL_NO_CONTEXT, 34 EGL_NATIVE_BUFFER_ANDROID,
33 EGL_NATIVE_BUFFER_ANDROID, 35 buffer.native_buffer,
34 buffer.native_buffer, 36 attrs);
35 attrs);
36 37
37 if (egl_image_ == EGL_NO_IMAGE_KHR) { 38 if (egl_image_ == EGL_NO_IMAGE_KHR) {
38 EGLint error = eglGetError(); 39 EGLint error = eglGetError();
39 LOG(ERROR) << "Error creating EGLImage: " << error; 40 LOG(ERROR) << "Error creating EGLImage: " << error;
40 return false; 41 return false;
41 } 42 }
42 43
43 return true; 44 return true;
44 } 45 }
45 46
46 void GLImageEGL::Destroy() { 47 void GLImageEGL::Destroy() {
47 if (egl_image_ == EGL_NO_IMAGE_KHR) 48 if (egl_image_ == EGL_NO_IMAGE_KHR ||
49 egl_image_for_unbind_ == EGL_NO_IMAGE_KHR)
reveman 2014/03/20 13:02:05 This is not right. You will call eglDestroyImageKH
48 return; 50 return;
49 51
50 EGLBoolean success = eglDestroyImageKHR( 52 EGLBoolean success = eglDestroyImageKHR(
51 GLSurfaceEGL::GetHardwareDisplay(), egl_image_); 53 GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
52 54
53 if (success == EGL_FALSE) { 55 EGLBoolean status = eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
56 egl_image_for_unbind_);
57
58 if (success == EGL_FALSE || status == EGL_FALSE) {
54 EGLint error = eglGetError(); 59 EGLint error = eglGetError();
55 LOG(ERROR) << "Error destroying EGLImage: " << error; 60 LOG(ERROR) << "Error destroying EGLImage: " << error;
56 } 61 }
57 62
58 egl_image_ = EGL_NO_IMAGE_KHR; 63 egl_image_ = EGL_NO_IMAGE_KHR;
64 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
65
66 if (texture_id_) {
67 glDeleteTextures(1, &texture_id_);
68 texture_id_ = 0;
69 }
59 } 70 }
60 71
61 gfx::Size GLImageEGL::GetSize() { 72 gfx::Size GLImageEGL::GetSize() {
62 return size_; 73 return size_;
63 } 74 }
64 75
65 bool GLImageEGL::BindTexImage(unsigned target) { 76 bool GLImageEGL::BindTexImage(unsigned target) {
66 if (egl_image_ == EGL_NO_IMAGE_KHR) { 77 if (egl_image_ == EGL_NO_IMAGE_KHR) {
67 LOG(ERROR) << "NULL EGLImage in BindTexImage"; 78 LOG(ERROR) << "NULL EGLImage in BindTexImage";
68 return false; 79 return false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 112 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
102 } 113 }
103 114
104 void GLImageEGL::DidUseTexImage() { 115 void GLImageEGL::DidUseTexImage() {
105 DCHECK(in_use_); 116 DCHECK(in_use_);
106 in_use_ = false; 117 in_use_ = false;
107 118
108 if (!release_after_use_) 119 if (!release_after_use_)
109 return; 120 return;
110 121
111 char zero[4] = { 0, }; 122 if (!egl_image_for_unbind_) {
112 glTexImage2D(target_, 123 if (!texture_id_)
reveman 2014/03/20 13:02:05 this can be DCHECK_EQ(0u, texture_id_)
113 0, 124 glGenTextures(1, &texture_id_);
114 GL_RGBA, 125
115 1, 126 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_);
116 1, 127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
117 0, 128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
118 GL_RGBA, 129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
119 GL_UNSIGNED_BYTE, 130
120 &zero); 131 char zero[4] = {0, };
132 glTexImage2D(
133 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero);
134
135 EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
136 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
137 EGLImageKHR egl_image_for_unbind_ =
138 eglCreateImageKHR(eglGetCurrentDisplay(),
139 eglGetCurrentContext(),
140 EGL_GL_TEXTURE_2D_KHR,
141 reinterpret_cast<EGLClientBuffer>(texture_id_),
142 attrs);
143 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_for_unbind_)
144 << "Error creating EGLImage: " << eglGetError();
145 }
146 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
147 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
121 } 148 }
122 149
123 void GLImageEGL::WillModifyTexImage() { 150 void GLImageEGL::WillModifyTexImage() {
124 } 151 }
125 152
126 void GLImageEGL::DidModifyTexImage() { 153 void GLImageEGL::DidModifyTexImage() {
127 } 154 }
128 155
129 void GLImageEGL::SetReleaseAfterUse() { 156 void GLImageEGL::SetReleaseAfterUse() {
130 release_after_use_ = true; 157 release_after_use_ = true;
131 } 158 }
132 159
133 } // namespace gfx 160 } // namespace gfx
OLDNEW
« ui/gl/gl_image_egl.h ('K') | « ui/gl/gl_image_egl.h ('k') | ui/gl/gl_image_shm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698