1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 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 16 #ifndef XCOMPONENT_COMMON_H 17 #define XCOMPONENT_COMMON_H 18 19 #include <EGL/egl.h> 20 #include <EGL/eglext.h> 21 #include <GLES3/gl3.h> 22 #include <EGL/eglplatform.h> 23 24 namespace OHOS { 25 /** 26 * Vertex shader. 27 */ 28 const char VERTEX_SHADER[] = "#version 300 es\n" 29 "layout(location = 0) in vec4 a_position;\n" 30 "layout(location = 1) in vec4 a_color; \n" 31 "out vec4 v_color; \n" 32 "void main() \n" 33 "{ \n" 34 " gl_Position = a_position; \n" 35 " v_color = a_color; \n" 36 "} \n"; 37 38 /** 39 * Fragment shader. 40 */ 41 const char FRAGMENT_SHADER[] = "#version 300 es\n" 42 "precision mediump float; \n" 43 "in vec4 v_color; \n" 44 "out vec4 fragColor; \n" 45 "void main() \n" 46 "{ \n" 47 " fragColor = v_color; \n" 48 "} \n"; 49 50 const GLfloat BACKGROUND_COLOR[] = {0.0f / 255, 0.0f / 255, 255.0f / 255, 1.0f}; 51 52 const GLfloat DRAW_COLOR[] = {0.0f / 255, 255.0f / 255, 0.0f / 255, 1.0f}; 53 54 const GLfloat CHANGE_COLOR[] = {146.0f / 255, 214.0f / 255, 204.0f / 255, 1.0f}; 55 56 /** 57 * Background area. 58 */ 59 const GLfloat BACKGROUND_RECTANGLE_VERTICES[] = {-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f}; 60 61 /** 62 * Log print domain. 63 */ 64 const unsigned int LOG_PRINT_DOMAIN = 0xFF00; 65 66 /** 67 * Get context parameter count. 68 */ 69 const size_t GET_CONTEXT_PARAM_CNT = 1; 70 71 /** 72 * Fifty percent. 73 */ 74 const float FIFTY_PERCENT = 0.5; 75 76 /** 77 * Pointer size. 78 */ 79 const GLint POINTER_SIZE = 2; 80 81 /** 82 * Triangle fan size. 83 */ 84 const GLsizei TRIANGLE_FAN_SIZE = 4; 85 86 /** 87 * Egl red size default. 88 */ 89 const int EGL_RED_SIZE_DEFAULT = 8; 90 91 /** 92 * Egl green size default. 93 */ 94 const int EGL_GREEN_SIZE_DEFAULT = 8; 95 96 /** 97 * Egl blue size default. 98 */ 99 const int EGL_BLUE_SIZE_DEFAULT = 8; 100 101 /** 102 * Egl alpha size default. 103 */ 104 const int EGL_ALPHA_SIZE_DEFAULT = 8; 105 106 /** 107 * Default y position. 108 */ 109 const int DEFAULT_Y_POSITION = 0; 110 111 /** 112 * Program error. 113 */ 114 const GLuint PROGRAM_ERROR = 0; 115 116 /** 117 * Rectangle vertices size. 118 */ 119 const int RECTANGLE_VERTICES_SIZE = 8; 120 121 /** 122 * Position error. 123 */ 124 const GLint POSITION_ERROR = -1; 125 126 /** 127 * Context type. 128 */ 129 enum ContextType { 130 APP_LIFECYCLE, 131 PAGE_LIFECYCLE, 132 }; 133 134 /** 135 * Config attribute list. 136 */ 137 const EGLint ATTRIB_LIST[] = { 138 // Key,value. 139 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 140 EGL_RED_SIZE, EGL_RED_SIZE_DEFAULT, 141 EGL_GREEN_SIZE, EGL_GREEN_SIZE_DEFAULT, 142 EGL_BLUE_SIZE, EGL_BLUE_SIZE_DEFAULT, 143 EGL_ALPHA_SIZE, EGL_ALPHA_SIZE_DEFAULT, 144 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 145 // End. 146 EGL_NONE}; 147 148 /** 149 * Context attributes. 150 */ 151 const EGLint CONTEXT_ATTRIBS[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; 152 } // namespace OHOS 153 #endif // XCOMPONENT_COMMON_H