1 // Copyright (C) 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "host-common/opengl/misc.h"
16
17 #include "aemu/base/GLObjectCounter.h"
18
19 #include <cstring>
20
21 static int s_glesMajorVersion = 2;
22 static int s_glesMinorVersion = 0;
23
24 android::base::GLObjectCounter* s_default_gl_object_counter = nullptr;
25
26 android::base::GLObjectCounter* s_gl_object_counter = nullptr;
27 static GrallocImplementation s_gralloc_implementation = MINIGBM;
28
29 static SelectedRenderer s_renderer =
30 SELECTED_RENDERER_HOST;
31
setGlesVersion(int maj,int min)32 void emugl::setGlesVersion(int maj, int min) {
33 s_glesMajorVersion = maj;
34 s_glesMinorVersion = min;
35 }
36
getGlesVersion(int * maj,int * min)37 void emugl::getGlesVersion(int* maj, int* min) {
38 if (maj) *maj = s_glesMajorVersion;
39 if (min) *min = s_glesMinorVersion;
40 }
41
setRenderer(SelectedRenderer renderer)42 void emugl::setRenderer(SelectedRenderer renderer) {
43 s_renderer = renderer;
44 }
45
getRenderer()46 SelectedRenderer emugl::getRenderer() {
47 return s_renderer;
48 }
49
hasExtension(const char * extensionsStr,const char * wantedExtension)50 bool emugl::hasExtension(const char* extensionsStr, const char* wantedExtension) {
51 if (!extensionsStr) {
52 return false;
53 }
54 const char* match = strstr(extensionsStr, wantedExtension);
55 size_t wantedTerminatorOffset = strlen(wantedExtension);
56 if (match &&
57 (match[wantedTerminatorOffset] == ' ' ||
58 match[wantedTerminatorOffset] == '\0')) {
59 return true;
60 }
61 return false;
62 }
63
setGLObjectCounter(android::base::GLObjectCounter * counter)64 void emugl::setGLObjectCounter(android::base::GLObjectCounter* counter) {
65 s_gl_object_counter = counter;
66 }
67
getGLObjectCounter()68 android::base::GLObjectCounter* emugl::getGLObjectCounter() {
69 if (!s_gl_object_counter) {
70 if (!s_default_gl_object_counter) {
71 s_default_gl_object_counter = new android::base::GLObjectCounter;
72 }
73 return s_default_gl_object_counter;
74 }
75 return s_gl_object_counter;
76 }
77
setGrallocImplementation(GrallocImplementation gralloc)78 void emugl::setGrallocImplementation(GrallocImplementation gralloc) {
79 s_gralloc_implementation = gralloc;
80 }
81
getGrallocImplementation()82 GrallocImplementation emugl::getGrallocImplementation() {
83 return s_gralloc_implementation;
84 }
85