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     const char* match = strstr(extensionsStr, wantedExtension);
52     size_t wantedTerminatorOffset = strlen(wantedExtension);
53     if (match &&
54         (match[wantedTerminatorOffset] == ' ' ||
55          match[wantedTerminatorOffset] == '\0')) {
56         return true;
57     }
58     return false;
59 }
60 
setGLObjectCounter(android::base::GLObjectCounter * counter)61 void emugl::setGLObjectCounter(android::base::GLObjectCounter* counter) {
62     s_gl_object_counter = counter;
63 }
64 
getGLObjectCounter()65 android::base::GLObjectCounter* emugl::getGLObjectCounter() {
66     if (!s_gl_object_counter) {
67         if (!s_default_gl_object_counter) {
68             s_default_gl_object_counter = new android::base::GLObjectCounter;
69         }
70         return s_default_gl_object_counter;
71     }
72     return s_gl_object_counter;
73 }
74 
setGrallocImplementation(GrallocImplementation gralloc)75 void emugl::setGrallocImplementation(GrallocImplementation gralloc) {
76     s_gralloc_implementation = gralloc;
77 }
78 
getGrallocImplementation()79 GrallocImplementation emugl::getGrallocImplementation() {
80     return s_gralloc_implementation;
81 }
82