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

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: comments + nits 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_egl.h ('k') | ui/gl/gl_image_shm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_for_unbind_(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 EGLBoolean success = EGL_FALSE;
reveman 2014/03/20 13:52:44 nit: move this inside the (egl_image_ != EGL_NO_IM
48 return; 49 if (egl_image_ != EGL_NO_IMAGE_KHR) {
49 50 success =
50 EGLBoolean success = eglDestroyImageKHR( 51 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
51 GLSurfaceEGL::GetHardwareDisplay(), egl_image_); 52 if (success == EGL_FALSE)
52 53 LOG(ERROR) << "Error destroying EGLImage: " << eglGetError();
53 if (success == EGL_FALSE) { 54 egl_image_ = EGL_NO_IMAGE_KHR;
54 EGLint error = eglGetError();
55 LOG(ERROR) << "Error destroying EGLImage: " << error;
56 } 55 }
57 56
58 egl_image_ = EGL_NO_IMAGE_KHR; 57 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) {
58 success = eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_for_unbind_);
59 if (success == EGL_FALSE)
60 LOG(ERROR) << "Error destroying EGLImage: " << eglGetError();
61 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
62 }
63
64 if (texture_id_for_unbind_) {
65 glDeleteTextures(1, &texture_id_for_unbind_);
66 texture_id_for_unbind_ = 0;
67 }
59 } 68 }
60 69
61 gfx::Size GLImageEGL::GetSize() { 70 gfx::Size GLImageEGL::GetSize() {
62 return size_; 71 return size_;
63 } 72 }
64 73
65 bool GLImageEGL::BindTexImage(unsigned target) { 74 bool GLImageEGL::BindTexImage(unsigned target) {
66 if (egl_image_ == EGL_NO_IMAGE_KHR) { 75 if (egl_image_ == EGL_NO_IMAGE_KHR) {
67 LOG(ERROR) << "NULL EGLImage in BindTexImage"; 76 LOG(ERROR) << "NULL EGLImage in BindTexImage";
68 return false; 77 return false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); 110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
102 } 111 }
103 112
104 void GLImageEGL::DidUseTexImage() { 113 void GLImageEGL::DidUseTexImage() {
105 DCHECK(in_use_); 114 DCHECK(in_use_);
106 in_use_ = false; 115 in_use_ = false;
107 116
108 if (!release_after_use_) 117 if (!release_after_use_)
109 return; 118 return;
110 119
111 char zero[4] = { 0, }; 120 if (!egl_image_for_unbind_) {
reveman 2014/03/20 13:52:44 this should be (egl_image_for_unbind_ == EGL_NO_IM
112 glTexImage2D(target_, 121 DCHECK_EQ(0u, texture_id_for_unbind_);
113 0, 122 glGenTextures(1, &texture_id_for_unbind_);
114 GL_RGBA, 123
115 1, 124 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_for_unbind_);
116 1, 125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
117 0, 126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
118 GL_RGBA, 127 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
119 GL_UNSIGNED_BYTE, 128
120 &zero); 129 char zero[4] = {0, };
130 glTexImage2D(
131 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero);
132
133 EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level.
134 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
135 EGLImageKHR egl_image_for_unbind_ = eglCreateImageKHR(
136 eglGetCurrentDisplay(),
137 eglGetCurrentContext(),
138 EGL_GL_TEXTURE_2D_KHR,
139 reinterpret_cast<EGLClientBuffer>(texture_id_for_unbind_),
140 attrs);
141 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_for_unbind_)
142 << "Error creating EGLImage: " << eglGetError();
143 }
reveman 2014/03/20 13:52:44 nit: I would add blank line here to separate the l
144 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_);
145 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
121 } 146 }
122 147
123 void GLImageEGL::WillModifyTexImage() { 148 void GLImageEGL::WillModifyTexImage() {
124 } 149 }
125 150
126 void GLImageEGL::DidModifyTexImage() { 151 void GLImageEGL::DidModifyTexImage() {
127 } 152 }
128 153
129 void GLImageEGL::SetReleaseAfterUse() { 154 void GLImageEGL::SetReleaseAfterUse() {
130 release_after_use_ = true; 155 release_after_use_ = true;
131 } 156 }
132 157
133 } // namespace gfx 158 } // namespace gfx
OLDNEW
« no previous file with comments | « 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