gl_image_egl.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "ui/gl/gl_image_egl.h"
  5. #include "ui/gl/egl_util.h"
  6. #include "ui/gl/gl_bindings.h"
  7. #include "ui/gl/gl_enums.h"
  8. #include "ui/gl/gl_surface_egl.h"
  9. namespace gl {
  10. GLImageEGL::GLImageEGL(const gfx::Size& size)
  11. : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {}
  12. GLImageEGL::~GLImageEGL() {
  13. DCHECK(thread_checker_.CalledOnValidThread());
  14. if (egl_image_ == EGL_NO_IMAGE_KHR)
  15. return;
  16. const EGLBoolean result = eglDestroyImageKHR(
  17. GLSurfaceEGL::GetGLDisplayEGL()->GetDisplay(), egl_image_);
  18. if (result == EGL_FALSE)
  19. DLOG(ERROR) << "Error destroying EGLImage: " << ui::GetLastEGLErrorString();
  20. }
  21. bool GLImageEGL::Initialize(EGLContext context,
  22. EGLenum target,
  23. EGLClientBuffer buffer,
  24. const EGLint* attrs) {
  25. DCHECK(thread_checker_.CalledOnValidThread());
  26. DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
  27. egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetGLDisplayEGL()->GetDisplay(),
  28. context, target, buffer, attrs);
  29. const bool success = egl_image_ != EGL_NO_IMAGE_KHR;
  30. if (!success)
  31. LOG(ERROR) << "Error creating EGLImage: " << ui::GetLastEGLErrorString();
  32. return success;
  33. }
  34. gfx::Size GLImageEGL::GetSize() {
  35. return size_;
  36. }
  37. void* GLImageEGL::GetEGLImage() const {
  38. return egl_image_;
  39. }
  40. GLImageEGL::BindOrCopy GLImageEGL::ShouldBindOrCopy() {
  41. return egl_image_ == EGL_NO_IMAGE_KHR ? COPY : BIND;
  42. }
  43. bool GLImageEGL::BindTexImage(unsigned target) {
  44. DCHECK(thread_checker_.CalledOnValidThread());
  45. DCHECK_EQ(BIND, ShouldBindOrCopy());
  46. glEGLImageTargetTexture2DOES(target, egl_image_);
  47. return true;
  48. }
  49. } // namespace gl