summaryrefslogtreecommitdiffstats
path: root/exynos4/hal/libEGL_mali/eglApi.cpp
blob: bbd6aa430b6f32f8c0502d8c22287da7b084680d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (C) 2019 The Android Open Source Project
 * Copyright (C) 2019 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <log/log.h>
#include <system/graphics.h>
#include <system/window.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>

#ifdef SKIP_EGL_CONTEXT_DETACH
static int debug_level = 0;
#endif

extern "C" EGLBoolean shim_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
        EGLint attribute, EGLint *value);

extern "C" EGLSurface shim_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
                                    NativeWindowType window,
                                    const EGLint *attrib_list);

extern "C" EGLBoolean shim_eglMakeCurrent(  EGLDisplay dpy, EGLSurface draw,
                            EGLSurface read, EGLContext ctx);

extern "C" EGLBoolean shim_eglDestroySurface(EGLDisplay dpy, EGLSurface surface);

extern "C" EGLSurface shim_eglGetCurrentSurface(EGLint readdraw);

extern "C" EGLContext shim_eglGetCurrentContext(void);

EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
        EGLint attribute, EGLint *value) {
     return shim_eglGetConfigAttrib(dpy, config, attribute, value);
}

EGLSurface eglCreateWindowSurface(  EGLDisplay dpy, EGLConfig config,
                                    NativeWindowType window,
                                    const EGLint *attrib_list) {
#ifdef NEEDS_NATIVE_WINDOW_FORMAT_FIX
     int format, err;
     window->query(window, NATIVE_WINDOW_FORMAT, &format);

     if (format == (int)HAL_PIXEL_FORMAT_RGBA_8888) {
         format = (int)HAL_PIXEL_FORMAT_BGRA_8888;
         err = window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
     }

#endif
     return shim_eglCreateWindowSurface(dpy, config, window, attrib_list);
}

EGLBoolean eglMakeCurrent(  EGLDisplay dpy, EGLSurface draw,
                            EGLSurface read, EGLContext ctx) {
#ifdef SKIP_EGL_CONTEXT_DETACH
    EGLSurface curRead, curDraw;
    EGLContext curCtx;
    if (debug_level > 1) {
        curRead = shim_eglGetCurrentSurface(EGL_READ);
        curDraw = shim_eglGetCurrentSurface(EGL_DRAW);
        curCtx  = shim_eglGetCurrentContext();
        ALOGD("%s: before makeCurrent: curRead=%s, curDraw=%s, curCtx=%s",
                    __func__, (curRead == EGL_NO_SURFACE ? "NULL" : "ok"),
                              (curDraw == EGL_NO_SURFACE ? "NULL" : "ok"),
                              (curCtx  == EGL_NO_CONTEXT ? "NULL" : "ok"));
    }

    if (draw == EGL_NO_SURFACE &&
          read == EGL_NO_SURFACE &&
             ctx == EGL_NO_CONTEXT) {
        ALOGD_IF(debug_level > 0, "%s: skipping context detach!", __func__);

        return true;
    } else
        ALOGD_IF(debug_level > 1, "%s: init", __func__);
#endif

    EGLBoolean res = shim_eglMakeCurrent(dpy, draw, read, ctx);

#ifdef SKIP_EGL_CONTEXT_DETACH
    if (debug_level > 1) {
        curRead = shim_eglGetCurrentSurface(EGL_READ);
        curDraw = shim_eglGetCurrentSurface(EGL_DRAW);
        curCtx  = shim_eglGetCurrentContext();
        ALOGD("%s: after makeCurrent: curRead=%s, curDraw=%s, curCtx=%s",
                    __func__, (curRead == EGL_NO_SURFACE ? "NULL" : "ok"),
                              (curDraw == EGL_NO_SURFACE ? "NULL" : "ok"),
                              (curCtx  == EGL_NO_CONTEXT ? "NULL" : "ok"));
    }
#endif

    return res;
}

EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
#ifdef SKIP_EGL_CONTEXT_DETACH
    EGLSurface curRead, curDraw;
    EGLContext curCtx;
    if (debug_level > 2) {
        curRead = shim_eglGetCurrentSurface(EGL_READ);
        curDraw = shim_eglGetCurrentSurface(EGL_DRAW);
        curCtx  = shim_eglGetCurrentContext();
        ALOGD("%s: before destroySurface: curRead=%s, curDraw=%s, curCtx=%s",
                       __func__, (curRead == EGL_NO_SURFACE ? "NULL" : "ok"),
                                 (curDraw == EGL_NO_SURFACE ? "NULL" : "ok"),
                                (curCtx  == EGL_NO_CONTEXT ? "NULL" : "ok"));
    }
#endif

    EGLBoolean res = shim_eglDestroySurface(dpy, surface);

#ifdef SKIP_EGL_CONTEXT_DETACH
    if (debug_level > 2) {
        curRead = shim_eglGetCurrentSurface(EGL_READ);
        curDraw = shim_eglGetCurrentSurface(EGL_DRAW);
        curCtx  = shim_eglGetCurrentContext();
        ALOGD("%s: after destroySurface: curRead=%s, curDraw=%s, curCtx=%s",
                      __func__, (curRead == EGL_NO_SURFACE ? "NULL" : "ok"),
                                (curDraw == EGL_NO_SURFACE ? "NULL" : "ok"),
                               (curCtx  == EGL_NO_CONTEXT ? "NULL" : "ok"));
    }
#endif
   return res;
}