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.
5 #include "ui/gl/gl_image_egl.h"
7 #include "ui/gl/egl_util.h"
8 #include "ui/gl/gl_surface_egl.h"
12 GLImageEGL::GLImageEGL(const gfx::Size
& size
)
13 : egl_image_(EGL_NO_IMAGE_KHR
), size_(size
) {
16 GLImageEGL::~GLImageEGL() {
17 DCHECK(thread_checker_
.CalledOnValidThread());
18 DCHECK_EQ(EGL_NO_IMAGE_KHR
, egl_image_
);
21 bool GLImageEGL::Initialize(EGLenum target
,
22 EGLClientBuffer buffer
,
23 const EGLint
* attrs
) {
24 DCHECK(thread_checker_
.CalledOnValidThread());
25 DCHECK_EQ(EGL_NO_IMAGE_KHR
, egl_image_
);
26 egl_image_
= eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
31 if (egl_image_
== EGL_NO_IMAGE_KHR
) {
32 DLOG(ERROR
) << "Error creating EGLImage: " << ui::GetLastEGLErrorString();
39 void GLImageEGL::Destroy(bool have_context
) {
40 DCHECK(thread_checker_
.CalledOnValidThread());
41 if (egl_image_
!= EGL_NO_IMAGE_KHR
) {
43 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_
);
44 if (result
== EGL_FALSE
) {
45 DLOG(ERROR
) << "Error destroying EGLImage: "
46 << ui::GetLastEGLErrorString();
48 egl_image_
= EGL_NO_IMAGE_KHR
;
52 gfx::Size
GLImageEGL::GetSize() { return size_
; }
54 unsigned GLImageEGL::GetInternalFormat() { return GL_RGBA
; }
56 bool GLImageEGL::BindTexImage(unsigned target
) {
57 DCHECK(thread_checker_
.CalledOnValidThread());
58 DCHECK_NE(EGL_NO_IMAGE_KHR
, egl_image_
);
59 glEGLImageTargetTexture2DOES(target
, egl_image_
);
60 DCHECK_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
64 bool GLImageEGL::CopyTexSubImage(unsigned target
,
70 bool GLImageEGL::ScheduleOverlayPlane(gfx::AcceleratedWidget widget
,
72 OverlayTransform transform
,
73 const Rect
& bounds_rect
,
74 const RectF
& crop_rect
) {