Skip to content

Commit 0dc908c

Browse files
author
Jamie Gennis
committed
EGL: Add stubs for EGL_ANDROID_blob_cache
This change adds a stub cache implementation that gets passed to the underlying EGL implementation at initialization time. Change-Id: I14437c5b6f91b7a34a19bb02ad802e6e54f88d2a
1 parent 62015f5 commit 0dc908c

File tree

5 files changed

+139
-1
lines changed

5 files changed

+139
-1
lines changed

opengl/libs/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include $(CLEAR_VARS)
88

99
LOCAL_SRC_FILES:= \
1010
EGL/egl_tls.cpp \
11+
EGL/egl_cache.cpp \
1112
EGL/egl_display.cpp \
1213
EGL/egl_object.cpp \
1314
EGL/egl.cpp \
@@ -157,4 +158,3 @@ LOCAL_MODULE:= libETC1
157158
include $(BUILD_SHARED_LIBRARY)
158159

159160
include $(call all-makefiles-under,$(LOCAL_PATH))
160-

opengl/libs/EGL/eglApi.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,17 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
858858
return NULL;
859859
}
860860

861+
// The EGL_ANDROID_blob_cache extension should not be exposed to
862+
// applications. It is used internally by the Android EGL layer.
863+
if (!strcmp(procname, "eglSetBlobCacheFuncs")) {
864+
return NULL;
865+
}
866+
861867
__eglMustCastToProperFunctionPointerType addr;
862868
addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap));
863869
if (addr) return addr;
864870

871+
865872
// this protects accesses to sGLExtentionMap and sGLExtentionSlot
866873
pthread_mutex_lock(&sExtensionMapMutex);
867874

opengl/libs/EGL/egl_cache.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
** Copyright 2011, 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+
#include "egl_cache.h"
18+
#include "egl_display.h"
19+
#include "egl_impl.h"
20+
#include "egldefs.h"
21+
22+
// ----------------------------------------------------------------------------
23+
namespace android {
24+
// ----------------------------------------------------------------------------
25+
26+
#define BC_EXT_STR "EGL_ANDROID_blob_cache"
27+
28+
//
29+
// EGL_ANDROID_blob_cache types and functions
30+
//
31+
typedef khronos_ssize_t EGLsizei;
32+
33+
typedef void (*EGLSetBlobFunc) (const void* key, EGLsizei keySize,
34+
const void* value, EGLsizei valueSize);
35+
36+
typedef EGLsizei (*EGLGetBlobFunc) (const void* key, EGLsizei keySize,
37+
void* value, EGLsizei valueSize);
38+
39+
typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSPROC) (EGLDisplay dpy,
40+
EGLSetBlobFunc set, EGLGetBlobFunc get);
41+
42+
//
43+
// egl_cache_t definition
44+
//
45+
static void setBlob(const void* key, EGLsizei keySize, const void* value,
46+
EGLsizei valueSize) {
47+
}
48+
49+
static EGLsizei getBlob(const void* key, EGLsizei keySize, void* value,
50+
EGLsizei valueSize) {
51+
return 0;
52+
}
53+
54+
egl_cache_t* egl_cache_t::get() {
55+
static egl_cache_t theCache;
56+
return &theCache;
57+
}
58+
59+
void egl_cache_t::initialize(egl_display_t *display) {
60+
for (int i = 0; i < IMPL_NUM_IMPLEMENTATIONS; i++) {
61+
egl_connection_t* const cnx = &gEGLImpl[i];
62+
if (cnx->dso && cnx->major >= 0 && cnx->minor >= 0) {
63+
const char* exts = display->disp[i].queryString.extensions;
64+
size_t bcExtLen = strlen(BC_EXT_STR);
65+
size_t extsLen = strlen(exts);
66+
bool equal = !strcmp(BC_EXT_STR, exts);
67+
bool atStart = !strncmp(BC_EXT_STR " ", exts, bcExtLen+1);
68+
bool atEnd = (bcExtLen+1) < extsLen &&
69+
!strcmp(" " BC_EXT_STR, exts + extsLen - (bcExtLen+1));
70+
bool inMiddle = strstr(" " BC_EXT_STR " ", exts);
71+
if (equal || atStart || atEnd || inMiddle) {
72+
PFNEGLSETBLOBCACHEFUNCSPROC eglSetBlobCacheFuncs;
73+
eglSetBlobCacheFuncs =
74+
reinterpret_cast<PFNEGLSETBLOBCACHEFUNCSPROC>(
75+
cnx->egl.eglGetProcAddress("eglSetBlobCacheFuncs"));
76+
if (eglSetBlobCacheFuncs == NULL) {
77+
LOGE("EGL_ANDROID_blob_cache advertised by display %d, "
78+
"but unable to get eglSetBlobCacheFuncs", i);
79+
continue;
80+
}
81+
82+
eglSetBlobCacheFuncs(display->disp[i].dpy, setBlob, getBlob);
83+
EGLint err = cnx->egl.eglGetError();
84+
if (err != EGL_SUCCESS) {
85+
LOGE("eglSetBlobCacheFuncs resulted in an error: %#x",
86+
err);
87+
}
88+
}
89+
}
90+
}
91+
}
92+
93+
// ----------------------------------------------------------------------------
94+
}; // namespace android
95+
// ----------------------------------------------------------------------------

opengl/libs/EGL/egl_cache.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
** Copyright 2011, 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+
// ----------------------------------------------------------------------------
18+
namespace android {
19+
// ----------------------------------------------------------------------------
20+
21+
class egl_display_t;
22+
23+
class egl_cache_t {
24+
public:
25+
26+
static egl_cache_t* get();
27+
28+
void initialize(egl_display_t* display);
29+
};
30+
31+
// ----------------------------------------------------------------------------
32+
}; // namespace android
33+
// ----------------------------------------------------------------------------

opengl/libs/EGL/egl_display.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
** limitations under the License.
1515
*/
1616

17+
#include "egl_cache.h"
1718
#include "egl_display.h"
1819
#include "egl_object.h"
1920
#include "egl_tls.h"
@@ -170,6 +171,8 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
170171
}
171172
}
172173

174+
egl_cache_t::get()->initialize(this);
175+
173176
EGLBoolean res = EGL_FALSE;
174177
for (int i = 0; i < IMPL_NUM_IMPLEMENTATIONS; i++) {
175178
egl_connection_t* const cnx = &gEGLImpl[i];

0 commit comments

Comments
 (0)