Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: ui/gl/gl_image_android_native_buffer.cc

Issue 212933009: ui: Refactor GLImageEGL for usage by targets other than EGL_NATIVE_BUFFER_ANDROID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gl/gl_image_android_native_buffer.cc
diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_android_native_buffer.cc
similarity index 63%
copy from ui/gl/gl_image_egl.cc
copy to ui/gl/gl_image_android_native_buffer.cc
index d2ec68460324087e5f35da4982b9e3048a57fe64..c74a8f65adc44827bf38d00a601ca087dc92fa7e 100644
--- a/ui/gl/gl_image_egl.cc
+++ b/ui/gl/gl_image_android_native_buffer.cc
@@ -1,69 +1,48 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/gl/gl_image_egl.h"
+#include "ui/gl/gl_image_android_native_buffer.h"
-#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/scoped_binders.h"
namespace gfx {
-GLImageEGL::GLImageEGL(gfx::Size size)
- : egl_image_(EGL_NO_IMAGE_KHR),
- size_(size),
+GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(gfx::Size size)
+ : GLImageEGL(size),
release_after_use_(false),
in_use_(false),
target_(0),
egl_image_for_unbind_(EGL_NO_IMAGE_KHR),
texture_id_for_unbind_(0) {}
-GLImageEGL::~GLImageEGL() { Destroy(); }
+GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); }
-bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) {
+bool GLImageAndroidNativeBuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) {
DCHECK(buffer.native_buffer);
EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
- egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
- EGL_NO_CONTEXT,
- EGL_NATIVE_BUFFER_ANDROID,
- buffer.native_buffer,
- attrs);
- if (egl_image_ == EGL_NO_IMAGE_KHR) {
- EGLint error = eglGetError();
- LOG(ERROR) << "Error creating EGLImage: " << error;
- return false;
- }
-
- return true;
+ return GLImageEGL::Initialize(
+ EGL_NATIVE_BUFFER_ANDROID, buffer.native_buffer, attrs);
}
-void GLImageEGL::Destroy() {
- if (egl_image_ != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
- egl_image_ = EGL_NO_IMAGE_KHR;
- }
-
+void GLImageAndroidNativeBuffer::Destroy() {
if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) {
eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
egl_image_for_unbind_);
egl_image_for_unbind_ = EGL_NO_IMAGE_KHR;
}
-
if (texture_id_for_unbind_) {
glDeleteTextures(1, &texture_id_for_unbind_);
texture_id_for_unbind_ = 0;
}
-}
-gfx::Size GLImageEGL::GetSize() { return size_; }
+ GLImageEGL::Destroy();
+}
-bool GLImageEGL::BindTexImage(unsigned target) {
- if (egl_image_ == EGL_NO_IMAGE_KHR) {
- LOG(ERROR) << "NULL EGLImage in BindTexImage";
- return false;
- }
+bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) {
+ DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
if (target == GL_TEXTURE_RECTANGLE_ARB) {
LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target";
@@ -85,12 +64,7 @@ bool GLImageEGL::BindTexImage(unsigned target) {
return true;
}
-void GLImageEGL::ReleaseTexImage(unsigned target) {
- // Nothing to do here as image is released after each use or there is no need
- // to release image.
-}
-
-void GLImageEGL::WillUseTexImage() {
+void GLImageAndroidNativeBuffer::WillUseTexImage() {
DCHECK(egl_image_);
DCHECK(!in_use_);
in_use_ = true;
@@ -98,7 +72,7 @@ void GLImageEGL::WillUseTexImage() {
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
-void GLImageEGL::DidUseTexImage() {
+void GLImageAndroidNativeBuffer::DidUseTexImage() {
DCHECK(in_use_);
in_use_ = false;
@@ -120,8 +94,7 @@ void GLImageEGL::DidUseTexImage() {
GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero);
}
- EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_IMAGE_PRESERVED_KHR,
reveman 2014/03/27 22:52:04 Removing "EGL_GL_TEXTURE_LEVEL_KHR, 0" as that's d
- EGL_TRUE, EGL_NONE};
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
// Need to pass current EGL rendering context to eglCreateImageKHR for
// target type EGL_GL_TEXTURE_2D_KHR.
egl_image_for_unbind_ = eglCreateImageKHR(
@@ -138,6 +111,8 @@ void GLImageEGL::DidUseTexImage() {
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
}
-void GLImageEGL::SetReleaseAfterUse() { release_after_use_ = true; }
+void GLImageAndroidNativeBuffer::SetReleaseAfterUse() {
+ release_after_use_ = true;
+}
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698