Lines Matching refs:ctx

88   egl_ctx *ctx = data;  in egl_free_ctx()  local
91 if (ctx->egl_display != EGL_NO_DISPLAY) { in egl_free_ctx()
92 eglMakeCurrent(ctx->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, in egl_free_ctx()
95 if (ctx->program) in egl_free_ctx()
96 glDeleteProgram(ctx->program); in egl_free_ctx()
98 if (ctx->fragment_shader) in egl_free_ctx()
99 glDeleteShader(ctx->fragment_shader); in egl_free_ctx()
101 if (ctx->vertex_shader) in egl_free_ctx()
102 glDeleteShader(ctx->vertex_shader); in egl_free_ctx()
104 for (i = 0; i < ctx->num_surfaces; i++) { in egl_free_ctx()
105 if (ctx->egl_surfaces[i] != EGL_NO_SURFACE) in egl_free_ctx()
106 eglDestroySurface(ctx->egl_display, ctx->egl_surfaces[i]); in egl_free_ctx()
109 if (ctx->egl_context != EGL_NO_CONTEXT) in egl_free_ctx()
110 eglDestroyContext(ctx->egl_display, ctx->egl_context); in egl_free_ctx()
112 eglTerminate(ctx->egl_display); in egl_free_ctx()
116 for (i = 0; i < ctx->num_surfaces; i++) { in egl_free_ctx()
117 if (ctx->gbm_surfaces[i]) in egl_free_ctx()
118 gbm_surface_destroy(ctx->gbm_surfaces[i]); in egl_free_ctx()
121 if (ctx->gbm_dev) in egl_free_ctx()
122 gbm_device_destroy(ctx->gbm_dev); in egl_free_ctx()
124 free(ctx); in egl_free_ctx()
127 static int egl_flush_surfaces(egl_ctx *ctx) in egl_flush_surfaces() argument
133 eglMakeCurrent(ctx->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, in egl_flush_surfaces()
136 for (i = 0; i < ctx->num_surfaces; i++) { in egl_flush_surfaces()
137 if (ctx->egl_surfaces[i] != EGL_NO_SURFACE) { in egl_flush_surfaces()
138 eglDestroySurface(ctx->egl_display, ctx->egl_surfaces[i]); in egl_flush_surfaces()
139 ctx->egl_surfaces[i] = EGL_NO_SURFACE; in egl_flush_surfaces()
143 for (i = 0; i < ctx->num_surfaces; i++) { in egl_flush_surfaces()
144 if (ctx->gbm_surfaces[i]) { in egl_flush_surfaces()
145 gbm_surface_destroy(ctx->gbm_surfaces[i]); in egl_flush_surfaces()
146 ctx->gbm_surfaces[i] = NULL; in egl_flush_surfaces()
150 for (i = 0; i < ctx->num_surfaces; i++) { in egl_flush_surfaces()
151 if (!ctx->modifier) in egl_flush_surfaces()
152 ctx->gbm_surfaces[i] = in egl_flush_surfaces()
153 gbm_surface_create(ctx->gbm_dev, ctx->width, ctx->height, in egl_flush_surfaces()
154 ctx->format, 0); in egl_flush_surfaces()
156 ctx->gbm_surfaces[i] = in egl_flush_surfaces()
157 gbm_surface_create_with_modifiers(ctx->gbm_dev, in egl_flush_surfaces()
158 ctx->width, ctx->height, in egl_flush_surfaces()
159 ctx->format, &ctx->modifier, 1); in egl_flush_surfaces()
160 if (!ctx->gbm_surfaces[i]) { in egl_flush_surfaces()
165 ctx->egl_surfaces[i] = in egl_flush_surfaces()
166 eglCreateWindowSurface(ctx->egl_display, ctx->egl_config, in egl_flush_surfaces()
167 (EGLNativeWindowType)ctx->gbm_surfaces[i], NULL); in egl_flush_surfaces()
168 if (ctx->egl_surfaces[i] == EGL_NO_SURFACE) { in egl_flush_surfaces()
174 ctx->current_surface = 0; in egl_flush_surfaces()
185 egl_ctx *ctx; in egl_init_ctx() local
210 ctx = calloc(1, sizeof(*ctx)); in egl_init_ctx()
211 if (!ctx) { in egl_init_ctx()
216 ctx->format = format; in egl_init_ctx()
217 ctx->modifier = modifier; in egl_init_ctx()
218 ctx->num_surfaces = num_surfaces; in egl_init_ctx()
219 ctx->width = ctx->height = 0; in egl_init_ctx()
221 for (i = 0; i < ctx->num_surfaces; i++) in egl_init_ctx()
222 ctx->egl_surfaces[i] = EGL_NO_SURFACE; in egl_init_ctx()
224 ctx->gbm_dev = gbm_create_device(fd); in egl_init_ctx()
225 if (!ctx->gbm_dev) { in egl_init_ctx()
230 ctx->egl_display = get_platform_display(EGL_PLATFORM_GBM_KHR, in egl_init_ctx()
231 (void*)ctx->gbm_dev, NULL); in egl_init_ctx()
232 if (ctx->egl_display == EGL_NO_DISPLAY) { in egl_init_ctx()
237 if (!eglInitialize(ctx->egl_display, NULL, NULL)) { in egl_init_ctx()
247 if (!eglGetConfigs(ctx->egl_display, NULL, 0, &num_configs) || in egl_init_ctx()
259 if (!eglGetConfigs(ctx->egl_display, configs, num_configs, &num_configs)) { in egl_init_ctx()
267 if (!eglGetConfigAttrib(ctx->egl_display, configs[i], in egl_init_ctx()
278 ctx->egl_config = configs[0]; in egl_init_ctx()
280 ctx->egl_config = configs[i]; in egl_init_ctx()
283 ctx->egl_context = eglCreateContext(ctx->egl_display, ctx->egl_config, in egl_init_ctx()
285 if (ctx->egl_context == EGL_NO_CONTEXT) { in egl_init_ctx()
290 eglMakeCurrent(ctx->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, in egl_init_ctx()
291 ctx->egl_context); in egl_init_ctx()
294 ctx->vertex_shader = glCreateShader(GL_VERTEX_SHADER); in egl_init_ctx()
295 glShaderSource(ctx->vertex_shader, 1, &source, NULL); in egl_init_ctx()
296 glCompileShader(ctx->vertex_shader); in egl_init_ctx()
297 glGetShaderiv(ctx->vertex_shader, GL_COMPILE_STATUS, &status); in egl_init_ctx()
299 glGetShaderInfoLog(ctx->vertex_shader, sizeof(msg), NULL, msg); in egl_init_ctx()
305 ctx->fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); in egl_init_ctx()
306 glShaderSource(ctx->fragment_shader, 1, &source, NULL); in egl_init_ctx()
307 glCompileShader(ctx->fragment_shader); in egl_init_ctx()
308 glGetShaderiv(ctx->fragment_shader, GL_COMPILE_STATUS, &status); in egl_init_ctx()
310 glGetShaderInfoLog(ctx->fragment_shader, sizeof(msg), NULL, msg); in egl_init_ctx()
315 ctx->program = glCreateProgram(); in egl_init_ctx()
316 glAttachShader(ctx->program, ctx->vertex_shader); in egl_init_ctx()
317 glAttachShader(ctx->program, ctx->fragment_shader); in egl_init_ctx()
318 glLinkProgram(ctx->program); in egl_init_ctx()
320 glGetProgramiv(ctx->program, GL_LINK_STATUS, &status); in egl_init_ctx()
322 glGetProgramInfoLog(ctx->program, sizeof(msg), NULL, msg); in egl_init_ctx()
327 glUseProgram(ctx->program); in egl_init_ctx()
329 texcoord = glGetAttribLocation(ctx->program, "texcoord"); in egl_init_ctx()
333 glUniform1i(glGetUniformLocation(ctx->program, "tex"), 0); in egl_init_ctx()
335 return ctx; in egl_init_ctx()
337 egl_free_ctx(ctx); in egl_init_ctx()
375 static int egl_attach_dmabuf(egl_ctx *ctx, int dma_fd, int width, int height) in egl_attach_dmabuf() argument
415 image = create_image(ctx->egl_display, ctx->egl_context, in egl_attach_dmabuf()
423 destroy_image(ctx->egl_display, image); in egl_attach_dmabuf()
431 egl_ctx *ctx = data; in egl_convert_fb() local
450 if (ctx->width != scaled_w || ctx->height != scaled_h) { in egl_convert_fb()
451 ctx->width = scaled_w; in egl_convert_fb()
452 ctx->height = scaled_h; in egl_convert_fb()
453 glViewport(0, 0, ctx->width, ctx->height); in egl_convert_fb()
455 egl_flush_surfaces(ctx); in egl_convert_fb()
458 ctx->current_surface = (ctx->current_surface + 1) % ctx->num_surfaces; in egl_convert_fb()
459 eglMakeCurrent(ctx->egl_display, ctx->egl_surfaces[ctx->current_surface], in egl_convert_fb()
460 ctx->egl_surfaces[ctx->current_surface], in egl_convert_fb()
461 ctx->egl_context); in egl_convert_fb()
465 verts[2 * i] += x * 2.0 / ctx->width; in egl_convert_fb()
466 verts[2 * i + 1] -= y * 2.0 / ctx->height; in egl_convert_fb()
469 position = glGetAttribLocation(ctx->program, "position"); in egl_convert_fb()
477 if (egl_attach_dmabuf(ctx, dma_fd, w, h) < 0) { in egl_convert_fb()
483 eglSwapBuffers(ctx->egl_display, ctx->egl_surfaces[ctx->current_surface]); in egl_convert_fb()
485 bo = gbm_surface_lock_front_buffer(ctx->gbm_surfaces[ctx->current_surface]); in egl_convert_fb()
491 fb = egl_bo_to_fb(fd, bo, ctx->format, ctx->modifier); in egl_convert_fb()
492 gbm_surface_release_buffer(ctx->gbm_surfaces[ctx->current_surface], bo); in egl_convert_fb()