|
Line 0
Source/WebCore/platform/graphics/surfaces/egl/EGLConfigSelector.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2012 Intel Corporation. All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
| 6 |
* are met: |
| 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. |
| 12 |
* |
| 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. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "config.h" |
| 27 |
#include "EGLConfigSelector.h" |
| 28 |
|
| 29 |
#if USE(EGL) |
| 30 |
|
| 31 |
namespace WebCore { |
| 32 |
|
| 33 |
SharedEGLDisplay* SharedEGLDisplay::m_staticSharedEGLDisplay = 0; |
| 34 |
|
| 35 |
static EGLint configAttributeList[] = { |
| 36 |
#if USE(OPENGL_ES_2) |
| 37 |
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 38 |
#else |
| 39 |
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
| 40 |
#endif |
| 41 |
EGL_RED_SIZE, 8, |
| 42 |
EGL_GREEN_SIZE, 8, |
| 43 |
EGL_BLUE_SIZE, 8, |
| 44 |
EGL_STENCIL_SIZE, 8, |
| 45 |
EGL_ALPHA_SIZE, 8, |
| 46 |
EGL_SURFACE_TYPE, EGL_NONE, |
| 47 |
EGL_NONE |
| 48 |
}; |
| 49 |
|
| 50 |
void SharedEGLDisplay::deref() |
| 51 |
{ |
| 52 |
if (derefBase()) { |
| 53 |
m_staticSharedEGLDisplay = 0; |
| 54 |
delete this; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
EGLDisplay SharedEGLDisplay::sharedEGLDisplay() const |
| 59 |
{ |
| 60 |
return m_eglDisplay; |
| 61 |
} |
| 62 |
|
| 63 |
SharedEGLDisplay::SharedEGLDisplay(NativeSharedDisplay* display) |
| 64 |
: m_eglDisplay(EGL_NO_DISPLAY) |
| 65 |
{ |
| 66 |
if (display) |
| 67 |
m_eglDisplay = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(display)); |
| 68 |
else |
| 69 |
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 70 |
|
| 71 |
if (m_eglDisplay == EGL_NO_DISPLAY) { |
| 72 |
LOG_ERROR("EGLDisplay Initialization failed."); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
EGLBoolean success; |
| 77 |
success = eglInitialize(m_eglDisplay, 0, 0); |
| 78 |
|
| 79 |
if (success != EGL_TRUE) { |
| 80 |
LOG_ERROR("EGLInitialization failed."); |
| 81 |
m_eglDisplay = EGL_NO_DISPLAY; |
| 82 |
} |
| 83 |
|
| 84 |
success = eglBindAPI(eglAPIVersion); |
| 85 |
|
| 86 |
if (success != EGL_TRUE) { |
| 87 |
LOG_ERROR("Failed to set EGL API(%d).", eglGetError()); |
| 88 |
m_eglDisplay = EGL_NO_DISPLAY; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void SharedEGLDisplay::cleanup() |
| 93 |
{ |
| 94 |
if (m_eglDisplay == EGL_NO_DISPLAY) |
| 95 |
return; |
| 96 |
|
| 97 |
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 98 |
eglTerminate(m_eglDisplay); |
| 99 |
m_eglDisplay = EGL_NO_DISPLAY; |
| 100 |
} |
| 101 |
|
| 102 |
SharedEGLDisplay::~SharedEGLDisplay() |
| 103 |
{ |
| 104 |
cleanup(); |
| 105 |
} |
| 106 |
|
| 107 |
EGLConfigSelector::EGLConfigSelector(NativeSharedDisplay* display) |
| 108 |
: m_pbufferFBConfig(0) |
| 109 |
, m_surfaceContextFBConfig(0) |
| 110 |
{ |
| 111 |
m_sharedDisplay = SharedEGLDisplay::create(display); |
| 112 |
} |
| 113 |
|
| 114 |
EGLConfigSelector::~EGLConfigSelector() |
| 115 |
{ |
| 116 |
} |
| 117 |
|
| 118 |
PlatformDisplay EGLConfigSelector::display() const |
| 119 |
{ |
| 120 |
return m_sharedDisplay->sharedEGLDisplay(); |
| 121 |
} |
| 122 |
|
| 123 |
EGLConfig EGLConfigSelector::pBufferContextConfig() |
| 124 |
{ |
| 125 |
if (!m_pbufferFBConfig) { |
| 126 |
configAttributeList[13] = EGL_PIXMAP_BIT; |
| 127 |
m_pbufferFBConfig = createConfig(configAttributeList); |
| 128 |
} |
| 129 |
|
| 130 |
return m_pbufferFBConfig; |
| 131 |
} |
| 132 |
|
| 133 |
EGLConfig EGLConfigSelector::surfaceContextConfig() |
| 134 |
{ |
| 135 |
if (!m_surfaceContextFBConfig) { |
| 136 |
configAttributeList[13] = EGL_WINDOW_BIT; |
| 137 |
m_surfaceContextFBConfig = createConfig(configAttributeList); |
| 138 |
} |
| 139 |
|
| 140 |
return m_surfaceContextFBConfig; |
| 141 |
} |
| 142 |
|
| 143 |
EGLint EGLConfigSelector::nativeVisualId(const EGLConfig& config) const |
| 144 |
{ |
| 145 |
if (display() == EGL_NO_DISPLAY) |
| 146 |
return -1; |
| 147 |
|
| 148 |
EGLint eglValue = 0; |
| 149 |
eglGetConfigAttrib(display(), config, EGL_NATIVE_VISUAL_ID, &eglValue); |
| 150 |
|
| 151 |
return eglValue; |
| 152 |
} |
| 153 |
|
| 154 |
void EGLConfigSelector::reset() |
| 155 |
{ |
| 156 |
m_surfaceContextFBConfig = 0; |
| 157 |
m_pbufferFBConfig = 0; |
| 158 |
} |
| 159 |
|
| 160 |
EGLConfig EGLConfigSelector::createConfig(const int attributes[]) |
| 161 |
{ |
| 162 |
if (display() == EGL_NO_DISPLAY) |
| 163 |
return 0; |
| 164 |
|
| 165 |
int numConfigs; |
| 166 |
EGLConfig config = 0; |
| 167 |
|
| 168 |
if (!eglChooseConfig(display(), attributes, &config, 1, &numConfigs)) |
| 169 |
LOG_ERROR("Failed to get supported configirations."); |
| 170 |
|
| 171 |
if (numConfigs != 1) { |
| 172 |
LOG_ERROR("EGLChooseConfig didn't return exactly one config but (%d).", numConfigs); |
| 173 |
config = 0; |
| 174 |
} |
| 175 |
|
| 176 |
return config; |
| 177 |
} |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
#endif |