OLD | NEW |
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_surface_egl.h" | 7 #include "ui/gl/gl_surface_egl.h" |
8 | 8 |
9 namespace gfx { | 9 namespace gfx { |
10 | 10 |
11 GLImageEGL::GLImageEGL(const gfx::Size& size) | 11 GLImageEGL::GLImageEGL(const gfx::Size& size) |
12 : egl_image_(EGL_NO_IMAGE_KHR), size_(size) { | 12 : egl_image_(EGL_NO_IMAGE_KHR), size_(size) { |
13 } | 13 } |
14 | 14 |
15 GLImageEGL::~GLImageEGL() { Destroy(); } | 15 GLImageEGL::~GLImageEGL() { |
| 16 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 17 } |
16 | 18 |
17 bool GLImageEGL::Initialize(EGLenum target, | 19 bool GLImageEGL::Initialize(EGLenum target, |
18 EGLClientBuffer buffer, | 20 EGLClientBuffer buffer, |
19 const EGLint* attrs) { | 21 const EGLint* attrs) { |
20 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | 22 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
21 egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(), | 23 egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
22 EGL_NO_CONTEXT, | 24 EGL_NO_CONTEXT, |
23 target, | 25 target, |
24 buffer, | 26 buffer, |
25 attrs); | 27 attrs); |
26 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 28 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
27 EGLint error = eglGetError(); | 29 EGLint error = eglGetError(); |
28 LOG(ERROR) << "Error creating EGLImage: " << error; | 30 LOG(ERROR) << "Error creating EGLImage: " << error; |
29 return false; | 31 return false; |
30 } | 32 } |
31 | 33 |
32 return true; | 34 return true; |
33 } | 35 } |
34 | 36 |
35 void GLImageEGL::Destroy() { | 37 void GLImageEGL::Destroy(bool have_context) { |
36 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 38 if (egl_image_ != EGL_NO_IMAGE_KHR) { |
37 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 39 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); |
38 egl_image_ = EGL_NO_IMAGE_KHR; | 40 egl_image_ = EGL_NO_IMAGE_KHR; |
39 } | 41 } |
40 } | 42 } |
41 | 43 |
42 gfx::Size GLImageEGL::GetSize() { return size_; } | 44 gfx::Size GLImageEGL::GetSize() { return size_; } |
43 | 45 |
44 bool GLImageEGL::BindTexImage(unsigned target) { | 46 bool GLImageEGL::BindTexImage(unsigned target) { |
45 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); | 47 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); |
46 glEGLImageTargetTexture2DOES(target, egl_image_); | 48 glEGLImageTargetTexture2DOES(target, egl_image_); |
47 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 49 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
48 return true; | 50 return true; |
49 } | 51 } |
50 | 52 |
51 } // namespace gfx | 53 } // namespace gfx |
OLD | NEW |