ozone: evdev: Don't crash without cursor in scroll & click events
[chromium-blink-merge.git] / ui / gl / gl_image_egl.cc
blob5531c8d4528defaf11f5a11b42a86934c5921528
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/gl_surface_egl.h"
9 namespace gfx {
11 GLImageEGL::GLImageEGL(gfx::Size size)
12 : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {}
14 GLImageEGL::~GLImageEGL() { Destroy(); }
16 bool GLImageEGL::Initialize(EGLenum target,
17 EGLClientBuffer buffer,
18 const EGLint* attrs) {
19 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
20 egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
21 EGL_NO_CONTEXT,
22 target,
23 buffer,
24 attrs);
25 if (egl_image_ == EGL_NO_IMAGE_KHR) {
26 EGLint error = eglGetError();
27 LOG(ERROR) << "Error creating EGLImage: " << error;
28 return false;
31 return true;
34 void GLImageEGL::Destroy() {
35 if (egl_image_ != EGL_NO_IMAGE_KHR) {
36 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
37 egl_image_ = EGL_NO_IMAGE_KHR;
41 gfx::Size GLImageEGL::GetSize() { return size_; }
43 bool GLImageEGL::BindTexImage(unsigned target) {
44 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
45 glEGLImageTargetTexture2DOES(target, egl_image_);
46 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
47 return true;
50 } // namespace gfx