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