egl_display.h revision 518ec112f468eb67bf681b3eec896d7bfb4ff98d
1/*
2 ** Copyright 2007, 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_EGL_DISPLAY_H
18#define ANDROID_EGL_DISPLAY_H
19
20
21#include <ctype.h>
22#include <stdint.h>
23#include <stdlib.h>
24
25#include <EGL/egl.h>
26#include <EGL/eglext.h>
27#include <GLES/gl.h>
28#include <GLES/glext.h>
29
30#include <utils/SortedVector.h>
31#include <utils/threads.h>
32
33#include "hooks.h"
34
35// ----------------------------------------------------------------------------
36namespace android {
37// ----------------------------------------------------------------------------
38
39class egl_object_t;
40class egl_connection_t;
41
42// ----------------------------------------------------------------------------
43
44struct egl_config_t {
45    egl_config_t() {}
46    egl_config_t(int impl, EGLConfig config)
47        : impl(impl), config(config), configId(0), implConfigId(0) { }
48    int         impl;           // the implementation this config is for
49    EGLConfig   config;         // the implementation's EGLConfig
50    EGLint      configId;       // our CONFIG_ID
51    EGLint      implConfigId;   // the implementation's CONFIG_ID
52    inline bool operator < (const egl_config_t& rhs) const {
53        if (impl < rhs.impl) return true;
54        if (impl > rhs.impl) return false;
55        return config < rhs.config;
56    }
57};
58
59// ----------------------------------------------------------------------------
60
61class egl_display_t {
62    static egl_display_t sDisplay[NUM_DISPLAYS];
63    EGLDisplay getDisplay(EGLNativeDisplayType display);
64
65public:
66    enum {
67        NOT_INITIALIZED = 0,
68        INITIALIZED     = 1,
69        TERMINATED      = 2
70    };
71
72    egl_display_t();
73    ~egl_display_t();
74
75    EGLBoolean initialize(EGLint *major, EGLint *minor);
76    EGLBoolean terminate();
77
78    // add object to this display's list
79    void addObject(egl_object_t* object);
80    // remove object from this display's list if it has no reference.
81    // returns true if object was removed.
82    bool removeObject(egl_object_t* object);
83    // add reference to this object. returns true if this is a valid object.
84    bool getObject(egl_object_t* object);
85
86    static egl_display_t* get(EGLDisplay dpy);
87    static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp);
88
89    inline bool isReady() const { return (refs > 0); }
90    inline bool isValid() const { return magic == '_dpy'; }
91    inline bool isAlive() const { return isValid(); }
92
93    struct strings_t {
94        char const * vendor;
95        char const * version;
96        char const * clientApi;
97        char const * extensions;
98    };
99
100    struct DisplayImpl {
101        DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0),
102                        state(NOT_INITIALIZED), numConfigs(0) { }
103        EGLDisplay  dpy;
104        EGLConfig*  config;
105        EGLint      state;
106        EGLint      numConfigs;
107        strings_t   queryString;
108    };
109
110private:
111    uint32_t        magic;
112
113public:
114    DisplayImpl     disp[IMPL_NUM_IMPLEMENTATIONS];
115    EGLint          numTotalConfigs;
116    egl_config_t*   configs;
117
118private:
119    uint32_t        refs;
120    Mutex           lock;
121    SortedVector<egl_object_t*> objects;
122};
123
124// ----------------------------------------------------------------------------
125
126inline egl_display_t* get_display(EGLDisplay dpy) {
127    return egl_display_t::get(dpy);
128}
129
130// ----------------------------------------------------------------------------
131
132egl_display_t* validate_display(EGLDisplay dpy);
133egl_connection_t* validate_display_config(EGLDisplay dpy,
134        EGLConfig config, egl_display_t const*& dp);
135EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);
136EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface);
137
138// ----------------------------------------------------------------------------
139}; // namespace android
140// ----------------------------------------------------------------------------
141
142#endif // ANDROID_EGL_DISPLAY_H
143
144