mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Merge pull request #989 from jamesr/rm_gl_fence
Remove unused Ozone and GLFence/GLImage abstractions
This commit is contained in:
@@ -55,27 +55,8 @@ component("gl") {
|
||||
"gl_enums.h",
|
||||
"gl_enums_implementation_autogen.h",
|
||||
"gl_export.h",
|
||||
"gl_fence.cc",
|
||||
"gl_fence.h",
|
||||
"gl_fence_arb.cc",
|
||||
"gl_fence_arb.h",
|
||||
"gl_fence_egl.cc",
|
||||
"gl_fence_egl.h",
|
||||
"gl_fence_nv.cc",
|
||||
"gl_fence_nv.h",
|
||||
"gl_gl_api_implementation.cc",
|
||||
"gl_gl_api_implementation.h",
|
||||
"gl_image.h",
|
||||
"gl_image_egl.cc",
|
||||
"gl_image_egl.h",
|
||||
"gl_image_memory.cc",
|
||||
"gl_image_memory.h",
|
||||
"gl_image_ref_counted_memory.cc",
|
||||
"gl_image_ref_counted_memory.h",
|
||||
"gl_image_shared_memory.cc",
|
||||
"gl_image_shared_memory.h",
|
||||
"gl_image_stub.cc",
|
||||
"gl_image_stub.h",
|
||||
"gl_implementation.cc",
|
||||
"gl_implementation.h",
|
||||
"gl_implementation_android.cc",
|
||||
@@ -150,10 +131,6 @@ component("gl") {
|
||||
}
|
||||
if (is_linux) {
|
||||
deps += [ "//third_party/libevent" ]
|
||||
sources += [
|
||||
"gl_image_linux_dma_buffer.cc",
|
||||
"gl_image_linux_dma_buffer.h",
|
||||
]
|
||||
}
|
||||
if (use_x11) {
|
||||
sources += [
|
||||
@@ -164,8 +141,6 @@ component("gl") {
|
||||
"gl_egl_api_implementation.h",
|
||||
"gl_glx_api_implementation.cc",
|
||||
"gl_glx_api_implementation.h",
|
||||
"gl_image_glx.cc",
|
||||
"gl_image_glx.h",
|
||||
"gl_implementation_x11.cc",
|
||||
"gl_surface_glx.cc",
|
||||
"gl_surface_glx.h",
|
||||
@@ -185,8 +160,6 @@ component("gl") {
|
||||
sources += [
|
||||
"gl_egl_api_implementation.cc",
|
||||
"gl_egl_api_implementation.h",
|
||||
"gl_image_surface_texture.cc",
|
||||
"gl_image_surface_texture.h",
|
||||
]
|
||||
|
||||
defines += [
|
||||
@@ -198,19 +171,6 @@ component("gl") {
|
||||
|
||||
deps += [ ":gl_jni_headers" ]
|
||||
}
|
||||
if (use_ozone) {
|
||||
sources += [
|
||||
"gl_context_ozone.cc",
|
||||
"gl_egl_api_implementation.cc",
|
||||
"gl_egl_api_implementation.h",
|
||||
"gl_implementation_ozone.cc",
|
||||
"gl_surface_ozone.cc",
|
||||
]
|
||||
deps += [
|
||||
"//ui/ozone",
|
||||
"//ui/ozone:ozone_base",
|
||||
]
|
||||
}
|
||||
if (is_ios || is_mac) {
|
||||
sources = []
|
||||
sources = [
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2013 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_context.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/sys_info.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_context_egl.h"
|
||||
#include "ui/gl/gl_context_osmesa.h"
|
||||
#include "ui/gl/gl_context_stub.h"
|
||||
#include "ui/gl/gl_implementation.h"
|
||||
#include "ui/gl/gl_surface.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
// static
|
||||
scoped_refptr<GLContext> GLContext::CreateGLContext(
|
||||
GLShareGroup* share_group,
|
||||
GLSurface* compatible_surface,
|
||||
GpuPreference gpu_preference) {
|
||||
|
||||
switch (GetGLImplementation()) {
|
||||
case kGLImplementationMockGL:
|
||||
return scoped_refptr<GLContext>(new GLContextStub());
|
||||
case kGLImplementationOSMesaGL: {
|
||||
scoped_refptr<GLContext> context(new GLContextOSMesa(share_group));
|
||||
if (!context->Initialize(compatible_surface, gpu_preference))
|
||||
return NULL;
|
||||
return context;
|
||||
}
|
||||
case kGLImplementationEGLGLES2: {
|
||||
scoped_refptr<GLContext> context(new GLContextEGL(share_group));
|
||||
if (!context->Initialize(compatible_surface, gpu_preference))
|
||||
return NULL;
|
||||
return context;
|
||||
}
|
||||
default:
|
||||
NOTREACHED();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2012 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_fence.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_context.h"
|
||||
#include "ui/gl/gl_fence_arb.h"
|
||||
#include "ui/gl/gl_fence_egl.h"
|
||||
#include "ui/gl/gl_fence_nv.h"
|
||||
#include "ui/gl/gl_gl_api_implementation.h"
|
||||
#include "ui/gl/gl_version_info.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
GLFence::GLFence() {
|
||||
}
|
||||
|
||||
GLFence::~GLFence() {
|
||||
}
|
||||
|
||||
bool GLFence::IsSupported() {
|
||||
DCHECK(GetGLVersionInfo());
|
||||
return g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 ||
|
||||
g_driver_egl.ext.b_EGL_KHR_fence_sync ||
|
||||
g_driver_gl.ext.b_GL_NV_fence;
|
||||
}
|
||||
|
||||
GLFence* GLFence::Create() {
|
||||
DCHECK(GLContext::GetCurrent())
|
||||
<< "Trying to create fence with no context";
|
||||
|
||||
scoped_ptr<GLFence> fence;
|
||||
// Prefer ARB_sync which supports server-side wait.
|
||||
if (g_driver_gl.ext.b_GL_ARB_sync ||
|
||||
GetGLVersionInfo()->is_es3) {
|
||||
fence.reset(new GLFenceARB);
|
||||
} else if (g_driver_egl.ext.b_EGL_KHR_fence_sync) {
|
||||
fence.reset(new GLFenceEGL);
|
||||
} else if (g_driver_gl.ext.b_GL_NV_fence) {
|
||||
fence.reset(new GLFenceNV);
|
||||
}
|
||||
|
||||
DCHECK_EQ(!!fence.get(), GLFence::IsSupported());
|
||||
return fence.release();
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#ifndef UI_GL_GL_FENCE_H_
|
||||
#define UI_GL_GL_FENCE_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "ui/gl/gl_export.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLFence {
|
||||
public:
|
||||
GLFence();
|
||||
virtual ~GLFence();
|
||||
|
||||
static bool IsSupported();
|
||||
static GLFence* Create();
|
||||
|
||||
virtual bool HasCompleted() = 0;
|
||||
virtual void ClientWait() = 0;
|
||||
|
||||
// Will block the server if supported, but might fall back to blocking the
|
||||
// client.
|
||||
virtual void ServerWait() = 0;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(GLFence);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_FENCE_H_
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright 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_fence_arb.h"
|
||||
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetGLErrors() {
|
||||
// Clears and logs all current gl errors.
|
||||
std::string accumulated_errors;
|
||||
GLenum error;
|
||||
while ((error = glGetError()) != GL_NO_ERROR) {
|
||||
accumulated_errors += base::StringPrintf("0x%x ", error);
|
||||
}
|
||||
return accumulated_errors;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GLFenceARB::GLFenceARB() {
|
||||
sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
DCHECK_EQ(GL_TRUE, glIsSync(sync_));
|
||||
glFlush();
|
||||
}
|
||||
|
||||
bool GLFenceARB::HasCompleted() {
|
||||
// Handle the case where FenceSync failed.
|
||||
if (!sync_)
|
||||
return true;
|
||||
|
||||
DCHECK_EQ(GL_TRUE, glIsSync(sync_));
|
||||
// We could potentially use glGetSynciv here, but it doesn't work
|
||||
// on OSX 10.7 (always says the fence is not signaled yet).
|
||||
// glClientWaitSync works better, so let's use that instead.
|
||||
GLenum result = glClientWaitSync(sync_, 0, 0);
|
||||
if (result == GL_WAIT_FAILED) {
|
||||
LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors();
|
||||
}
|
||||
return result != GL_TIMEOUT_EXPIRED;
|
||||
}
|
||||
|
||||
void GLFenceARB::ClientWait() {
|
||||
DCHECK_EQ(GL_TRUE, glIsSync(sync_));
|
||||
GLenum result =
|
||||
glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
|
||||
DCHECK_NE(static_cast<GLenum>(GL_TIMEOUT_EXPIRED), result);
|
||||
if (result == GL_WAIT_FAILED) {
|
||||
LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors();
|
||||
}
|
||||
}
|
||||
|
||||
void GLFenceARB::ServerWait() {
|
||||
DCHECK_EQ(GL_TRUE, glIsSync(sync_));
|
||||
glWaitSync(sync_, 0, GL_TIMEOUT_IGNORED);
|
||||
}
|
||||
|
||||
GLFenceARB::~GLFenceARB() {
|
||||
DCHECK_EQ(GL_TRUE, glIsSync(sync_));
|
||||
glDeleteSync(sync_);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef UI_GL_GL_FENCE_ARB_H_
|
||||
#define UI_GL_GL_FENCE_ARB_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_fence.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLFenceARB : public GLFence {
|
||||
public:
|
||||
GLFenceARB();
|
||||
~GLFenceARB() override;
|
||||
|
||||
// GLFence implementation:
|
||||
bool HasCompleted() override;
|
||||
void ClientWait() override;
|
||||
void ServerWait() override;
|
||||
|
||||
private:
|
||||
GLsync sync_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLFenceARB);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_FENCE_ARB_H_
|
||||
@@ -1,73 +0,0 @@
|
||||
// Copyright 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_fence_egl.h"
|
||||
|
||||
#include "ui/gl/egl_util.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
namespace {
|
||||
|
||||
bool g_ignore_egl_sync_failures = false;
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
void GLFenceEGL::SetIgnoreFailures() {
|
||||
g_ignore_egl_sync_failures = true;
|
||||
}
|
||||
|
||||
GLFenceEGL::GLFenceEGL() {
|
||||
display_ = eglGetCurrentDisplay();
|
||||
sync_ = eglCreateSyncKHR(display_, EGL_SYNC_FENCE_KHR, NULL);
|
||||
DCHECK(sync_ != EGL_NO_SYNC_KHR);
|
||||
glFlush();
|
||||
}
|
||||
|
||||
bool GLFenceEGL::HasCompleted() {
|
||||
EGLint value = 0;
|
||||
if (eglGetSyncAttribKHR(display_, sync_, EGL_SYNC_STATUS_KHR, &value) !=
|
||||
EGL_TRUE) {
|
||||
LOG(ERROR) << "Failed to get EGLSync attribute. error code:"
|
||||
<< eglGetError();
|
||||
return true;
|
||||
}
|
||||
|
||||
DCHECK(value == EGL_SIGNALED_KHR || value == EGL_UNSIGNALED_KHR);
|
||||
return !value || value == EGL_SIGNALED_KHR;
|
||||
}
|
||||
|
||||
void GLFenceEGL::ClientWait() {
|
||||
EGLint flags = 0;
|
||||
EGLTimeKHR time = EGL_FOREVER_KHR;
|
||||
EGLint result = eglClientWaitSyncKHR(display_, sync_, flags, time);
|
||||
DCHECK_IMPLIES(!g_ignore_egl_sync_failures,
|
||||
EGL_TIMEOUT_EXPIRED_KHR != result);
|
||||
if (result == EGL_FALSE) {
|
||||
LOG(ERROR) << "Failed to wait for EGLSync. error:"
|
||||
<< ui::GetLastEGLErrorString();
|
||||
CHECK(g_ignore_egl_sync_failures);
|
||||
}
|
||||
}
|
||||
|
||||
void GLFenceEGL::ServerWait() {
|
||||
if (!gfx::g_driver_egl.ext.b_EGL_KHR_wait_sync) {
|
||||
ClientWait();
|
||||
return;
|
||||
}
|
||||
EGLint flags = 0;
|
||||
if (eglWaitSyncKHR(display_, sync_, flags) == EGL_FALSE) {
|
||||
LOG(ERROR) << "Failed to wait for EGLSync. error:"
|
||||
<< ui::GetLastEGLErrorString();
|
||||
CHECK(g_ignore_egl_sync_failures);
|
||||
}
|
||||
}
|
||||
|
||||
GLFenceEGL::~GLFenceEGL() {
|
||||
eglDestroySyncKHR(display_, sync_);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef UI_GL_GL_FENCE_EGL_H_
|
||||
#define UI_GL_GL_FENCE_EGL_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_fence.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLFenceEGL : public GLFence {
|
||||
public:
|
||||
static void SetIgnoreFailures();
|
||||
|
||||
GLFenceEGL();
|
||||
~GLFenceEGL() override;
|
||||
|
||||
// GLFence implementation:
|
||||
bool HasCompleted() override;
|
||||
void ClientWait() override;
|
||||
void ServerWait() override;
|
||||
|
||||
private:
|
||||
EGLSyncKHR sync_;
|
||||
EGLDisplay display_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLFenceEGL);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_FENCE_EGL_H_
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 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_fence_nv.h"
|
||||
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
GLFenceNV::GLFenceNV() {
|
||||
// What if either of these GL calls fails? TestFenceNV will return true.
|
||||
// See spec:
|
||||
// http://www.opengl.org/registry/specs/NV/fence.txt
|
||||
//
|
||||
// What should happen if TestFenceNV is called for a name before SetFenceNV
|
||||
// is called?
|
||||
// We generate an INVALID_OPERATION error, and return TRUE.
|
||||
// This follows the semantics for texture object names before
|
||||
// they are bound, in that they acquire their state upon binding.
|
||||
// We will arbitrarily return TRUE for consistency.
|
||||
glGenFencesNV(1, &fence_);
|
||||
glSetFenceNV(fence_, GL_ALL_COMPLETED_NV);
|
||||
DCHECK(glIsFenceNV(fence_));
|
||||
glFlush();
|
||||
}
|
||||
|
||||
bool GLFenceNV::HasCompleted() {
|
||||
DCHECK(glIsFenceNV(fence_));
|
||||
return !!glTestFenceNV(fence_);
|
||||
}
|
||||
|
||||
void GLFenceNV::ClientWait() {
|
||||
DCHECK(glIsFenceNV(fence_));
|
||||
glFinishFenceNV(fence_);
|
||||
}
|
||||
|
||||
void GLFenceNV::ServerWait() {
|
||||
DCHECK(glIsFenceNV(fence_));
|
||||
ClientWait();
|
||||
}
|
||||
|
||||
GLFenceNV::~GLFenceNV() {
|
||||
DCHECK(glIsFenceNV(fence_));
|
||||
glDeleteFencesNV(1, &fence_);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef UI_GL_GL_FENCE_NV_H_
|
||||
#define UI_GL_GL_FENCE_NV_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_fence.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLFenceNV : public GLFence {
|
||||
public:
|
||||
GLFenceNV();
|
||||
~GLFenceNV() override;
|
||||
|
||||
// GLFence implementation:
|
||||
bool HasCompleted() override;
|
||||
void ClientWait() override;
|
||||
void ServerWait() override;
|
||||
|
||||
private:
|
||||
GLuint fence_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLFenceNV);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_FENCE_NV_H_
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#ifndef UI_GL_GL_IMAGE_H_
|
||||
#define UI_GL_GL_IMAGE_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/rect_f.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/gfx/overlay_transform.h"
|
||||
#include "ui/gl/gl_export.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
// Encapsulates an image that can be bound to a texture, hiding platform
|
||||
// specific management.
|
||||
class GL_EXPORT GLImage : public base::RefCounted<GLImage> {
|
||||
public:
|
||||
GLImage() {}
|
||||
|
||||
// Destroys the image.
|
||||
virtual void Destroy(bool have_context) = 0;
|
||||
|
||||
// Get the size of the image.
|
||||
virtual gfx::Size GetSize() = 0;
|
||||
|
||||
// Bind image to texture currently bound to |target|.
|
||||
virtual bool BindTexImage(unsigned target) = 0;
|
||||
|
||||
// Release image from texture currently bound to |target|.
|
||||
virtual void ReleaseTexImage(unsigned target) = 0;
|
||||
|
||||
// Copy image to texture currently bound to |target|.
|
||||
virtual bool CopyTexImage(unsigned target) = 0;
|
||||
|
||||
// Called before the texture is used for drawing.
|
||||
virtual void WillUseTexImage() = 0;
|
||||
|
||||
// Called after the texture has been used for drawing.
|
||||
virtual void DidUseTexImage() = 0;
|
||||
|
||||
// Called before the texture image data will be modified.
|
||||
virtual void WillModifyTexImage() = 0;
|
||||
|
||||
// Called after the texture image data has been modified.
|
||||
virtual void DidModifyTexImage() = 0;
|
||||
|
||||
// Schedule image as an overlay plane to be shown at swap time for |widget|.
|
||||
virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~GLImage() {}
|
||||
|
||||
private:
|
||||
friend class base::RefCounted<GLImage>;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLImage);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_IMAGE_H_
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright (c) 2013 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_surface_egl.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
GLImageEGL::GLImageEGL(const gfx::Size& size)
|
||||
: egl_image_(EGL_NO_IMAGE_KHR), size_(size) {
|
||||
}
|
||||
|
||||
GLImageEGL::~GLImageEGL() {
|
||||
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
|
||||
}
|
||||
|
||||
bool GLImageEGL::Initialize(EGLenum target,
|
||||
EGLClientBuffer buffer,
|
||||
const EGLint* attrs) {
|
||||
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
|
||||
egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
|
||||
EGL_NO_CONTEXT,
|
||||
target,
|
||||
buffer,
|
||||
attrs);
|
||||
if (egl_image_ == EGL_NO_IMAGE_KHR) {
|
||||
EGLint error = eglGetError();
|
||||
LOG(ERROR) << "Error creating EGLImage: " << error;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageEGL::Destroy(bool have_context) {
|
||||
if (egl_image_ != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
|
||||
egl_image_ = EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Size GLImageEGL::GetSize() { return size_; }
|
||||
|
||||
bool GLImageEGL::BindTexImage(unsigned target) {
|
||||
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
|
||||
glEGLImageTargetTexture2DOES(target, egl_image_);
|
||||
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLImageEGL::CopyTexImage(unsigned target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GLImageEGL::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef UI_GL_GL_IMAGE_EGL_H_
|
||||
#define UI_GL_GL_IMAGE_EGL_H_
|
||||
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_image.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLImageEGL : public GLImage {
|
||||
public:
|
||||
explicit GLImageEGL(const gfx::Size& size);
|
||||
|
||||
bool Initialize(EGLenum target, EGLClientBuffer buffer, const EGLint* attrs);
|
||||
|
||||
// Overridden from GLImage:
|
||||
void Destroy(bool have_context) override;
|
||||
gfx::Size GetSize() override;
|
||||
bool BindTexImage(unsigned target) override;
|
||||
void ReleaseTexImage(unsigned target) override {}
|
||||
bool CopyTexImage(unsigned target) override;
|
||||
void WillUseTexImage() override {}
|
||||
void DidUseTexImage() override {}
|
||||
void WillModifyTexImage() override {}
|
||||
void DidModifyTexImage() override {}
|
||||
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) override;
|
||||
|
||||
protected:
|
||||
~GLImageEGL() override;
|
||||
|
||||
EGLImageKHR egl_image_;
|
||||
const gfx::Size size_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(GLImageEGL);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_IMAGE_EGL_H_
|
||||
@@ -1,202 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
extern "C" {
|
||||
#include <X11/Xlib.h>
|
||||
}
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_image_glx.h"
|
||||
#include "ui/gl/gl_surface_glx.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
namespace {
|
||||
|
||||
bool ValidFormat(unsigned internalformat) {
|
||||
switch (internalformat) {
|
||||
case GL_RGB:
|
||||
case GL_RGBA:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int TextureFormat(unsigned internalformat) {
|
||||
switch (internalformat) {
|
||||
case GL_RGB:
|
||||
return GLX_TEXTURE_FORMAT_RGB_EXT;
|
||||
case GL_RGBA:
|
||||
return GLX_TEXTURE_FORMAT_RGBA_EXT;
|
||||
default:
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int BindToTextureFormat(unsigned internalformat) {
|
||||
switch (internalformat) {
|
||||
case GL_RGB:
|
||||
return GLX_BIND_TO_TEXTURE_RGB_EXT;
|
||||
case GL_RGBA:
|
||||
return GLX_BIND_TO_TEXTURE_RGBA_EXT;
|
||||
default:
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned PixmapDepth(unsigned internalformat) {
|
||||
switch (internalformat) {
|
||||
case GL_RGBA:
|
||||
return 32u;
|
||||
case GL_RGB:
|
||||
return 24u;
|
||||
default:
|
||||
NOTREACHED();
|
||||
return 0u;
|
||||
}
|
||||
}
|
||||
|
||||
bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) {
|
||||
XID root_return;
|
||||
int x_return;
|
||||
int y_return;
|
||||
unsigned width_return;
|
||||
unsigned height_return;
|
||||
unsigned border_width_return;
|
||||
unsigned depth_return;
|
||||
if (!XGetGeometry(gfx::GetXDisplay(),
|
||||
pixmap,
|
||||
&root_return,
|
||||
&x_return,
|
||||
&y_return,
|
||||
&width_return,
|
||||
&height_return,
|
||||
&border_width_return,
|
||||
&depth_return))
|
||||
return false;
|
||||
|
||||
if (size)
|
||||
*size = gfx::Size(width_return, height_return);
|
||||
if (depth)
|
||||
*depth = depth_return;
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned ActualPixmapDepth(XID pixmap) {
|
||||
unsigned depth;
|
||||
if (!ActualPixmapGeometry(pixmap, NULL, &depth))
|
||||
return -1;
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
gfx::Size ActualPixmapSize(XID pixmap) {
|
||||
gfx::Size size;
|
||||
if (!ActualPixmapGeometry(pixmap, &size, NULL))
|
||||
return gfx::Size();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat)
|
||||
: glx_pixmap_(0), size_(size), internalformat_(internalformat) {
|
||||
}
|
||||
|
||||
GLImageGLX::~GLImageGLX() {
|
||||
DCHECK_EQ(0u, glx_pixmap_);
|
||||
}
|
||||
|
||||
bool GLImageGLX::Initialize(XID pixmap) {
|
||||
if (!GLSurfaceGLX::IsTextureFromPixmapSupported()) {
|
||||
DVLOG(0) << "GLX_EXT_texture_from_pixmap not supported.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidFormat(internalformat_)) {
|
||||
DVLOG(0) << "Invalid format: " << internalformat_;
|
||||
return false;
|
||||
}
|
||||
|
||||
DCHECK_EQ(PixmapDepth(internalformat_), ActualPixmapDepth(pixmap));
|
||||
DCHECK_EQ(size_.ToString(), ActualPixmapSize(pixmap).ToString());
|
||||
|
||||
int config_attribs[] = {
|
||||
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
|
||||
GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_EXT,
|
||||
BindToTextureFormat(internalformat_), GL_TRUE,
|
||||
0};
|
||||
int num_elements = 0;
|
||||
gfx::XScopedPtr<GLXFBConfig> config(
|
||||
glXChooseFBConfig(gfx::GetXDisplay(), DefaultScreen(gfx::GetXDisplay()),
|
||||
config_attribs, &num_elements));
|
||||
if (!config.get()) {
|
||||
DVLOG(0) << "glXChooseFBConfig failed.";
|
||||
return false;
|
||||
}
|
||||
if (!num_elements) {
|
||||
DVLOG(0) << "glXChooseFBConfig returned 0 elements.";
|
||||
return false;
|
||||
}
|
||||
|
||||
int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
|
||||
GLX_TEXTURE_FORMAT_EXT,
|
||||
TextureFormat(internalformat_), 0};
|
||||
glx_pixmap_ = glXCreatePixmap(
|
||||
gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
|
||||
if (!glx_pixmap_) {
|
||||
DVLOG(0) << "glXCreatePixmap failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageGLX::Destroy(bool have_context) {
|
||||
if (glx_pixmap_) {
|
||||
glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_);
|
||||
glx_pixmap_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Size GLImageGLX::GetSize() { return size_; }
|
||||
|
||||
bool GLImageGLX::BindTexImage(unsigned target) {
|
||||
if (!glx_pixmap_)
|
||||
return false;
|
||||
|
||||
// Requires TEXTURE_2D target.
|
||||
if (target != GL_TEXTURE_2D)
|
||||
return false;
|
||||
|
||||
glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageGLX::ReleaseTexImage(unsigned target) {
|
||||
DCHECK_NE(0u, glx_pixmap_);
|
||||
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target);
|
||||
|
||||
glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
|
||||
}
|
||||
|
||||
bool GLImageGLX::CopyTexImage(unsigned target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GLImageGLX::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
#ifndef UI_GL_GL_IMAGE_GLX_H_
|
||||
#define UI_GL_GL_IMAGE_GLX_H_
|
||||
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/x/x11_types.h"
|
||||
#include "ui/gl/gl_export.h"
|
||||
#include "ui/gl/gl_image.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLImageGLX : public GLImage {
|
||||
public:
|
||||
GLImageGLX(const gfx::Size& size, unsigned internalformat);
|
||||
|
||||
bool Initialize(XID pixmap);
|
||||
|
||||
// Overridden from GLImage:
|
||||
void Destroy(bool have_context) override;
|
||||
gfx::Size GetSize() override;
|
||||
bool BindTexImage(unsigned target) override;
|
||||
void ReleaseTexImage(unsigned target) override;
|
||||
bool CopyTexImage(unsigned target) override;
|
||||
void WillUseTexImage() override {}
|
||||
void DidUseTexImage() override {}
|
||||
void WillModifyTexImage() override {}
|
||||
void DidModifyTexImage() override {}
|
||||
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) override;
|
||||
|
||||
protected:
|
||||
~GLImageGLX() override;
|
||||
|
||||
private:
|
||||
XID glx_pixmap_;
|
||||
const gfx::Size size_;
|
||||
unsigned internalformat_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLImageGLX);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_IMAGE_GLX_H_
|
||||
@@ -1,132 +0,0 @@
|
||||
// Copyright 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_linux_dma_buffer.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define FOURCC(a, b, c, d) \
|
||||
((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
|
||||
(static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
|
||||
|
||||
#define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
|
||||
#define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
|
||||
|
||||
namespace gfx {
|
||||
namespace {
|
||||
|
||||
bool ValidFormat(unsigned internalformat, gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (internalformat) {
|
||||
case GL_ATC_RGB_AMD:
|
||||
return format == gfx::GpuMemoryBuffer::ATC;
|
||||
case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
|
||||
return format == gfx::GpuMemoryBuffer::ATCIA;
|
||||
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
||||
return format == gfx::GpuMemoryBuffer::DXT1;
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
||||
return format == gfx::GpuMemoryBuffer::DXT5;
|
||||
case GL_ETC1_RGB8_OES:
|
||||
return format == gfx::GpuMemoryBuffer::ETC1;
|
||||
case GL_RGB:
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return false;
|
||||
}
|
||||
NOTREACHED();
|
||||
return false;
|
||||
case GL_RGBA:
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
return false;
|
||||
}
|
||||
NOTREACHED();
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
EGLint FourCC(gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return DRM_FORMAT_ARGB8888;
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
return DRM_FORMAT_XRGB8888;
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IsHandleValid(const base::FileDescriptor& handle) {
|
||||
return handle.fd >= 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(const gfx::Size& size,
|
||||
unsigned internalformat)
|
||||
: GLImageEGL(size), internalformat_(internalformat) {
|
||||
}
|
||||
|
||||
GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() {
|
||||
}
|
||||
|
||||
bool GLImageLinuxDMABuffer::Initialize(const base::FileDescriptor& handle,
|
||||
gfx::GpuMemoryBuffer::Format format,
|
||||
int pitch) {
|
||||
if (!ValidFormat(internalformat_, format)) {
|
||||
LOG(ERROR) << "Invalid format: " << internalformat_;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsHandleValid(handle)) {
|
||||
LOG(ERROR) << "Invalid file descriptor: " << handle.fd;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
|
||||
// target, the EGL will take a reference to the dma_buf.
|
||||
EGLint attrs[] = {EGL_WIDTH,
|
||||
size_.width(),
|
||||
EGL_HEIGHT,
|
||||
size_.height(),
|
||||
EGL_LINUX_DRM_FOURCC_EXT,
|
||||
FourCC(format),
|
||||
EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
handle.fd,
|
||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
0,
|
||||
EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
pitch,
|
||||
EGL_NONE};
|
||||
return GLImageEGL::Initialize(
|
||||
EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef UI_GL_GL_IMAGE_LINUX_DMA_BUFFER_H_
|
||||
#define UI_GL_GL_IMAGE_LINUX_DMA_BUFFER_H_
|
||||
|
||||
#include "ui/gfx/gpu_memory_buffer.h"
|
||||
#include "ui/gl/gl_image_egl.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLImageLinuxDMABuffer : public GLImageEGL {
|
||||
public:
|
||||
GLImageLinuxDMABuffer(const gfx::Size& size, unsigned internalformat);
|
||||
|
||||
// Returns true on success and the file descriptor can be closed as the
|
||||
// implementation will take a reference to the dma_buf.
|
||||
bool Initialize(const base::FileDescriptor& handle,
|
||||
gfx::GpuMemoryBuffer::Format format,
|
||||
int pitch);
|
||||
|
||||
protected:
|
||||
~GLImageLinuxDMABuffer() override;
|
||||
|
||||
private:
|
||||
unsigned internalformat_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLImageLinuxDMABuffer);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_IMAGE_LINUX_DMA_BUFFER_H_
|
||||
@@ -1,381 +0,0 @@
|
||||
// Copyright 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_memory.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "ui/gl/gl_bindings.h"
|
||||
#include "ui/gl/gl_surface_egl.h"
|
||||
#include "ui/gl/scoped_binders.h"
|
||||
|
||||
namespace gfx {
|
||||
namespace {
|
||||
|
||||
bool ValidInternalFormat(unsigned internalformat) {
|
||||
switch (internalformat) {
|
||||
case GL_RGBA:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidFormat(gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
return false;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
return false;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
return GL_ATC_RGB_AMD;
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
return GL_ETC1_RGB8_OES;
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
return GL_RGBA;
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return GL_BGRA_EXT;
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) {
|
||||
return TextureFormat(format);
|
||||
}
|
||||
|
||||
GLenum DataType(gfx::GpuMemoryBuffer::Format format) {
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLsizei SizeInBytes(const gfx::Size& size,
|
||||
gfx::GpuMemoryBuffer::Format format) {
|
||||
size_t stride_in_bytes = 0;
|
||||
bool valid_stride = GLImageMemory::StrideInBytes(
|
||||
size.width(), format, &stride_in_bytes);
|
||||
DCHECK(valid_stride);
|
||||
return static_cast<GLsizei>(stride_in_bytes * size.height());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat)
|
||||
: size_(size),
|
||||
internalformat_(internalformat),
|
||||
memory_(NULL),
|
||||
format_(gfx::GpuMemoryBuffer::RGBA_8888),
|
||||
in_use_(false),
|
||||
target_(0),
|
||||
need_do_bind_tex_image_(false),
|
||||
egl_texture_id_(0u),
|
||||
egl_image_(EGL_NO_IMAGE_KHR) {
|
||||
}
|
||||
|
||||
GLImageMemory::~GLImageMemory() {
|
||||
DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
|
||||
DCHECK_EQ(0u, egl_texture_id_);
|
||||
}
|
||||
|
||||
// static
|
||||
bool GLImageMemory::StrideInBytes(size_t width,
|
||||
gfx::GpuMemoryBuffer::Format format,
|
||||
size_t* stride_in_bytes) {
|
||||
base::CheckedNumeric<size_t> s = width;
|
||||
switch (format) {
|
||||
case gfx::GpuMemoryBuffer::ATCIA:
|
||||
case gfx::GpuMemoryBuffer::DXT5:
|
||||
*stride_in_bytes = width;
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::ATC:
|
||||
case gfx::GpuMemoryBuffer::DXT1:
|
||||
case gfx::GpuMemoryBuffer::ETC1:
|
||||
DCHECK_EQ(width % 2, 0U);
|
||||
s /= 2;
|
||||
if (!s.IsValid())
|
||||
return false;
|
||||
|
||||
*stride_in_bytes = s.ValueOrDie();
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::RGBA_8888:
|
||||
case gfx::GpuMemoryBuffer::BGRA_8888:
|
||||
s *= 4;
|
||||
if (!s.IsValid())
|
||||
return false;
|
||||
|
||||
*stride_in_bytes = s.ValueOrDie();
|
||||
return true;
|
||||
case gfx::GpuMemoryBuffer::RGBX_8888:
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GLImageMemory::Initialize(const unsigned char* memory,
|
||||
gfx::GpuMemoryBuffer::Format format) {
|
||||
if (!ValidInternalFormat(internalformat_)) {
|
||||
LOG(ERROR) << "Invalid internalformat: " << internalformat_;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ValidFormat(format)) {
|
||||
LOG(ERROR) << "Invalid format: " << format;
|
||||
return false;
|
||||
}
|
||||
|
||||
DCHECK(memory);
|
||||
DCHECK(!memory_);
|
||||
DCHECK_IMPLIES(IsCompressedFormat(format), size_.width() % 4 == 0);
|
||||
DCHECK_IMPLIES(IsCompressedFormat(format), size_.height() % 4 == 0);
|
||||
memory_ = memory;
|
||||
format_ = format;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageMemory::Destroy(bool have_context) {
|
||||
if (egl_image_ != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
|
||||
egl_image_ = EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
|
||||
if (egl_texture_id_) {
|
||||
if (have_context)
|
||||
glDeleteTextures(1, &egl_texture_id_);
|
||||
egl_texture_id_ = 0u;
|
||||
}
|
||||
memory_ = NULL;
|
||||
}
|
||||
|
||||
gfx::Size GLImageMemory::GetSize() {
|
||||
return size_;
|
||||
}
|
||||
|
||||
bool GLImageMemory::BindTexImage(unsigned target) {
|
||||
if (target_ && target_ != target) {
|
||||
LOG(ERROR) << "GLImage can only be bound to one target";
|
||||
return false;
|
||||
}
|
||||
target_ = target;
|
||||
|
||||
// Defer DoBindTexImage if not currently in use.
|
||||
if (!in_use_) {
|
||||
need_do_bind_tex_image_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
DoBindTexImage(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLImageMemory::CopyTexImage(unsigned target) {
|
||||
TRACE_EVENT0("gpu", "GLImageMemory::CopyTexImage");
|
||||
|
||||
// GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexImage target.
|
||||
if (target == GL_TEXTURE_EXTERNAL_OES)
|
||||
return false;
|
||||
|
||||
DCHECK(memory_);
|
||||
if (IsCompressedFormat(format_)) {
|
||||
glCompressedTexSubImage2D(target,
|
||||
0, // level
|
||||
0, // x-offset
|
||||
0, // y-offset
|
||||
size_.width(), size_.height(),
|
||||
DataFormat(format_), SizeInBytes(size_, format_),
|
||||
memory_);
|
||||
} else {
|
||||
glTexSubImage2D(target, 0, // level
|
||||
0, // x
|
||||
0, // y
|
||||
size_.width(), size_.height(), DataFormat(format_),
|
||||
DataType(format_), memory_);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageMemory::WillUseTexImage() {
|
||||
DCHECK(!in_use_);
|
||||
in_use_ = true;
|
||||
|
||||
if (!need_do_bind_tex_image_)
|
||||
return;
|
||||
|
||||
DCHECK(target_);
|
||||
DoBindTexImage(target_);
|
||||
}
|
||||
|
||||
void GLImageMemory::DidUseTexImage() {
|
||||
DCHECK(in_use_);
|
||||
in_use_ = false;
|
||||
}
|
||||
|
||||
bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void GLImageMemory::DoBindTexImage(unsigned target) {
|
||||
TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage");
|
||||
|
||||
DCHECK(need_do_bind_tex_image_);
|
||||
need_do_bind_tex_image_ = false;
|
||||
|
||||
DCHECK(memory_);
|
||||
if (target == GL_TEXTURE_EXTERNAL_OES) {
|
||||
if (egl_image_ == EGL_NO_IMAGE_KHR) {
|
||||
DCHECK_EQ(0u, egl_texture_id_);
|
||||
glGenTextures(1, &egl_texture_id_);
|
||||
|
||||
{
|
||||
ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
if (IsCompressedFormat(format_)) {
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D,
|
||||
0, // mip level
|
||||
TextureFormat(format_), size_.width(),
|
||||
size_.height(),
|
||||
0, // border
|
||||
SizeInBytes(size_, format_), memory_);
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, // mip level
|
||||
TextureFormat(format_),
|
||||
size_.width(),
|
||||
size_.height(),
|
||||
0, // border
|
||||
DataFormat(format_),
|
||||
DataType(format_),
|
||||
memory_);
|
||||
}
|
||||
}
|
||||
|
||||
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_ =
|
||||
eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
|
||||
eglGetCurrentContext(),
|
||||
EGL_GL_TEXTURE_2D_KHR,
|
||||
reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
|
||||
attrs);
|
||||
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
|
||||
<< "Error creating EGLImage: " << eglGetError();
|
||||
} else {
|
||||
ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
|
||||
|
||||
if (IsCompressedFormat(format_)) {
|
||||
glCompressedTexSubImage2D(GL_TEXTURE_2D,
|
||||
0, // mip level
|
||||
0, // x-offset
|
||||
0, // y-offset
|
||||
size_.width(), size_.height(),
|
||||
DataFormat(format_),
|
||||
SizeInBytes(size_, format_),
|
||||
memory_);
|
||||
} else {
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0, // mip level
|
||||
0, // x-offset
|
||||
0, // y-offset
|
||||
size_.width(),
|
||||
size_.height(),
|
||||
DataFormat(format_),
|
||||
DataType(format_),
|
||||
memory_);
|
||||
}
|
||||
}
|
||||
|
||||
glEGLImageTargetTexture2DOES(target, egl_image_);
|
||||
DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
|
||||
if (IsCompressedFormat(format_)) {
|
||||
glCompressedTexImage2D(target,
|
||||
0, // mip level
|
||||
TextureFormat(format_), size_.width(),
|
||||
size_.height(),
|
||||
0, // border
|
||||
SizeInBytes(size_, format_), memory_);
|
||||
} else {
|
||||
glTexImage2D(target,
|
||||
0, // mip level
|
||||
TextureFormat(format_),
|
||||
size_.width(),
|
||||
size_.height(),
|
||||
0, // border
|
||||
DataFormat(format_),
|
||||
DataType(format_),
|
||||
memory_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright 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.
|
||||
|
||||
#ifndef UI_GL_GL_IMAGE_MEMORY_H_
|
||||
#define UI_GL_GL_IMAGE_MEMORY_H_
|
||||
|
||||
#include "ui/gl/gl_image.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "ui/gfx/gpu_memory_buffer.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
class GL_EXPORT GLImageMemory : public GLImage {
|
||||
public:
|
||||
GLImageMemory(const gfx::Size& size, unsigned internalformat);
|
||||
|
||||
static bool StrideInBytes(size_t width,
|
||||
gfx::GpuMemoryBuffer::Format format,
|
||||
size_t* stride_in_bytes);
|
||||
|
||||
bool Initialize(const unsigned char* memory,
|
||||
gfx::GpuMemoryBuffer::Format format);
|
||||
|
||||
// Overridden from GLImage:
|
||||
void Destroy(bool have_context) override;
|
||||
gfx::Size GetSize() override;
|
||||
bool BindTexImage(unsigned target) override;
|
||||
void ReleaseTexImage(unsigned target) override {}
|
||||
bool CopyTexImage(unsigned target) override;
|
||||
void WillUseTexImage() override;
|
||||
void DidUseTexImage() override;
|
||||
void WillModifyTexImage() override {}
|
||||
void DidModifyTexImage() override {}
|
||||
bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
|
||||
int z_order,
|
||||
OverlayTransform transform,
|
||||
const Rect& bounds_rect,
|
||||
const RectF& crop_rect) override;
|
||||
|
||||
protected:
|
||||
~GLImageMemory() override;
|
||||
|
||||
private:
|
||||
void DoBindTexImage(unsigned target);
|
||||
|
||||
const gfx::Size size_;
|
||||
const unsigned internalformat_;
|
||||
const unsigned char* memory_;
|
||||
gfx::GpuMemoryBuffer::Format format_;
|
||||
bool in_use_;
|
||||
unsigned target_;
|
||||
bool need_do_bind_tex_image_;
|
||||
unsigned egl_texture_id_;
|
||||
EGLImageKHR egl_image_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GLImageMemory);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
#endif // UI_GL_GL_IMAGE_MEMORY_H_
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 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_ref_counted_memory.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ref_counted_memory.h"
|
||||
|
||||
namespace gfx {
|
||||
|
||||
GLImageRefCountedMemory::GLImageRefCountedMemory(const gfx::Size& size,
|
||||
unsigned internalformat)
|
||||
: GLImageMemory(size, internalformat) {
|
||||
}
|
||||
|
||||
GLImageRefCountedMemory::~GLImageRefCountedMemory() {
|
||||
DCHECK(!ref_counted_memory_.get());
|
||||
}
|
||||
|
||||
bool GLImageRefCountedMemory::Initialize(
|
||||
base::RefCountedMemory* ref_counted_memory,
|
||||
gfx::GpuMemoryBuffer::Format format) {
|
||||
if (!GLImageMemory::Initialize(ref_counted_memory->front(), format))
|
||||
return false;
|
||||
|
||||
DCHECK(!ref_counted_memory_.get());
|
||||
ref_counted_memory_ = ref_counted_memory;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLImageRefCountedMemory::Destroy(bool have_context) {
|
||||
GLImageMemory::Destroy(have_context);
|
||||
ref_counted_memory_ = NULL;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user