diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn index 658c415f8..6b3115de2 100644 --- a/ui/gl/BUILD.gn +++ b/ui/gl/BUILD.gn @@ -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 = [ diff --git a/ui/gl/gl_context_ozone.cc b/ui/gl/gl_context_ozone.cc deleted file mode 100644 index 776e114e3..000000000 --- a/ui/gl/gl_context_ozone.cc +++ /dev/null @@ -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::CreateGLContext( - GLShareGroup* share_group, - GLSurface* compatible_surface, - GpuPreference gpu_preference) { - - switch (GetGLImplementation()) { - case kGLImplementationMockGL: - return scoped_refptr(new GLContextStub()); - case kGLImplementationOSMesaGL: { - scoped_refptr context(new GLContextOSMesa(share_group)); - if (!context->Initialize(compatible_surface, gpu_preference)) - return NULL; - return context; - } - case kGLImplementationEGLGLES2: { - scoped_refptr context(new GLContextEGL(share_group)); - if (!context->Initialize(compatible_surface, gpu_preference)) - return NULL; - return context; - } - default: - NOTREACHED(); - return NULL; - } -} - -} // namespace gfx - diff --git a/ui/gl/gl_fence.cc b/ui/gl/gl_fence.cc deleted file mode 100644 index c119aa011..000000000 --- a/ui/gl/gl_fence.cc +++ /dev/null @@ -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 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 diff --git a/ui/gl/gl_fence.h b/ui/gl/gl_fence.h deleted file mode 100644 index 76511f414..000000000 --- a/ui/gl/gl_fence.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_fence_arb.cc b/ui/gl/gl_fence_arb.cc deleted file mode 100644 index 5c6b33711..000000000 --- a/ui/gl/gl_fence_arb.cc +++ /dev/null @@ -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(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 diff --git a/ui/gl/gl_fence_arb.h b/ui/gl/gl_fence_arb.h deleted file mode 100644 index 3975efec7..000000000 --- a/ui/gl/gl_fence_arb.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_fence_egl.cc b/ui/gl/gl_fence_egl.cc deleted file mode 100644 index 641b8c2e3..000000000 --- a/ui/gl/gl_fence_egl.cc +++ /dev/null @@ -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 diff --git a/ui/gl/gl_fence_egl.h b/ui/gl/gl_fence_egl.h deleted file mode 100644 index 5b6006c19..000000000 --- a/ui/gl/gl_fence_egl.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_fence_nv.cc b/ui/gl/gl_fence_nv.cc deleted file mode 100644 index 0e23b2834..000000000 --- a/ui/gl/gl_fence_nv.cc +++ /dev/null @@ -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 diff --git a/ui/gl/gl_fence_nv.h b/ui/gl/gl_fence_nv.h deleted file mode 100644 index b1dc88fb9..000000000 --- a/ui/gl/gl_fence_nv.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_image.h b/ui/gl/gl_image.h deleted file mode 100644 index 214241396..000000000 --- a/ui/gl/gl_image.h +++ /dev/null @@ -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 { - 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; - - DISALLOW_COPY_AND_ASSIGN(GLImage); -}; - -} // namespace gfx - -#endif // UI_GL_GL_IMAGE_H_ diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_egl.cc deleted file mode 100644 index b8ee78c3a..000000000 --- a/ui/gl/gl_image_egl.cc +++ /dev/null @@ -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(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 diff --git a/ui/gl/gl_image_egl.h b/ui/gl/gl_image_egl.h deleted file mode 100644 index 716761f67..000000000 --- a/ui/gl/gl_image_egl.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_image_glx.cc b/ui/gl/gl_image_glx.cc deleted file mode 100644 index dea6cd64b..000000000 --- a/ui/gl/gl_image_glx.cc +++ /dev/null @@ -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 -} - -#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 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(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 diff --git a/ui/gl/gl_image_glx.h b/ui/gl/gl_image_glx.h deleted file mode 100644 index 1f4e819d1..000000000 --- a/ui/gl/gl_image_glx.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_image_linux_dma_buffer.cc b/ui/gl/gl_image_linux_dma_buffer.cc deleted file mode 100644 index 04ad06bd4..000000000 --- a/ui/gl/gl_image_linux_dma_buffer.cc +++ /dev/null @@ -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 - -#define FOURCC(a, b, c, d) \ - ((static_cast(a)) | (static_cast(b) << 8) | \ - (static_cast(c) << 16) | (static_cast(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(NULL), attrs); -} - -} // namespace gfx diff --git a/ui/gl/gl_image_linux_dma_buffer.h b/ui/gl/gl_image_linux_dma_buffer.h deleted file mode 100644 index 5256211aa..000000000 --- a/ui/gl/gl_image_linux_dma_buffer.h +++ /dev/null @@ -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_ diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc deleted file mode 100644 index 13e9d71e3..000000000 --- a/ui/gl/gl_image_memory.cc +++ /dev/null @@ -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(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 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(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(GL_NO_ERROR), glGetError()); - return; - } - - DCHECK_NE(static_cast(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 diff --git a/ui/gl/gl_image_memory.h b/ui/gl/gl_image_memory.h deleted file mode 100644 index 022782268..000000000 --- a/ui/gl/gl_image_memory.h +++ /dev/null @@ -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 -#include - -#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_ diff --git a/ui/gl/gl_image_ref_counted_memory.cc b/ui/gl/gl_image_ref_counted_memory.cc deleted file mode 100644 index 653d70a98..000000000 --- a/ui/gl/gl_image_ref_counted_memory.cc +++ /dev/null @@ -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 diff --git a/ui/gl/gl_image_ref_counted_memory.h b/ui/gl/gl_image_ref_counted_memory.h deleted file mode 100644 index 6bcf2179f..000000000 --- a/ui/gl/gl_image_ref_counted_memory.h +++ /dev/null @@ -1,38 +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_REF_COUNTED_MEMORY_H_ -#define UI_GL_GL_IMAGE_REF_COUNTED_MEMORY_H_ - -#include "base/memory/ref_counted.h" -#include "ui/gl/gl_image_memory.h" - -namespace base { -class RefCountedMemory; -} - -namespace gfx { - -class GL_EXPORT GLImageRefCountedMemory : public GLImageMemory { - public: - GLImageRefCountedMemory(const gfx::Size& size, unsigned internalformat); - - bool Initialize(base::RefCountedMemory* ref_counted_memory, - gfx::GpuMemoryBuffer::Format format); - - // Overridden from GLImage: - void Destroy(bool have_context) override; - - protected: - ~GLImageRefCountedMemory() override; - - private: - scoped_refptr ref_counted_memory_; - - DISALLOW_COPY_AND_ASSIGN(GLImageRefCountedMemory); -}; - -} // namespace gfx - -#endif // UI_GL_GL_IMAGE_REF_COUNTED_MEMORY_H_ diff --git a/ui/gl/gl_image_shared_memory.cc b/ui/gl/gl_image_shared_memory.cc deleted file mode 100644 index d9e31a73a..000000000 --- a/ui/gl/gl_image_shared_memory.cc +++ /dev/null @@ -1,84 +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_shared_memory.h" - -#include "base/logging.h" -#include "base/numerics/safe_math.h" -#include "base/process/process_handle.h" - -namespace gfx { -namespace { - -// Returns true if the size is valid and false otherwise. -bool SizeInBytes(const gfx::Size& size, - gfx::GpuMemoryBuffer::Format format, - size_t* size_in_bytes) { - if (size.IsEmpty()) - return false; - - size_t stride_in_bytes = 0; - if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes)) - return false; - base::CheckedNumeric s = stride_in_bytes; - s *= size.height(); - if (!s.IsValid()) - return false; - *size_in_bytes = s.ValueOrDie(); - return true; -} - -} // namespace - -GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size, - unsigned internalformat) - : GLImageMemory(size, internalformat) { -} - -GLImageSharedMemory::~GLImageSharedMemory() { - DCHECK(!shared_memory_); -} - -bool GLImageSharedMemory::Initialize(const gfx::GpuMemoryBufferHandle& handle, - gfx::GpuMemoryBuffer::Format format) { - size_t size_in_bytes; - if (!SizeInBytes(GetSize(), format, &size_in_bytes)) - return false; - - if (!base::SharedMemory::IsHandleValid(handle.handle)) - return false; - - base::SharedMemory shared_memory(handle.handle, true); - - // Duplicate the handle. - base::SharedMemoryHandle duped_shared_memory_handle; - if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), - &duped_shared_memory_handle)) { - DVLOG(0) << "Failed to duplicate shared memory handle."; - return false; - } - - scoped_ptr duped_shared_memory( - new base::SharedMemory(duped_shared_memory_handle, true)); - if (!duped_shared_memory->Map(size_in_bytes)) { - DVLOG(0) << "Failed to map shared memory."; - return false; - } - - if (!GLImageMemory::Initialize( - static_cast(duped_shared_memory->memory()), format)) { - return false; - } - - DCHECK(!shared_memory_); - shared_memory_ = duped_shared_memory.Pass(); - return true; -} - -void GLImageSharedMemory::Destroy(bool have_context) { - GLImageMemory::Destroy(have_context); - shared_memory_.reset(); -} - -} // namespace gfx diff --git a/ui/gl/gl_image_shared_memory.h b/ui/gl/gl_image_shared_memory.h deleted file mode 100644 index ab80b35bc..000000000 --- a/ui/gl/gl_image_shared_memory.h +++ /dev/null @@ -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_IMAGE_SHARED_MEMORY_H_ -#define UI_GL_GL_IMAGE_SHARED_MEMORY_H_ - -#include "base/memory/scoped_ptr.h" -#include "ui/gfx/gpu_memory_buffer.h" -#include "ui/gl/gl_image_memory.h" - -namespace gfx { - -class GL_EXPORT GLImageSharedMemory : public GLImageMemory { - public: - GLImageSharedMemory(const gfx::Size& size, unsigned internalformat); - - bool Initialize(const gfx::GpuMemoryBufferHandle& handle, - gfx::GpuMemoryBuffer::Format format); - - // Overridden from GLImage: - void Destroy(bool have_context) override; - - protected: - ~GLImageSharedMemory() override; - - private: - scoped_ptr shared_memory_; - - DISALLOW_COPY_AND_ASSIGN(GLImageSharedMemory); -}; - -} // namespace gfx - -#endif // UI_GL_GL_IMAGE_SHARED_MEMORY_H_ diff --git a/ui/gl/gl_image_stub.cc b/ui/gl/gl_image_stub.cc deleted file mode 100644 index 1c8e46974..000000000 --- a/ui/gl/gl_image_stub.cc +++ /dev/null @@ -1,27 +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_image_stub.h" - -namespace gfx { - -GLImageStub::GLImageStub() {} - -GLImageStub::~GLImageStub() {} - -gfx::Size GLImageStub::GetSize() { return gfx::Size(1, 1); } - -bool GLImageStub::BindTexImage(unsigned target) { return true; } - -bool GLImageStub::CopyTexImage(unsigned target) { return true; } - -bool GLImageStub::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, - int z_order, - OverlayTransform transform, - const Rect& bounds_rect, - const RectF& crop_rect) { - return false; -} - -} // namespace gfx diff --git a/ui/gl/gl_image_stub.h b/ui/gl/gl_image_stub.h deleted file mode 100644 index d83658654..000000000 --- a/ui/gl/gl_image_stub.h +++ /dev/null @@ -1,39 +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_STUB_H_ -#define UI_GL_GL_IMAGE_STUB_H_ - -#include "ui/gl/gl_image.h" - -namespace gfx { - -// A GLImage that does nothing for unit tests. -class GL_EXPORT GLImageStub : public GLImage { - public: - GLImageStub(); - - // 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: - ~GLImageStub() override; -}; - -} // namespace gfx - -#endif // UI_GL_GL_IMAGE_STUB_H_ diff --git a/ui/gl/gl_image_surface_texture.cc b/ui/gl/gl_image_surface_texture.cc deleted file mode 100644 index a321c4d30..000000000 --- a/ui/gl/gl_image_surface_texture.cc +++ /dev/null @@ -1,87 +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_surface_texture.h" - -#include "base/trace_event/trace_event.h" -#include "ui/gl/android/surface_texture.h" - -namespace gfx { - -GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size) - : size_(size), texture_id_(0) { -} - -GLImageSurfaceTexture::~GLImageSurfaceTexture() { - DCHECK(!surface_texture_.get()); - DCHECK_EQ(0, texture_id_); -} - -bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) { - DCHECK(!surface_texture_.get()); - surface_texture_ = surface_texture; - return true; -} - -void GLImageSurfaceTexture::Destroy(bool have_context) { - surface_texture_ = NULL; - texture_id_ = 0; -} - -gfx::Size GLImageSurfaceTexture::GetSize() { return size_; } - -bool GLImageSurfaceTexture::BindTexImage(unsigned target) { - TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage"); - - if (target != GL_TEXTURE_EXTERNAL_OES) { - LOG(ERROR) - << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; - return false; - } - - GLint texture_id; - glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); - DCHECK(texture_id); - - if (texture_id_ && texture_id_ != texture_id) { - LOG(ERROR) << "Surface texture can only be bound to one texture ID"; - return false; - } - - DCHECK(surface_texture_.get()); - if (texture_id != texture_id_) { - // Note: Surface textures used as gpu memory buffers are created with an - // initial dummy texture id of 0. We need to call DetachFromGLContext() here - // to detach from the dummy texture before we can attach to a real texture - // id. DetachFromGLContext() will delete the texture for the current - // attachment point so it's important that this is never called when - // attached to a real texture id. Detaching from the dummy texture id should - // not cause any problems as the GL should silently ignore 0 when passed to - // glDeleteTextures. - DCHECK_EQ(0, texture_id_); - surface_texture_->DetachFromGLContext(); - - // This will attach the surface texture to the texture currently bound to - // GL_TEXTURE_EXTERNAL_OES target. - surface_texture_->AttachToGLContext(); - texture_id_ = texture_id; - } - - surface_texture_->UpdateTexImage(); - return true; -} - -bool GLImageSurfaceTexture::CopyTexImage(unsigned target) { - return false; -} - -bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, - int z_order, - OverlayTransform transform, - const Rect& bounds_rect, - const RectF& crop_rect) { - return false; -} - -} // namespace gfx diff --git a/ui/gl/gl_image_surface_texture.h b/ui/gl/gl_image_surface_texture.h deleted file mode 100644 index d2ff5b707..000000000 --- a/ui/gl/gl_image_surface_texture.h +++ /dev/null @@ -1,50 +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_SURFACE_TEXTURE_H_ -#define UI_GL_GL_IMAGE_SURFACE_TEXTURE_H_ - -#include "base/memory/ref_counted.h" -#include "ui/gl/gl_bindings.h" -#include "ui/gl/gl_image.h" - -namespace gfx { -class SurfaceTexture; - -class GL_EXPORT GLImageSurfaceTexture : public GLImage { - public: - explicit GLImageSurfaceTexture(const gfx::Size& size); - - bool Initialize(SurfaceTexture* surface_texture); - - // 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: - ~GLImageSurfaceTexture() override; - - private: - scoped_refptr surface_texture_; - const gfx::Size size_; - GLint texture_id_; - - DISALLOW_COPY_AND_ASSIGN(GLImageSurfaceTexture); -}; - -} // namespace gfx - -#endif // UI_GL_GL_IMAGE_SURFACE_TEXTURE_H_ diff --git a/ui/gl/gl_implementation_ozone.cc b/ui/gl/gl_implementation_ozone.cc deleted file mode 100644 index 2a85720da..000000000 --- a/ui/gl/gl_implementation_ozone.cc +++ /dev/null @@ -1,117 +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 "base/bind.h" -#include "ui/gl/gl_bindings.h" -#include "ui/gl/gl_context_stub_with_extensions.h" -#include "ui/gl/gl_egl_api_implementation.h" -#include "ui/gl/gl_gl_api_implementation.h" -#include "ui/gl/gl_implementation.h" -#include "ui/gl/gl_implementation_osmesa.h" -#include "ui/gl/gl_osmesa_api_implementation.h" -#include "ui/ozone/public/ozone_platform.h" -#include "ui/ozone/public/surface_factory_ozone.h" - -namespace gfx { - -namespace { - -void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { - glClearDepthf(static_cast(depth)); -} - -void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, - GLclampd z_far) { - glDepthRangef(static_cast(z_near), static_cast(z_far)); -} - -} // namespace - -void GetAllowedGLImplementations(std::vector* impls) { - impls->push_back(kGLImplementationEGLGLES2); - impls->push_back(kGLImplementationOSMesaGL); -} - -bool InitializeStaticGLBindings(GLImplementation implementation) { - // Prevent reinitialization with a different implementation. Once the gpu - // unit tests have initialized with kGLImplementationMock, we don't want to - // later switch to another GL implementation. - DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); - ui::OzonePlatform::InitializeForGPU(); - - switch (implementation) { - case kGLImplementationOSMesaGL: - return InitializeStaticGLBindingsOSMesaGL(); - case kGLImplementationEGLGLES2: - if (!ui::SurfaceFactoryOzone::GetInstance()->LoadEGLGLES2Bindings( - base::Bind(&AddGLNativeLibrary), - base::Bind(&SetGLGetProcAddressProc))) - return false; - SetGLImplementation(kGLImplementationEGLGLES2); - InitializeStaticGLBindingsGL(); - InitializeStaticGLBindingsEGL(); - - // These two functions take single precision float rather than double - // precision float parameters in GLES. - ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; - ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; - break; - case kGLImplementationMockGL: { - SetGLImplementation(kGLImplementationMockGL); - InitializeStaticGLBindingsGL(); - break; - } - default: - NOTIMPLEMENTED() - << "Unsupported GL type for Ozone surface implementation"; - return false; - } - - return true; -} - -bool InitializeDynamicGLBindings(GLImplementation implementation, - GLContext* context) { - switch (implementation) { - case kGLImplementationOSMesaGL: - case kGLImplementationEGLGLES2: - InitializeDynamicGLBindingsGL(context); - break; - case kGLImplementationMockGL: - if (!context) { - scoped_refptr mock_context( - new GLContextStubWithExtensions()); - mock_context->SetGLVersionString("3.0"); - InitializeDynamicGLBindingsGL(mock_context.get()); - } else - InitializeDynamicGLBindingsGL(context); - break; - default: - return false; - } - - return true; -} - -void InitializeDebugGLBindings() { -} - -void ClearGLBindings() { - ClearGLBindingsEGL(); - ClearGLBindingsGL(); - SetGLImplementation(kGLImplementationNone); - UnloadGLNativeLibraries(); -} - -bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { - switch (GetGLImplementation()) { - case kGLImplementationEGLGLES2: - return GetGLWindowSystemBindingInfoEGL(info); - default: - return false; - } - return false; -} - -} // namespace gfx diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc deleted file mode 100644 index 800be1759..000000000 --- a/ui/gl/gl_surface_ozone.cc +++ /dev/null @@ -1,510 +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_surface.h" - -#include "base/bind.h" -#include "base/callback.h" -#include "base/location.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/threading/worker_pool.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gl/gl_context.h" -#include "ui/gl/gl_image.h" -#include "ui/gl/gl_image_linux_dma_buffer.h" -#include "ui/gl/gl_implementation.h" -#include "ui/gl/gl_surface_egl.h" -#include "ui/gl/gl_surface_osmesa.h" -#include "ui/gl/gl_surface_stub.h" -#include "ui/gl/scoped_binders.h" -#include "ui/gl/scoped_make_current.h" -#include "ui/ozone/public/native_pixmap.h" -#include "ui/ozone/public/surface_factory_ozone.h" -#include "ui/ozone/public/surface_ozone_egl.h" - -namespace gfx { - -namespace { - -void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { - eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, - EGL_FOREVER_KHR); -} - -// A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow -class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { - public: - GLSurfaceOzoneEGL(scoped_ptr ozone_surface, - AcceleratedWidget widget) - : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), - ozone_surface_(ozone_surface.Pass()), - widget_(widget) {} - - bool Initialize() override { - return Initialize(ozone_surface_->CreateVSyncProvider()); - } - bool Resize(const gfx::Size& size) override { - if (!ozone_surface_->ResizeNativeWindow(size)) { - if (!ReinitializeNativeSurface() || - !ozone_surface_->ResizeNativeWindow(size)) - return false; - } - - return NativeViewGLSurfaceEGL::Resize(size); - } - bool SwapBuffers() override { - if (!NativeViewGLSurfaceEGL::SwapBuffers()) - return false; - - return ozone_surface_->OnSwapBuffers(); - } - bool ScheduleOverlayPlane(int z_order, - OverlayTransform transform, - GLImage* image, - const Rect& bounds_rect, - const RectF& crop_rect) override { - return image->ScheduleOverlayPlane( - widget_, z_order, transform, bounds_rect, crop_rect); - } - - private: - using NativeViewGLSurfaceEGL::Initialize; - - ~GLSurfaceOzoneEGL() override { - Destroy(); // EGL surface must be destroyed before SurfaceOzone - } - - bool ReinitializeNativeSurface() { - scoped_ptr scoped_make_current; - GLContext* current_context = GLContext::GetCurrent(); - bool was_current = - current_context && current_context->IsCurrent(this); - if (was_current) { - scoped_make_current.reset( - new ui::ScopedMakeCurrent(current_context, this)); - } - - Destroy(); - ozone_surface_ = - ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( - widget_).Pass(); - if (!ozone_surface_) { - LOG(ERROR) << "Failed to create native surface."; - return false; - } - - window_ = ozone_surface_->GetNativeWindow(); - if (!Initialize()) { - LOG(ERROR) << "Failed to initialize."; - return false; - } - - return true; - } - - // The native surface. Deleting this is allowed to free the EGLNativeWindow. - scoped_ptr ozone_surface_; - AcceleratedWidget widget_; - - DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); -}; - -class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { - public: - GLSurfaceOzoneSurfaceless(scoped_ptr ozone_surface, - AcceleratedWidget widget) - : SurfacelessEGL(gfx::Size()), - ozone_surface_(ozone_surface.Pass()), - widget_(widget), - has_implicit_external_sync_( - HasEGLExtension("EGL_ARM_implicit_external_sync")), - last_swap_buffers_result_(true), - weak_factory_(this) {} - - bool Initialize() override { - if (!SurfacelessEGL::Initialize()) - return false; - vsync_provider_ = ozone_surface_->CreateVSyncProvider(); - if (!vsync_provider_) - return false; - return true; - } - bool Resize(const gfx::Size& size) override { - if (!ozone_surface_->ResizeNativeWindow(size)) - return false; - - return SurfacelessEGL::Resize(size); - } - bool SwapBuffers() override { - glFlush(); - // TODO: the following should be replaced by a per surface flush as it gets - // implemented in GL drivers. - if (has_implicit_external_sync_) { - EGLSyncKHR fence = InsertFence(); - if (!fence) - return false; - - EGLDisplay display = GetDisplay(); - WaitForFence(display, fence); - eglDestroySyncKHR(display, fence); - } else if (ozone_surface_->IsUniversalDisplayLinkDevice()) { - glFinish(); - } - - return ozone_surface_->OnSwapBuffers(); - } - bool ScheduleOverlayPlane(int z_order, - OverlayTransform transform, - GLImage* image, - const Rect& bounds_rect, - const RectF& crop_rect) override { - return image->ScheduleOverlayPlane( - widget_, z_order, transform, bounds_rect, crop_rect); - } - bool IsOffscreen() override { return false; } - VSyncProvider* GetVSyncProvider() override { return vsync_provider_.get(); } - bool SupportsPostSubBuffer() override { return true; } - bool PostSubBuffer(int x, int y, int width, int height) override { - // The actual sub buffer handling is handled at higher layers. - SwapBuffers(); - return true; - } - bool SwapBuffersAsync(const SwapCompletionCallback& callback) override { - glFlush(); - // TODO: the following should be replaced by a per surface flush as it gets - // implemented in GL drivers. - if (has_implicit_external_sync_) { - // If last swap failed, don't try to schedule new ones. - if (!last_swap_buffers_result_) { - last_swap_buffers_result_ = true; - return false; - } - - EGLSyncKHR fence = InsertFence(); - if (!fence) - return false; - - base::Closure fence_wait_task = - base::Bind(&WaitForFence, GetDisplay(), fence); - - base::Closure fence_retired_callback = - base::Bind(&GLSurfaceOzoneSurfaceless::FenceRetired, - weak_factory_.GetWeakPtr(), fence, callback); - - base::WorkerPool::PostTaskAndReply(FROM_HERE, fence_wait_task, - fence_retired_callback, false); - return true; - } else if (ozone_surface_->IsUniversalDisplayLinkDevice()) { - glFinish(); - } - return ozone_surface_->OnSwapBuffersAsync(callback); - } - bool PostSubBufferAsync(int x, - int y, - int width, - int height, - const SwapCompletionCallback& callback) override { - return SwapBuffersAsync(callback); - } - - protected: - ~GLSurfaceOzoneSurfaceless() override { - Destroy(); // EGL surface must be destroyed before SurfaceOzone - } - - EGLSyncKHR InsertFence() { - const EGLint attrib_list[] = {EGL_SYNC_CONDITION_KHR, - EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM, - EGL_NONE}; - return eglCreateSyncKHR(GetDisplay(), EGL_SYNC_FENCE_KHR, attrib_list); - } - - void FenceRetired(EGLSyncKHR fence, const SwapCompletionCallback& callback) { - eglDestroySyncKHR(GetDisplay(), fence); - last_swap_buffers_result_ = ozone_surface_->OnSwapBuffersAsync(callback); - } - - // The native surface. Deleting this is allowed to free the EGLNativeWindow. - scoped_ptr ozone_surface_; - AcceleratedWidget widget_; - scoped_ptr vsync_provider_; - bool has_implicit_external_sync_; - bool last_swap_buffers_result_; - - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); -}; - -// This provides surface-like semantics implemented through surfaceless. -// A framebuffer is bound automatically. -class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl - : public GLSurfaceOzoneSurfaceless { - public: - GLSurfaceOzoneSurfacelessSurfaceImpl( - scoped_ptr ozone_surface, - AcceleratedWidget widget) - : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget), - fbo_(0), - current_surface_(0) { - for (auto& texture : textures_) - texture = 0; - } - - unsigned int GetBackingFrameBufferObject() override { return fbo_; } - - bool OnMakeCurrent(GLContext* context) override { - if (!fbo_) { - glGenFramebuffersEXT(1, &fbo_); - if (!fbo_) - return false; - glGenTextures(arraysize(textures_), textures_); - if (!CreatePixmaps()) - return false; - } - BindFramebuffer(); - glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); - return SurfacelessEGL::OnMakeCurrent(context); - } - - bool Resize(const gfx::Size& size) override { - if (size == GetSize()) - return true; - return GLSurfaceOzoneSurfaceless::Resize(size) && CreatePixmaps(); - } - - bool SupportsPostSubBuffer() override { return false; } - - bool SwapBuffers() override { - if (!images_[current_surface_]->ScheduleOverlayPlane( - widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, - gfx::Rect(GetSize()), gfx::RectF(1, 1))) - return false; - if (!GLSurfaceOzoneSurfaceless::SwapBuffers()) - return false; - current_surface_ ^= 1; - BindFramebuffer(); - return true; - } - - bool SwapBuffersAsync(const SwapCompletionCallback& callback) override { - if (!images_[current_surface_]->ScheduleOverlayPlane( - widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, - gfx::Rect(GetSize()), gfx::RectF(1, 1))) - return false; - if (!GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback)) - return false; - current_surface_ ^= 1; - BindFramebuffer(); - return true; - } - - void Destroy() override { - GLContext* current_context = GLContext::GetCurrent(); - DCHECK(current_context && current_context->IsCurrent(this)); - glBindFramebufferEXT(GL_FRAMEBUFFER, 0); - if (fbo_) { - glDeleteTextures(arraysize(textures_), textures_); - for (auto& texture : textures_) - texture = 0; - glDeleteFramebuffersEXT(1, &fbo_); - fbo_ = 0; - } - for (auto image : images_) { - if (image) - image->Destroy(true); - } - } - - private: - class SurfaceImage : public GLImageLinuxDMABuffer { - public: - SurfaceImage(const gfx::Size& size, unsigned internalformat) - : GLImageLinuxDMABuffer(size, internalformat) {} - - bool Initialize(scoped_refptr pixmap, - gfx::GpuMemoryBuffer::Format format) { - base::FileDescriptor handle(pixmap->GetDmaBufFd(), false); - if (!GLImageLinuxDMABuffer::Initialize(handle, format, - pixmap->GetDmaBufPitch())) - return false; - pixmap_ = pixmap; - return true; - } - bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, - int z_order, - gfx::OverlayTransform transform, - const gfx::Rect& bounds_rect, - const gfx::RectF& crop_rect) override { - return ui::SurfaceFactoryOzone::GetInstance()->ScheduleOverlayPlane( - widget, z_order, transform, pixmap_, bounds_rect, crop_rect); - } - - private: - ~SurfaceImage() override {} - - scoped_refptr pixmap_; - }; - - ~GLSurfaceOzoneSurfacelessSurfaceImpl() override { - DCHECK(!fbo_); - for (size_t i = 0; i < arraysize(textures_); i++) - DCHECK(!textures_[i]) << "texture " << i << " not released"; - } - - void BindFramebuffer() { - ScopedFrameBufferBinder fb(fbo_); - glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, textures_[current_surface_], 0); - } - - bool CreatePixmaps() { - if (!fbo_) - return true; - for (size_t i = 0; i < arraysize(textures_); i++) { - scoped_refptr pixmap = - ui::SurfaceFactoryOzone::GetInstance()->CreateNativePixmap( - widget_, GetSize(), ui::SurfaceFactoryOzone::RGBA_8888, - ui::SurfaceFactoryOzone::SCANOUT); - if (!pixmap) - return false; - scoped_refptr image = new SurfaceImage(GetSize(), GL_RGBA); - if (!image->Initialize(pixmap, gfx::GpuMemoryBuffer::Format::BGRA_8888)) - return false; - images_[i] = image; - // Bind image to texture. - ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); - if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) - return false; - } - return true; - } - - GLuint fbo_; - GLuint textures_[2]; - scoped_refptr images_[2]; - int current_surface_; - DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); -}; - -} // namespace - -// static -bool GLSurface::InitializeOneOffInternal() { - switch (GetGLImplementation()) { - case kGLImplementationEGLGLES2: - if (!GLSurfaceEGL::InitializeOneOff()) { - LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; - return false; - } - - return true; - case kGLImplementationOSMesaGL: - case kGLImplementationMockGL: - return true; - default: - return false; - } -} - -// static -scoped_refptr GLSurface::CreateSurfacelessViewGLSurface( - gfx::AcceleratedWidget window) { - if (GetGLImplementation() == kGLImplementationEGLGLES2 && - window != kNullAcceleratedWidget && - GLSurfaceEGL::IsEGLSurfacelessContextSupported() && - ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) { - scoped_ptr surface_ozone = - ui::SurfaceFactoryOzone::GetInstance() - ->CreateSurfacelessEGLSurfaceForWidget(window); - if (!surface_ozone) - return nullptr; - scoped_refptr surface; - surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); - if (surface->Initialize()) - return surface; - } - - return nullptr; -} - -// static -scoped_refptr GLSurface::CreateViewGLSurface( - gfx::AcceleratedWidget window) { - if (GetGLImplementation() == kGLImplementationOSMesaGL) { - scoped_refptr surface(new GLSurfaceOSMesaHeadless()); - if (!surface->Initialize()) - return NULL; - return surface; - } - DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); - if (window != kNullAcceleratedWidget) { - scoped_refptr surface; - if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && - ui::SurfaceFactoryOzone::GetInstance() - ->CanShowPrimaryPlaneAsOverlay()) { - scoped_ptr surface_ozone = - ui::SurfaceFactoryOzone::GetInstance() - ->CreateSurfacelessEGLSurfaceForWidget(window); - if (!surface_ozone) - return NULL; - surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(), - window); - } else { - scoped_ptr surface_ozone = - ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( - window); - if (!surface_ozone) - return NULL; - - surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); - } - if (!surface->Initialize()) - return NULL; - return surface; - } else { - scoped_refptr surface = new GLSurfaceStub(); - if (surface->Initialize()) - return surface; - } - return NULL; -} - -// static -scoped_refptr GLSurface::CreateOffscreenGLSurface( - const gfx::Size& size) { - switch (GetGLImplementation()) { - case kGLImplementationOSMesaGL: { - scoped_refptr surface( - new GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, size)); - if (!surface->Initialize()) - return NULL; - - return surface; - } - case kGLImplementationEGLGLES2: { - scoped_refptr surface; - if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && - (size.width() == 0 && size.height() == 0)) { - surface = new SurfacelessEGL(size); - } else - surface = new PbufferGLSurfaceEGL(size); - - if (!surface->Initialize()) - return NULL; - return surface; - } - default: - NOTREACHED(); - return NULL; - } -} - -EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { - return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); -} - -} // namespace gfx