blob: 1c685f15c66511e96128029dabdcfd6d69c91763 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
2 * Copyright (C) 2023 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// #define LOG_NDEBUG 0
18#define LOG_TAG "EglUtil"
19#include "EglUtil.h"
20
21#include <cstring>
22
Biswarup Pal26bff382024-04-22 12:16:12 +000023#include "EglDisplayContext.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010024#include "GLES/gl.h"
25#include "log/log.h"
26
27namespace android {
28namespace companion {
29namespace virtualcamera {
30
Biswarup Pal26bff382024-04-22 12:16:12 +000031// Lower bound for maximum supported texture size is at least 2048x2048
32constexpr int kDefaultMaxTextureSize = 2048;
33
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010034bool checkEglError(const char* operation) {
35 GLenum err = glGetError();
36 if (err == GL_NO_ERROR) {
37 return false;
38 }
39 ALOGE("%s failed: %d", operation, err);
40 return true;
41}
42
43bool isGlExtensionSupported(const char* extension) {
44 const char* extensions =
45 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
46 if (extension == nullptr || extensions == nullptr) {
47 return false;
48 }
49 return strstr(extensions, extension) != nullptr;
50}
51
Biswarup Pal26bff382024-04-22 12:16:12 +000052int getMaximumTextureSize() {
53 static const int kMaxTextureSize = [] {
54 EglDisplayContext displayContext;
55 displayContext.makeCurrent();
56 int maxTextureSize = -1;
57 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
58 return maxTextureSize;
59 }();
60 if (kMaxTextureSize <= 0) {
61 return kDefaultMaxTextureSize;
62 }
63 return kMaxTextureSize;
64}
65
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010066} // namespace virtualcamera
67} // namespace companion
68} // namespace android