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

Side by Side Diff: ui/gl/gl_image_egl.cc

Issue 13543007: GLImage support for Android zero-copy pixel buffers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add expectations to the unittests for GetErrors() coming from the suppressor Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gl/gl_image_egl.h"
6
7 #include "ui/gl/gl_bindings.h"
8
9 // TODO(kaanb): remove when crbug.com/227205 is fixed.
10 #define EGL_NATIVE_BUFFER_ANDROID 0x3140
11
12 namespace gfx {
13
14 GLImageEGL::GLImageEGL(gfx::Size size)
15 : egl_image_(EGL_NO_IMAGE_KHR),
16 size_(size) {
17 }
18
19 GLImageEGL::~GLImageEGL() {
20 Destroy();
21 }
22
23 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) {
24 EGLClientBuffer cbuf = static_cast<EGLClientBuffer>(buffer);
25 EGLint attrs[] = {
26 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
27 EGL_NONE,
28 };
29 egl_image_ = eglCreateImageKHR(
30 eglGetDisplay(EGL_DEFAULT_DISPLAY),
31 EGL_NO_CONTEXT,
32 EGL_NATIVE_BUFFER_ANDROID,
33 cbuf,
34 attrs);
35
36 if (egl_image_ == EGL_NO_IMAGE_KHR) {
37 EGLint error = eglGetError();
38 LOG(ERROR) << "Error creating EGLImage: " << error;
39 return false;
40 }
41
42 return true;
43 }
44
45 bool GLImageEGL::BindTexImage() {
46 if (egl_image_ == EGL_NO_IMAGE_KHR) {
47 LOG(ERROR) << "NULL EGLImage in BindTexImage";
48 return false;
49 }
50
51 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image_);
52
53 if (glGetError() != GL_NO_ERROR) {
54 return false;
55 }
56
57 return true;
58 }
59
60 gfx::Size GLImageEGL::GetSize() {
61 return size_;
62 }
63
64 void GLImageEGL::Destroy() {
65 if (egl_image_ == EGL_NO_IMAGE_KHR)
66 return;
67
68 EGLBoolean success = eglDestroyImageKHR(
69 eglGetDisplay(EGL_DEFAULT_DISPLAY), egl_image_);
70
71 if (success == EGL_FALSE) {
72 EGLint error = eglGetError();
73 LOG(ERROR) << "Error destroying EGLImage: " << error;
74 }
75
76 egl_image_ = EGL_NO_IMAGE_KHR;
77 }
78
79 void GLImageEGL::ReleaseTexImage() {
80 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE,
81 NULL);
82 }
83
84 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698