blob: 1e64302f26a9fdbcd3bb60d254fbe2f790e5296d [file] [log] [blame]
Jamie Gennisaca51c02011-11-03 17:42:43 -07001/*
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// ----------------------------------------------------------------------------
23namespace android {
24// ----------------------------------------------------------------------------
25
26#define BC_EXT_STR "EGL_ANDROID_blob_cache"
27
28//
29// EGL_ANDROID_blob_cache types and functions
30//
31typedef khronos_ssize_t EGLsizei;
32
33typedef void (*EGLSetBlobFunc) (const void* key, EGLsizei keySize,
34 const void* value, EGLsizei valueSize);
35
36typedef EGLsizei (*EGLGetBlobFunc) (const void* key, EGLsizei keySize,
37 void* value, EGLsizei valueSize);
38
39typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSPROC) (EGLDisplay dpy,
40 EGLSetBlobFunc set, EGLGetBlobFunc get);
41
42//
43// egl_cache_t definition
44//
45static void setBlob(const void* key, EGLsizei keySize, const void* value,
46 EGLsizei valueSize) {
47}
48
49static EGLsizei getBlob(const void* key, EGLsizei keySize, void* value,
50 EGLsizei valueSize) {
51 return 0;
52}
53
54egl_cache_t* egl_cache_t::get() {
55 static egl_cache_t theCache;
56 return &theCache;
57}
58
59void 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// ----------------------------------------------------------------------------