)
ELSEIF (WTF_PLATFORM_WAYLAND)
LIST(APPEND WebCore_SOURCES
+ platform/graphics/surfaces/egl/EGLWaylandSurface.cpp
platform/graphics/surfaces/wayland/WaylandHelper.cpp
)
ENDIF()
m_currentDrawable = this;
}
+void GLPlatformSurface::releaseCurrent()
+{
+ if (this == m_currentDrawable)
+ m_currentDrawable = 0;
+}
+
GLPlatformSurface* GLPlatformSurface::getCurrent()
{
return m_currentDrawable;
virtual bool isCurrentDrawable() const;
virtual void onMakeCurrent();
+ void releaseCurrent();
// Convenience Function to update surface backbuffer with texture contents.
// Note that the function doesn't track or restore any GL states.
#include "config.h"
#include "EGLContext.h"
-#if USE(EGL)
+#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include "EGLHelper.h"
#include <wtf/text/WTFString.h>
EGL_NONE
};
-static bool isRobustnessExtSupported(EGLDisplay display)
-{
- static bool didQueryForRobustnessExtension = false;
- static bool isRobustnessExtensionSupported = false;
-
- if (!didQueryForRobustnessExtension) {
- didQueryForRobustnessExtension = true;
- isRobustnessExtensionSupported = GLPlatformContext::supportsEGLExtension(display, "EGL_EXT_create_context_robustness");
- }
-
- return isRobustnessExtensionSupported;
-}
-
EGLOffScreenContext::EGLOffScreenContext()
: GLPlatformContext()
{
if (!config)
return false;
- if (isRobustnessExtSupported(display))
+ static bool isRobustnessExtensionSupported = GLPlatformContext::supportsEGLExtension(display, "EGL_EXT_create_context_robustness");
+ if (isRobustnessExtensionSupported)
m_contextHandle = eglCreateContext(display, config, sharedContext, contextRobustnessAttributes);
if (m_contextHandle != EGL_NO_CONTEXT) {
// EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT bit set must also support GL_EXT_robustness or
// a version of OpenGL incorporating equivalent functionality.
// The spec also defines similar requirements for attribute EGL_LOSE_CONTEXT_ON_RESET_EXT.
- if (platformMakeCurrent(surface) && (GLPlatformContext::supportsGLExtension("GL_EXT_robustness")))
+ GLPlatformContext* currentContext = GLPlatformContext::getCurrent();
+ GLPlatformSurface* currentSurface = GLPlatformSurface::getCurrent();
+
+ if (GLPlatformContext::makeCurrent(surface) && (GLPlatformContext::supportsGLExtension("GL_EXT_robustness")))
m_resetLostContext = true;
else
eglDestroyContext(display, m_contextHandle);
+
+ if (currentContext && currentSurface)
+ currentContext->makeCurrent(currentSurface);
+ else {
+ releaseCurrent();
+ surface->releaseCurrent();
+ }
}
if (m_contextHandle == EGL_NO_CONTEXT)
EGLOffScreenContext::~EGLOffScreenContext()
{
- platformReleaseCurrent();
- destroy();
+ if (m_contextHandle) {
+ platformReleaseCurrent();
+ destroy();
+ }
}
bool EGLOffScreenContext::isCurrentContext() const
#include "config.h"
#include "EGLHelper.h"
-#if USE(EGL)
+#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include <opengl/GLPlatformContext.h>
if (m_eglDisplay == EGL_NO_DISPLAY)
return;
+ eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(m_eglDisplay);
+ eglReleaseThread();
m_eglDisplay = EGL_NO_DISPLAY;
}
return display;
}
-void EGLHelper::resolveEGLBindings()
+void EGLHelper::resolveEGLBindings(EGLDisplay eglDisplay)
{
static bool initialized = false;
initialized = true;
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return;
- if (GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_image") && GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_image_pixmap") && GLPlatformContext::supportsGLExtension("GL_OES_EGL_image")) {
- eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
- eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
- eglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
- }
-
if (GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_lock_surface")) {
eglLockSurfaceKHR = (PFNEGLLOCKSURFACEKHRPROC)eglGetProcAddress("eglLockSurfaceKHR");
eglUnlockSurfaceKHR = (PFNEGLUNLOCKSURFACEKHRPROC)eglGetProcAddress("eglUnlockSurfaceKHR");
}
+
+ if (!GLPlatformContext::supportsGLExtension("GL_OES_EGL_image")) {
+ LOG_ERROR("Platform doesn't support GL_OES_EGL_image. Support for this extension is required for Hardware Acceleration.");
+ return;
+ }
+
+#if PLATFORM(WAYLAND)
+ if (GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_image_base") && GLPlatformContext::supportsEGLExtension(display, "EGL_WL_bind_wayland_display")) {
+#else
+ if (GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_image") && GLPlatformContext::supportsEGLExtension(display, "EGL_KHR_image_pixmap")) {
+#endif
+ eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
+ eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
+ eglImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
+ } else
+#if PLATFORM(WAYLAND)
+ LOG_ERROR("Platform doesn't support EGL_KHR_image_base or EGL_WL_bind_wayland_display. Support for these extensions is required for Hardware Acceleration.");
+#else
+ LOG_ERROR("Platform doesn't support EGL_KHR_image or EGL_KHR_image_pixmap. Support for these extensions is required for Hardware Acceleration.");
+#endif
}
-void EGLHelper::createEGLImage(EGLImageKHR* image, GLenum target, const EGLClientBuffer clientBuffer, const EGLint attributes[])
+void EGLHelper::createEGLImage(EGLImageKHR* image, GLenum target, const EGLClientBuffer clientBuffer, const EGLint attributes[], EGLDisplay eglDisplay)
{
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return;
EGLImageKHR tempHandle = EGL_NO_IMAGE_KHR;
-
if (eglCreateImageKHR && eglImageTargetTexture2DOES && eglDestroyImageKHR)
- tempHandle = eglCreateImageKHR(display, EGL_NO_CONTEXT, target, clientBuffer, attributes);
+ tempHandle = eglCreateImageKHR(display, EGL_NO_CONTEXT, target, clientBuffer, attributes);
*image = tempHandle;
}
-void EGLHelper::destroyEGLImage(const EGLImageKHR image)
+void EGLHelper::destroyEGLImage(const EGLImageKHR image, EGLDisplay eglDisplay)
{
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return;
void EGLHelper::imageTargetTexture2DOES(const EGLImageKHR image)
{
- eglImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast<GLeglImageOES>(image));
+ if (eglImageTargetTexture2DOES)
+ eglImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast<GLeglImageOES>(image));
}
-bool EGLHelper::lockSurface(EGLSurface surface, EGLint lockAttrib[])
+bool EGLHelper::lockSurface(EGLSurface surface, EGLint lockAttrib[], EGLDisplay eglDisplay)
{
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return false;
return true;
}
-bool EGLHelper::unlockSurface(EGLSurface surface)
+bool EGLHelper::unlockSurface(EGLSurface surface, EGLDisplay eglDisplay)
{
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return false;
return true;
}
-bool EGLHelper::querySurface(EGLSurface surface, EGLint attribute, EGLint* value)
+bool EGLHelper::querySurface(EGLSurface surface, EGLint attribute, EGLint* value, EGLDisplay eglDisplay)
{
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return false;
LOG_ERROR("'%s' returned egl error '%s' (0x%x)\n", name, egErrorStrings[errorCode - EGL_SUCCESS], errorCode);
}
-bool EGLHelper::isVendor(const String& vendorName)
+bool EGLHelper::isVendor(const String& vendorName, EGLDisplay eglDisplay)
{
static Vector<String> vendorComponents;
if (!vendorComponents.size()) {
- EGLDisplay display = currentDisplay();
+ EGLDisplay display = eglDisplay;
+ if (display == EGL_NO_DISPLAY)
+ display = currentDisplay();
if (display == EGL_NO_DISPLAY)
return false;
#ifndef EGLHelper_h
#define EGLHelper_h
-#if USE(EGL)
+#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include "EGLSurface.h"
+#if PLATFORM(WAYLAND)
+#include "WaylandHelper.h"
+#endif
#include <wtf/text/WTFString.h>
#define GL_GLEXT_PROTOTYPES 1
public:
static PlatformDisplay eglDisplay();
static PlatformDisplay currentDisplay();
- static void resolveEGLBindings();
- static void createEGLImage(EGLImageKHR*, GLenum, const EGLClientBuffer, const EGLint* = 0);
- static void destroyEGLImage(const EGLImageKHR);
+ static void resolveEGLBindings(EGLDisplay = EGL_NO_DISPLAY);
+ static void createEGLImage(EGLImageKHR*, GLenum, const EGLClientBuffer, const EGLint* = 0, EGLDisplay = EGL_NO_DISPLAY);
+ static void destroyEGLImage(const EGLImageKHR, EGLDisplay = EGL_NO_DISPLAY);
static void imageTargetTexture2DOES(const EGLImageKHR);
- static bool isVendor(const String&);
+ static bool isVendor(const String&, EGLDisplay = EGL_NO_DISPLAY);
static void HandleEGLError(const char* name);
- static bool lockSurface(EGLSurface, EGLint[]);
- static bool unlockSurface(EGLSurface);
- static bool querySurface(EGLSurface, EGLint, EGLint*);
+ static bool lockSurface(EGLSurface, EGLint[], EGLDisplay = EGL_NO_DISPLAY);
+ static bool unlockSurface(EGLSurface, EGLDisplay = EGL_NO_DISPLAY);
+ static bool querySurface(EGLSurface, EGLint, EGLint*, EGLDisplay = EGL_NO_DISPLAY);
};
}
#include "config.h"
#include "EGLSurface.h"
-#if USE(EGL)
+#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include "EGLConfigSelector.h"
#include "EGLHelper.h"
-#include "GLPlatformContext.h"
#if PLATFORM(X11)
#include "EGLXSurface.h"
+#elif PLATFORM(WAYLAND)
+#include "EGLWaylandSurface.h"
#endif
+#include <wtf/UnusedParam.h>
namespace WebCore {
PassOwnPtr<GLPlatformSurface> EGLTransportSurface::createTransportSurface(const IntSize& size, SurfaceAttributes attributes)
PlatformSurfaceConfig EGLTransportSurface::configuration()
{
- return m_configSelector->pixmapContextConfig();
+ return m_configSelector->surfaceContextConfig();
}
PassOwnPtr<GLPlatformSurface> EGLOffScreenSurface::createOffScreenSurface(const IntSize& size, SurfaceAttributes attributes)
OwnPtr<GLPlatformSurface> surface;
#if PLATFORM(X11)
surface = adoptPtr(new EGLPixmapSurface(size, attributes));
+#elif PLATFORM(WAYLAND)
+ SurfaceAttributes surfaceAttributes = attributes;
+ surfaceAttributes |= GLPlatformSurface::DoubleBuffered;
+ surface = adoptPtr(new EGLWindowSurface(size, surfaceAttributes));
#else
UNUSED_PARAM(attributes);
#endif
- if (surface)
+ if (surface && surface->handle() && surface->drawable())
return surface.release();
+ LOG_ERROR("Failed to create EGL OffscreenSurface.");
return nullptr;
}
if (m_sharedDisplay == EGL_NO_DISPLAY || m_drawable == EGL_NO_SURFACE)
return;
+ GLPlatformSurface::destroy();
+
if (m_drawable) {
eglDestroySurface(m_sharedDisplay, m_drawable);
m_drawable = EGL_NO_SURFACE;
#ifndef EGLSurface_h
#define EGLSurface_h
-#if USE(EGL)
+#if USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
#include "GLPlatformSurface.h"
#include <wtf/PassOwnPtr.h>
#if PLATFORM(WAYLAND)
#include <wayland-client.h>
#include <wayland-egl.h>
+#include <wayland-server.h>
#endif
#define EGL_EGLEXT_PROTOTYPES 1
#include <EGL/egl.h>
#include <EGL/eglext.h>
+#if PLATFORM(WAYLAND)
+#include <EGL/eglmesaext.h>
+#endif
+
#define GL_GLEXT_PROTOTYPES 1
#if USE(OPENGL_ES_2)
#include <GLES2/gl2.h>
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EGLWaylandSurface.h"
+
+#if PLATFORM(WAYLAND) && (USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE))
+
+#include "EGLConfigSelector.h"
+#include "EGLHelper.h"
+#include "WaylandHelper.h"
+
+#include <wtf/UnusedParam.h>
+
+namespace WebCore {
+static int sharedBufferHandle = 0;
+EGLWindowSurface::EGLWindowSurface(const IntSize& size, GLPlatformSurface::SurfaceAttributes attributes)
+ : EGLOffScreenSurface(attributes)
+ , m_nativeWindow(0)
+ , m_surface(0)
+{
+ if (!m_configSelector)
+ return;
+
+ if (!m_configSelector->surfaceContextConfig()) {
+ destroy();
+ return;
+ }
+
+ m_surface = wl_compositor_create_surface(WaylandHelper::compositor());
+
+ if (!m_surface) {
+ LOG_ERROR("Failed to create surface.");
+ destroy();
+ return;
+ }
+
+ m_nativeWindow = wl_egl_window_create(m_surface, size.width(), size.height());
+
+ if (!m_nativeWindow) {
+ LOG_ERROR("Failed to create Native Window.");
+ destroy();
+ return;
+ }
+
+ m_drawable = eglCreateWindowSurface(m_sharedDisplay, m_configSelector->surfaceContextConfig(), m_nativeWindow, 0);
+
+ if (m_drawable == EGL_NO_SURFACE) {
+ LOG_ERROR("Failed to create EGL surface(%d).", eglGetError());
+ destroy();
+ return;
+ }
+
+ sharedBufferHandle++;
+ m_bufferHandle = sharedBufferHandle;
+}
+
+EGLWindowSurface::~EGLWindowSurface()
+{
+ if (m_nativeWindow || m_surface || (m_drawable != EGL_NO_SURFACE))
+ LOG_ERROR("Resources not destroyed for surface with id: %d", m_bufferHandle);
+
+ m_bufferHandle = 0;
+}
+
+void EGLWindowSurface::swapBuffers()
+{
+ if (!eglSwapBuffers(m_sharedDisplay, m_drawable))
+ LOG_ERROR("Failed to SwapBuffers(%d).", eglGetError());
+
+ wl_display_dispatch(WaylandHelper::nativeDisplay());
+}
+
+void EGLWindowSurface::destroy()
+{
+ EGLOffScreenSurface::destroy();
+
+ if (!m_nativeWindow && !m_surface)
+ return;
+
+ if (m_nativeWindow) {
+ wl_egl_window_destroy(m_nativeWindow);
+ m_nativeWindow = 0;
+ }
+
+ if (m_surface) {
+ wl_surface_destroy(m_surface);
+ m_surface = 0;
+ }
+}
+
+PlatformSurfaceConfig EGLWindowSurface::configuration()
+{
+ return m_configSelector->surfaceContextConfig();
+}
+
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EGLWaylandSurface_h
+#define EGLWaylandSurface_h
+
+#if PLATFORM(WAYLAND) && (USE(EGL) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE))
+
+#include "EGLSurface.h"
+
+namespace WebCore {
+
+// Contents of the surface are backed by native window.
+class EGLWindowSurface : public EGLOffScreenSurface {
+public:
+ EGLWindowSurface(const IntSize&, GLPlatformSurface::SurfaceAttributes);
+ virtual ~EGLWindowSurface();
+ virtual void swapBuffers() OVERRIDE;
+ virtual void destroy() OVERRIDE;
+ virtual PlatformSurfaceConfig configuration() OVERRIDE;
+
+private:
+ struct wl_egl_window* m_nativeWindow;
+ struct wl_surface* m_surface;
+};
+
+}
+
+#endif
+
+#endif