2
* Copyright (C) 2019 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#if ENABLE(GRAPHICS_CONTEXT_GL) && USE(ANGLE)
29
#include "ExtensionsGLANGLE.h"
31
#include "GraphicsContextGLOpenGL.h"
33
#include <ANGLE/entry_points_gles_2_0_autogen.h>
34
#include <ANGLE/entry_points_gles_3_0_autogen.h>
35
// Skip the inclusion of ANGLE's explicit context entry points for now.
36
#define GL_ANGLE_explicit_context
37
#define GL_ANGLE_explicit_context_gles1
38
typedef void* GLeglContext;
39
#include <ANGLE/entry_points_gles_ext_autogen.h>
41
// Note: this file can't be compiled in the same unified source file
42
// as others which include the system's OpenGL headers.
46
ExtensionsGLANGLE::ExtensionsGLANGLE(GraphicsContextGLOpenGL* context, bool useIndexedGetString)
47
: m_initializedAvailableExtensions(false)
52
, m_isImagination(false)
53
, m_requiresBuiltInFunctionEmulation(false)
54
, m_requiresRestrictedMaximumTextureSize(false)
55
, m_useIndexedGetString(useIndexedGetString)
57
// FIXME: ideally, remove this initialization altogether. ANGLE
58
// subsumes the responsibility for graphics driver workarounds.
59
m_vendor = String(reinterpret_cast<const char*>(gl::GetString(GL_VENDOR)));
60
m_renderer = String(reinterpret_cast<const char*>(gl::GetString(GL_RENDERER)));
62
Vector<String> vendorComponents = m_vendor.convertToASCIILowercase().split(' ');
63
if (vendorComponents.contains("nvidia"))
65
if (vendorComponents.contains("ati") || vendorComponents.contains("amd"))
67
if (vendorComponents.contains("intel"))
69
if (vendorComponents.contains("imagination"))
70
m_isImagination = true;
73
ExtensionsGLANGLE::~ExtensionsGLANGLE() = default;
75
bool ExtensionsGLANGLE::supports(const String& name)
77
if (!m_initializedAvailableExtensions)
78
initializeAvailableExtensions();
80
return supportsExtension(name);
83
void ExtensionsGLANGLE::ensureEnabled(const String& name)
85
// Enable support in ANGLE (if not enabled already).
86
if (m_requestableExtensions.contains(name) && !m_enabledExtensions.contains(name)) {
87
m_context->makeContextCurrent();
88
gl::RequestExtensionANGLE(name.ascii().data());
89
m_enabledExtensions.add(name);
93
bool ExtensionsGLANGLE::isEnabled(const String& name)
95
return m_availableExtensions.contains(name) || m_enabledExtensions.contains(name);
98
int ExtensionsGLANGLE::getGraphicsResetStatusARB()
100
return GraphicsContextGL::NO_ERROR;
103
String ExtensionsGLANGLE::getTranslatedShaderSourceANGLE(PlatformGLObject shader)
105
int sourceLength = 0;
106
m_context->getShaderiv(shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &sourceLength);
108
return emptyString();
109
Vector<GLchar> name(sourceLength); // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE includes null termination.
110
int returnedLength = 0;
111
gl::GetTranslatedShaderSourceANGLE(shader, sourceLength, &returnedLength, name.data());
113
return emptyString();
114
// returnedLength does not include the null terminator.
115
ASSERT(returnedLength == sourceLength - 1);
116
return String(name.data(), returnedLength);
119
void ExtensionsGLANGLE::initializeAvailableExtensions()
121
if (m_useIndexedGetString) {
122
GLint numExtensions = 0;
123
gl::GetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
124
for (GLint i = 0; i < numExtensions; ++i)
125
m_availableExtensions.add(gl::GetStringi(GL_EXTENSIONS, i));
126
gl::GetIntegerv(GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE, &numExtensions);
127
for (GLint i = 0; i < numExtensions; ++i)
128
m_requestableExtensions.add(gl::GetStringi(GL_REQUESTABLE_EXTENSIONS_ANGLE, i));
130
String extensionsString = getExtensions();
131
for (auto& extension : extensionsString.split(' '))
132
m_availableExtensions.add(extension);
133
extensionsString = String(reinterpret_cast<const char*>(gl::GetString(GL_REQUESTABLE_EXTENSIONS_ANGLE)));
134
for (auto& extension : extensionsString.split(' '))
135
m_requestableExtensions.add(extension);
137
m_initializedAvailableExtensions = true;
140
void ExtensionsGLANGLE::readnPixelsEXT(int, int, GCGLsizei, GCGLsizei, GCGLenum, GCGLenum, GCGLsizei, void *)
142
m_context->synthesizeGLError(GL_INVALID_OPERATION);
145
void ExtensionsGLANGLE::getnUniformfvEXT(GCGLuint, int, GCGLsizei, float *)
147
m_context->synthesizeGLError(GL_INVALID_OPERATION);
150
void ExtensionsGLANGLE::getnUniformivEXT(GCGLuint, int, GCGLsizei, int *)
152
m_context->synthesizeGLError(GL_INVALID_OPERATION);
155
void ExtensionsGLANGLE::blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter)
157
// FIXME: consider adding support for APPLE_framebuffer_multisample.
158
gl::BlitFramebufferANGLE(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
161
void ExtensionsGLANGLE::renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height)
163
gl::RenderbufferStorageMultisampleANGLE(target, samples, internalformat, width, height);
166
PlatformGLObject ExtensionsGLANGLE::createVertexArrayOES()
168
m_context->makeContextCurrent();
170
gl::GenVertexArraysOES(1, &array);
174
void ExtensionsGLANGLE::deleteVertexArrayOES(PlatformGLObject array)
179
m_context->makeContextCurrent();
180
gl::DeleteVertexArraysOES(1, &array);
183
GCGLboolean ExtensionsGLANGLE::isVertexArrayOES(PlatformGLObject array)
188
m_context->makeContextCurrent();
189
return gl::IsVertexArrayOES(array);
192
void ExtensionsGLANGLE::bindVertexArrayOES(PlatformGLObject array)
194
m_context->makeContextCurrent();
195
gl::BindVertexArrayOES(array);
198
void ExtensionsGLANGLE::insertEventMarkerEXT(const String&)
200
// FIXME: implement this function and add GL_EXT_debug_marker in supports().
204
void ExtensionsGLANGLE::pushGroupMarkerEXT(const String&)
206
// FIXME: implement this function and add GL_EXT_debug_marker in supports().
210
void ExtensionsGLANGLE::popGroupMarkerEXT(void)
212
// FIXME: implement this function and add GL_EXT_debug_marker in supports().
216
bool ExtensionsGLANGLE::supportsExtension(const String& name)
218
return m_availableExtensions.contains(name) || m_requestableExtensions.contains(name);
221
void ExtensionsGLANGLE::drawBuffersEXT(GCGLsizei n, const GCGLenum* bufs)
223
gl::DrawBuffersEXT(n, bufs);
226
void ExtensionsGLANGLE::drawArraysInstanced(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei primcount)
228
m_context->makeContextCurrent();
229
gl::DrawArraysInstancedANGLE(mode, first, count, primcount);
232
void ExtensionsGLANGLE::drawElementsInstanced(GCGLenum mode, GCGLsizei count, GCGLenum type, long long offset, GCGLsizei primcount)
234
m_context->makeContextCurrent();
235
gl::DrawElementsInstancedANGLE(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)), primcount);
238
void ExtensionsGLANGLE::vertexAttribDivisor(GCGLuint index, GCGLuint divisor)
240
m_context->makeContextCurrent();
241
gl::VertexAttribDivisorANGLE(index, divisor);
244
String ExtensionsGLANGLE::getExtensions()
246
return String(reinterpret_cast<const char*>(gl::GetString(GL_EXTENSIONS)));
249
} // namespace WebCore
251
#endif // ENABLE(GRAPHICS_CONTEXT_GL) && USE(ANGLE)