1/*
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
17#ifndef ANDROID_SF_GLEXTENSION_H
18#define ANDROID_SF_GLEXTENSION_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Singleton.h>
24#include <utils/SortedVector.h>
25#include <utils/String8.h>
26
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
29#include <GLES/gl.h>
30#include <GLES/glext.h>
31
32namespace android {
33// ---------------------------------------------------------------------------
34
35class GLExtensions : public Singleton<GLExtensions> {
36    friend class Singleton<GLExtensions>;
37
38    bool mHasNoConfigContext = false;
39    bool mHasNativeFenceSync = false;
40    bool mHasFenceSync = false;
41    bool mHasWaitSync = false;
42    bool mHasImageCrop = false;
43    bool mHasProtectedContent = false;
44    bool mHasContextPriority = false;
45
46    String8 mVendor;
47    String8 mRenderer;
48    String8 mVersion;
49    String8 mExtensions;
50    SortedVector<String8> mExtensionList;
51
52    String8 mEGLVersion;
53    String8 mEGLExtensions;
54    SortedVector<String8> mEGLExtensionList;
55
56    static SortedVector<String8> parseExtensionString(char const* extensions);
57
58    GLExtensions(const GLExtensions&);
59    GLExtensions& operator=(const GLExtensions&);
60
61protected:
62    GLExtensions() = default;
63
64public:
65    bool hasNoConfigContext() const { return mHasNoConfigContext; }
66    bool hasNativeFenceSync() const { return mHasNativeFenceSync; }
67    bool hasFenceSync() const { return mHasFenceSync; }
68    bool hasWaitSync() const { return mHasWaitSync; }
69    bool hasImageCrop() const { return mHasImageCrop; }
70    bool hasProtectedContent() const { return mHasProtectedContent; }
71    bool hasContextPriority() const { return mHasContextPriority; }
72
73    void initWithGLStrings(GLubyte const* vendor, GLubyte const* renderer, GLubyte const* version,
74                           GLubyte const* extensions);
75    char const* getVendor() const;
76    char const* getRenderer() const;
77    char const* getVersion() const;
78    char const* getExtensions() const;
79    bool hasExtension(char const* extension) const;
80
81    void initWithEGLStrings(char const* eglVersion, char const* eglExtensions);
82    char const* getEGLVersion() const;
83    char const* getEGLExtensions() const;
84    bool hasEGLExtension(char const* extension) const;
85};
86
87// ---------------------------------------------------------------------------
88}; // namespace android
89
90#endif // ANDROID_SF_GLEXTENSION_H
91