1 /* 2 * Copyright © 2012 John Kåre Alsaker 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 * permit persons to whom the Software is furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the 13 * next paragraph) shall be included in all copies or substantial 14 * portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 */ 25 #ifndef GL_RENDERER_H 26 #define GL_RENDERER_H 27 28 #include "config.h" 29 30 #include <stdint.h> 31 32 #include <libweston/libweston.h> 33 #include "backend.h" 34 #include "libweston-internal.h" 35 #include <hilog/log.h> // OHOS hilog 36 37 #include "buffer_handle.h" 38 39 // OHOS hilog 40 #ifndef weston_log 41 #define weston_log(fmt, ...) (HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)) 42 #define weston_log_continue(fmt, ...) (HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)) 43 #endif 44 45 #define GL_RENDERER_FRMAEBUFFER_SIZE 2 46 47 #ifdef ENABLE_EGL 48 49 #include <EGL/egl.h> 50 #include <EGL/eglext.h> 51 52 #else 53 54 typedef int EGLint; 55 typedef int EGLenum; 56 typedef void *EGLDisplay; 57 typedef void *EGLSurface; 58 typedef void *EGLConfig; 59 typedef intptr_t EGLNativeDisplayType; 60 typedef intptr_t EGLNativeWindowType; 61 #define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) 62 #define EGL_PBUFFER_BIT 0x0001 63 #define EGL_WINDOW_BIT 0x0004 64 65 #endif /* ENABLE_EGL */ 66 67 enum gl_renderer_border_side { 68 GL_RENDERER_BORDER_TOP = 0, 69 GL_RENDERER_BORDER_LEFT = 1, 70 GL_RENDERER_BORDER_RIGHT = 2, 71 GL_RENDERER_BORDER_BOTTOM = 3, 72 }; 73 74 /** 75 * Options passed to the \c display_create method of the GL renderer interface. 76 * 77 * \see struct gl_renderer_interface 78 */ 79 struct gl_renderer_display_options { 80 /** The EGL platform identifier */ 81 EGLenum egl_platform; 82 /** The native display corresponding to the given EGL platform */ 83 void *egl_native_display; 84 /** EGL_SURFACE_TYPE bits for the base EGLConfig */ 85 EGLint egl_surface_type; 86 /** Array of DRM pixel formats acceptable for the base EGLConfig */ 87 const uint32_t *drm_formats; 88 /** The \c drm_formats array length */ 89 unsigned drm_formats_count; 90 }; 91 92 struct gl_renderer_output_options { 93 /** Native window handle for \c eglCreateWindowSurface */ 94 EGLNativeWindowType window_for_legacy; 95 /** Native window handle for \c eglCreatePlatformWindowSurface */ 96 void *window_for_platform; 97 /** Array of DRM pixel formats acceptable for the window */ 98 const uint32_t *drm_formats; 99 /** The \c drm_formats array length */ 100 unsigned drm_formats_count; 101 }; 102 103 struct gl_renderer_pbuffer_options { 104 /** Width of the rendering surface in pixels */ 105 int width; 106 /** Height of the rendering surface in pixels */ 107 int height; 108 /** Array of DRM pixel formats acceptable for the pbuffer */ 109 const uint32_t *drm_formats; 110 /** The \c drm_formats array length */ 111 unsigned drm_formats_count; 112 }; 113 114 struct gl_renderer_fbo_options { 115 BufferHandle *handle[GL_RENDERER_FRMAEBUFFER_SIZE]; 116 }; 117 118 struct gl_renderer_interface { 119 /** 120 * Initialize GL-renderer with the given EGL platform and native display 121 * 122 * \param ec The weston_compositor where to initialize. 123 * \param options The options struct describing display configuration 124 * \return 0 on success, -1 on failure. 125 * 126 * This function creates an EGLDisplay and initializes it. It also 127 * creates the GL ES context and sets it up. It attempts GL ES 3.0 128 * and falls back to GL ES 2.0 if 3.0 is not supported. 129 * 130 * If \c platform is zero or EGL_EXT_platform_base is not supported, 131 * choosing the platform is left for the EGL implementation. Otherwise 132 * the given platform is used explicitly if the EGL implementation 133 * advertises it. Without the advertisement this function fails. 134 * 135 * If neither EGL_KHR_no_config_context or EGL_MESA_configless_context 136 * are supported, the arguments egl_surface_type, drm_formats, and 137 * drm_formats_count are used to find a so called base EGLConfig. The 138 * GL context is created with the base EGLConfig, and outputs will be 139 * required to use the same config as well. If one or both of the 140 * extensions are supported, these arguments are unused, and each 141 * output can use a different EGLConfig (pixel format). 142 * 143 * The first format in drm_formats that matches any EGLConfig 144 * determines which EGLConfig is chosen. On EGL GBM platform, the 145 * pixel format must match exactly. On other platforms, it is enough 146 * that each R, G, B, A channel has the same number of bits as in the 147 * DRM format. 148 */ 149 int (*display_create)(struct weston_compositor *ec, 150 const struct gl_renderer_display_options *options); 151 152 /** 153 * Attach GL-renderer to the output with a native window 154 * 155 * \param output The output to create a rendering surface for. 156 * \param options The options struct describing output configuration 157 * \return 0 on success, -1 on failure. 158 * 159 * This function creates the renderer data structures needed to repaint 160 * the output. The repaint results will be directed to the given native 161 * window. 162 * 163 * If EGL_EXT_platform_base is supported then \c window_for_platform is 164 * used, otherwise \c window_for_legacy is used. This is because the 165 * handle on X11 platform is different between the two. 166 * 167 * The first format in drm_formats that matches any EGLConfig 168 * determines which EGLConfig is chosen. See \c display_create about 169 * how the matching works and the possible limitations. 170 * 171 * This function should be used only if \c display_create was called 172 * with \c EGL_WINDOW_BIT in \c egl_surface_type. 173 */ 174 int (*output_window_create)(struct weston_output *output, 175 const struct gl_renderer_output_options *options); 176 177 /** 178 * Attach GL-renderer to the output with internal pixel storage 179 * 180 * \param output The output to create a rendering surface for. 181 * \param options The options struct describing the pbuffer 182 * \return 0 on success, -1 on failure. 183 * 184 * This function creates the renderer data structures needed to repaint 185 * the output. The repaint results will be kept internal and can only 186 * be accessed through e.g. screen capture. 187 * 188 * The first format in drm_formats that matches any EGLConfig 189 * determines which EGLConfig is chosen. See \c display_create about 190 * how the matching works and the possible limitations. 191 * 192 * This function should be used only if \c display_create was called 193 * with \c EGL_PBUFFER_BIT in \c egl_surface_type. 194 */ 195 int (*output_pbuffer_create)(struct weston_output *output, 196 const struct gl_renderer_pbuffer_options *options); 197 198 // OHOS hdi-backend 199 int (*output_fbo_create)(struct weston_output *output, 200 const struct gl_renderer_fbo_options *options); 201 202 void (*output_destroy)(struct weston_output *output); 203 204 /* Sets the output border. 205 * 206 * The side specifies the side for which we are setting the border. 207 * The width and height are the width and height of the border. 208 * The tex_width patemeter specifies the width of the actual 209 * texture; this may be larger than width if the data is not 210 * tightly packed. 211 * 212 * The top and bottom textures will extend over the sides to the 213 * full width of the bordered window. The right and left edges, 214 * however, will extend only to the top and bottom of the 215 * compositor surface. This is demonstrated by the picture below: 216 * 217 * +-----------------------+ 218 * | TOP | 219 * +-+-------------------+-+ 220 * | | | | 221 * |L| |R| 222 * |E| |I| 223 * |F| |G| 224 * |T| |H| 225 * | | |T| 226 * | | | | 227 * +-+-------------------+-+ 228 * | BOTTOM | 229 * +-----------------------+ 230 */ 231 void (*output_set_border)(struct weston_output *output, 232 enum gl_renderer_border_side side, 233 int32_t width, int32_t height, 234 int32_t tex_width, unsigned char *data); 235 236 /* Create fence sync FD to wait for GPU rendering. 237 * 238 * Return FD on success, -1 on failure or unsupported 239 * EGL_ANDROID_native_fence_sync extension. 240 */ 241 int (*create_fence_fd)(struct weston_output *output); 242 243 // OHOS hdi-backend 244 int (*output_get_current_fbo_index)(struct weston_output *output); 245 }; 246 247 #endif 248