mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-04-28 20:24:36 +09:00
follow focused
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "../include/window_texture.h"
|
||||
#include <X11/extensions/Xcomposite.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define EGL_TRUE 1
|
||||
#define EGL_IMAGE_PRESERVED_KHR 0x30D2
|
||||
#define EGL_NATIVE_PIXMAP_KHR 0x30B0
|
||||
|
||||
static int x11_supports_composite_named_window_pixmap(Display *display) {
|
||||
int extension_major;
|
||||
@@ -18,9 +21,6 @@ int window_texture_init(WindowTexture *window_texture, Display *display, Window
|
||||
window_texture->window = window;
|
||||
window_texture->pixmap = None;
|
||||
window_texture->texture_id = 0;
|
||||
window_texture->target_texture_id = 0;
|
||||
window_texture->texture_width = 0;
|
||||
window_texture->texture_height = 0;
|
||||
window_texture->redirected = 0;
|
||||
window_texture->egl = egl;
|
||||
|
||||
@@ -38,11 +38,6 @@ static void window_texture_cleanup(WindowTexture *self, int delete_texture) {
|
||||
self->texture_id = 0;
|
||||
}
|
||||
|
||||
if(delete_texture && self->target_texture_id) {
|
||||
self->egl->glDeleteTextures(1, &self->target_texture_id);
|
||||
self->target_texture_id = 0;
|
||||
}
|
||||
|
||||
if(self->pixmap) {
|
||||
XFreePixmap(self->display, self->pixmap);
|
||||
self->pixmap = None;
|
||||
@@ -57,11 +52,6 @@ void window_texture_deinit(WindowTexture *self) {
|
||||
window_texture_cleanup(self, 1);
|
||||
}
|
||||
|
||||
|
||||
#define EGL_TRUE 1
|
||||
#define EGL_IMAGE_PRESERVED_KHR 0x30D2
|
||||
#define EGL_NATIVE_PIXMAP_KHR 0x30B0
|
||||
|
||||
int window_texture_on_resize(WindowTexture *self) {
|
||||
window_texture_cleanup(self, 0);
|
||||
|
||||
@@ -84,7 +74,7 @@ int window_texture_on_resize(WindowTexture *self) {
|
||||
if(self->texture_id == 0) {
|
||||
self->egl->glGenTextures(1, &texture_id);
|
||||
if(texture_id == 0) {
|
||||
result = 4;
|
||||
result = 3;
|
||||
goto cleanup;
|
||||
}
|
||||
self->egl->glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
@@ -93,48 +83,39 @@ int window_texture_on_resize(WindowTexture *self) {
|
||||
texture_id = self->texture_id;
|
||||
}
|
||||
|
||||
image = self->egl->eglCreateImage(self->egl->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)pixmap, pixmap_attrs);
|
||||
if(!image) {
|
||||
fprintf(stderr, "eglCreateImage failed\n");
|
||||
return -1;
|
||||
}
|
||||
fprintf(stderr, "gl error: %d\n", self->egl->glGetError());
|
||||
|
||||
fprintf(stderr, "image: %p\n", image);
|
||||
self->egl->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
|
||||
if(self->egl->glGetError() != 0) {
|
||||
fprintf(stderr, "glEGLImageTargetTexture2DOES failed\n");
|
||||
}
|
||||
|
||||
self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
self->egl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
self->egl->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
self->pixmap = pixmap;
|
||||
if(texture_id != 0) {
|
||||
self->texture_id = texture_id;
|
||||
|
||||
self->egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &self->texture_width);
|
||||
self->egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &self->texture_height);
|
||||
|
||||
fprintf(stderr, "texture width: %d, height: %d\n", self->texture_width, self->texture_height);
|
||||
|
||||
self->egl->glGenTextures(1, &self->target_texture_id);
|
||||
self->egl->glBindTexture(GL_TEXTURE_2D, self->target_texture_id);
|
||||
self->egl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, self->texture_width, self->texture_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
fprintf(stderr, "gl error: %d\n", self->egl->glGetError());
|
||||
self->egl->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
image = self->egl->eglCreateImage(self->egl->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)pixmap, pixmap_attrs);
|
||||
if(!image) {
|
||||
result = 4;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// TODO: destroyImage(image)
|
||||
return 0;
|
||||
self->egl->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
|
||||
if(self->egl->glGetError() != 0) {
|
||||
result = 5;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
self->pixmap = pixmap;
|
||||
self->texture_id = texture_id;
|
||||
|
||||
cleanup:
|
||||
if(texture_id != 0) self->egl->glDeleteTextures(1, &texture_id);
|
||||
if(pixmap) XFreePixmap(self->display, pixmap);
|
||||
self->egl->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
if(image)
|
||||
self->egl->eglDestroyImage(self->egl->egl_display, image);
|
||||
|
||||
if(result != 0) {
|
||||
if(texture_id != 0)
|
||||
self->egl->glDeleteTextures(1, &texture_id);
|
||||
if(pixmap)
|
||||
XFreePixmap(self->display, pixmap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user