2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "EGLSurface.h"
29 #if USE(EGL) && USE(GRAPHICS_SURFACE)
33 EGLWindowTransportSurface::EGLWindowTransportSurface()
36 m_configSelector = adoptPtr(new EGLConfigSelector(NativeWrapper::nativeDisplay()));
37 m_sharedDisplay = m_configSelector->display();
39 if (m_sharedDisplay == EGL_NO_DISPLAY) {
40 m_configSelector = nullptr;
44 EGLConfig config = m_configSelector->surfaceContextConfig();
51 EGLint visualId = m_configSelector->nativeVisualId(config);
58 NativeWrapper::createOffScreenWindow(&m_bufferHandle, visualId);
60 if (!m_bufferHandle) {
65 m_drawable = eglCreateWindowSurface(m_sharedDisplay, m_configSelector->surfaceContextConfig(), (EGLNativeWindowType)m_bufferHandle, 0);
67 if (m_drawable == EGL_NO_SURFACE) {
68 LOG_ERROR("Failed to create EGL surface(%d).", eglGetError());
73 EGLWindowTransportSurface::~EGLWindowTransportSurface()
77 PlatformSurfaceConfig EGLWindowTransportSurface::configuration()
79 return m_configSelector->surfaceContextConfig();
82 void EGLWindowTransportSurface::swapBuffers()
87 EGLBoolean success = eglBindAPI(eglAPIVersion);
89 if (success != EGL_TRUE) {
90 LOG_ERROR("Failed to set EGL API(%d).", eglGetError());
94 success = eglSwapBuffers(m_sharedDisplay, m_drawable);
96 if (success != EGL_TRUE) {
97 LOG_ERROR("Failed to SwapBuffers(%d).", eglGetError());
102 void EGLWindowTransportSurface::destroy()
104 GLPlatformSurface::destroy();
105 NativeWrapper::destroyWindow(m_bufferHandle);
110 void EGLWindowTransportSurface::freeEGLResources()
112 if (m_drawable == EGL_NO_SURFACE || m_sharedDisplay == EGL_NO_DISPLAY)
115 EGLBoolean eglResult = eglBindAPI(eglAPIVersion);
117 if (eglResult != EGL_TRUE) {
118 LOG_ERROR("Failed to set EGL API(%d).", eglGetError());
122 eglDestroySurface(m_sharedDisplay, m_drawable);
123 m_drawable = EGL_NO_SURFACE;
126 void EGLWindowTransportSurface::setGeometry(const IntRect& newRect)
128 GLPlatformSurface::setGeometry(newRect);
129 NativeWrapper::resizeWindow(newRect, m_bufferHandle);