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 bool GLImageEGL::BindTexImage(unsigned target
) {
55 DCHECK(thread_checker_
.CalledOnValidThread());
56 DCHECK_NE(EGL_NO_IMAGE_KHR
, egl_image_
);
57 glEGLImageTargetTexture2DOES(target
, egl_image_
);
58 DCHECK_EQ(static_cast<GLenum
>(GL_NO_ERROR
), glGetError());
62 bool GLImageEGL::CopyTexImage(unsigned target
) {
66 bool GLImageEGL::ScheduleOverlayPlane(gfx::AcceleratedWidget widget
,
68 OverlayTransform transform
,
69 const Rect
& bounds_rect
,
70 const RectF
& crop_rect
) {