blob: b7f86640b5eac47b8a2474c1df81ba482afaa7bb [file] [log] [blame]
Mathias Agopian875d8e12013-06-07 15:35:48 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathias Agopian875d8e12013-06-07 15:35:48 -070017#include <stdint.h>
Chia-I Wub027f802017-11-29 14:00:52 -080018#include <stdio.h>
19#include <stdlib.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070020
21#include "GLExtensions.h"
22
23namespace android {
24// ---------------------------------------------------------------------------
25
Chia-I Wub027f802017-11-29 14:00:52 -080026ANDROID_SINGLETON_STATIC_INSTANCE(GLExtensions)
Mathias Agopian875d8e12013-06-07 15:35:48 -070027
Chia-I Wu767d7c92017-11-30 13:22:48 -080028SortedVector<String8> GLExtensions::parseExtensionString(char const* extensions) {
29 SortedVector<String8> list;
30
31 char const* curr = extensions;
32 char const* head = curr;
33 do {
34 head = strchr(curr, ' ');
35 String8 s(curr, head ? head - curr : strlen(curr));
36 if (s.length()) {
37 list.add(s);
38 }
39 curr = head + 1;
40 } while (head);
41
42 return list;
43}
Mathias Agopian875d8e12013-06-07 15:35:48 -070044
Chia-I Wub027f802017-11-29 14:00:52 -080045void GLExtensions::initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer,
46 GLubyte const* version, GLubyte const* extensions) {
47 mVendor = (char const*)vendor;
48 mRenderer = (char const*)renderer;
49 mVersion = (char const*)version;
Mathias Agopian875d8e12013-06-07 15:35:48 -070050 mExtensions = (char const*)extensions;
Chia-I Wu767d7c92017-11-30 13:22:48 -080051 mExtensionList = parseExtensionString(mExtensions);
Mathias Agopian875d8e12013-06-07 15:35:48 -070052}
53
Chia-I Wub027f802017-11-29 14:00:52 -080054bool GLExtensions::hasExtension(char const* extension) const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070055 const String8 s(extension);
56 return mExtensionList.indexOf(s) >= 0;
57}
58
59char const* GLExtensions::getVendor() const {
60 return mVendor.string();
61}
62
63char const* GLExtensions::getRenderer() const {
64 return mRenderer.string();
65}
66
67char const* GLExtensions::getVersion() const {
68 return mVersion.string();
69}
70
Chia-I Wu767d7c92017-11-30 13:22:48 -080071char const* GLExtensions::getExtensions() const {
Mathias Agopian875d8e12013-06-07 15:35:48 -070072 return mExtensions.string();
73}
74
Chia-I Wu767d7c92017-11-30 13:22:48 -080075void GLExtensions::initWithEGLStrings(char const* eglVersion, char const* eglExtensions) {
76 mEGLVersion = eglVersion;
77 mEGLExtensions = eglExtensions;
78 mEGLExtensionList = parseExtensionString(mEGLExtensions);
79
80 // EGL_ANDROIDX_no_config_context is an experimental extension with no
81 // written specification. It will be replaced by something more formal.
82 // SurfaceFlinger is using it to allow a single EGLContext to render to
83 // both a 16-bit primary display framebuffer and a 32-bit virtual display
84 // framebuffer.
85 //
86 // EGL_KHR_no_config_context is official extension to allow creating a
87 // context that works with any surface of a display.
88 if (hasEGLExtension("EGL_ANDROIDX_no_config_context") ||
89 hasEGLExtension("EGL_KHR_no_config_context")) {
90 mHasNoConfigContext = true;
91 }
92}
93
94char const* GLExtensions::getEGLVersion() const {
95 return mEGLVersion.string();
96}
97
98char const* GLExtensions::getEGLExtensions() const {
99 return mEGLExtensions.string();
100}
101
102bool GLExtensions::hasEGLExtension(char const* extension) const {
103 const String8 s(extension);
104 return mEGLExtensionList.indexOf(s) >= 0;
105}
106
Mathias Agopian875d8e12013-06-07 15:35:48 -0700107// ---------------------------------------------------------------------------
108}; // namespace android