From c7be7bd71e27d5f399739c3c36a3ab1ba16566bb Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Thu, 23 Jan 2014 11:07:33 +0000 Subject: [PATCH] GL blitter: create texture for window's mask git-svn-id: svn://kolibrios.org@4517 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/sources/render/blit.c | 2 +- contrib/sdk/sources/render/render.c | 83 +++++++++++++++++++++++++++++ contrib/sdk/sources/render/render.h | 4 +- contrib/sdk/sources/render/swap.c | 17 +++--- 4 files changed, 97 insertions(+), 9 deletions(-) diff --git a/contrib/sdk/sources/render/blit.c b/contrib/sdk/sources/render/blit.c index a38f15d9a4..9e9b9f188a 100644 --- a/contrib/sdk/sources/render/blit.c +++ b/contrib/sdk/sources/render/blit.c @@ -57,7 +57,7 @@ void render_blit(struct render *render, enum px_buffer buffer) dst_xscale = 1.0/render->scr_width; dst_yscale = 1.0/render->scr_height; - r = winx + render->dx + render->width ; + r = winx + render->dx + render->width; b = winy + render->dy + render->height; float t0, t1, t2, t5; diff --git a/contrib/sdk/sources/render/render.c b/contrib/sdk/sources/render/render.c index cb4ae12ce8..9676095a6b 100644 --- a/contrib/sdk/sources/render/render.c +++ b/contrib/sdk/sources/render/render.c @@ -7,6 +7,7 @@ #include #include +void create_mask(struct render *render); static int drm_ioctl(int fd, unsigned long request, void *arg) { @@ -242,6 +243,8 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy) glBindTexture(GL_TEXTURE_2D, 0); + create_mask(render); + glGenFramebuffers(1, &render->framebuffer); if(glGetError() != GL_NO_ERROR) goto err8; @@ -326,6 +329,15 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy) render->sampler = glGetUniformLocation(render->blit_prog,"sampler"); + glUseProgram(render->blit_prog); + glUniform1i(render->sampler, 0); + + glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); + glEnableVertexAttribArray(0); + + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); + glEnableVertexAttribArray(1); + eglMakeCurrent(dpy, surface, surface, context); return render; @@ -358,3 +370,74 @@ err: + +void create_mask(struct render *render) +{ + static EGLint attrib[] = + { + EGL_GL_TEXTURE_LEVEL_KHR, 0, + EGL_NONE + }; + struct drm_i915_gem_mmap mmap_arg; + EGLint handle, stride; + int pitch; + void *data; + + glGenTextures(1, &render->tx_mask); + if(glGetError() != GL_NO_ERROR) + goto err1; + + glBindTexture(GL_TEXTURE_2D, render->tx_mask); + if(glGetError() != GL_NO_ERROR) + goto err2; + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + + pitch = (render->width+3) & -4; + + data = user_alloc(pitch*render->height); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, render->width, render->height, 0, + GL_RED,GL_UNSIGNED_BYTE, data); + + user_free(data); + + if(glGetError() != GL_NO_ERROR) + goto err2; + + render->mask = eglCreateImageKHR(render->dpy, render->context, + EGL_GL_TEXTURE_2D_KHR,(EGLClientBuffer)render->tx_mask,attrib); + + if(render->mask == EGL_NO_IMAGE_KHR) + goto err2; + + if(!eglExportDRMImageMESA(render->dpy, render->mask, NULL, &handle, &stride)) + goto err3; + + glBindTexture(GL_TEXTURE_2D, 0); + + mmap_arg.handle = handle; + mmap_arg.offset = 0; + mmap_arg.size = stride * render->height; + if (drm_ioctl(render->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg)) + { + printf("%s: failed to mmap image %p handle=%d, %d bytes, into CPU domain\n", + __FUNCTION__, render->mask, handle, stride*render->height); + goto err3; + } + + render->mask_buffer = (void *)(uintptr_t)mmap_arg.addr_ptr; + + printf("%s: mmap image %p handle=%d, %d bytes to %p\n", + __FUNCTION__, render->mask, handle, stride*render->height, render->mask_buffer); + + return; + +err3: + eglDestroyImageKHR(render->dpy, render->mask); +err2: + glBindTexture(GL_TEXTURE_2D, 0); +err1: + glDeleteTextures(1, &render->tx_mask); +}; diff --git a/contrib/sdk/sources/render/render.h b/contrib/sdk/sources/render/render.h index de611c27fa..fa47a67d91 100644 --- a/contrib/sdk/sources/render/render.h +++ b/contrib/sdk/sources/render/render.h @@ -23,9 +23,11 @@ struct render EGLint width, height; EGLint scr_width, scr_height; GLuint framebuffer; - EGLImageKHR front, back, screen; + EGLImageKHR screen, front, back, mask; GLuint tx_buffers[2]; GLuint tx_screen; + GLuint tx_mask; + void *mask_buffer; int back_buffer; GLuint blit_prog; GLint sampler; diff --git a/contrib/sdk/sources/render/swap.c b/contrib/sdk/sources/render/swap.c index 1c466cc5ea..5924800967 100644 --- a/contrib/sdk/sources/render/swap.c +++ b/contrib/sdk/sources/render/swap.c @@ -38,12 +38,18 @@ void render_swap_and_blit(struct render *render) goto err1; }; +#if 0 glUseProgram(render->blit_prog); glUniform1i(render->sampler, 0); glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices); glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); + glEnableVertexAttribArray(1); + +#endif + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]); glTexParameteri(GL_TEXTURE_2D, @@ -53,9 +59,6 @@ void render_swap_and_blit(struct render *render) GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords); - glEnableVertexAttribArray(1); - dst_xscale = 1.0/render->scr_width; dst_yscale = 1.0/render->scr_height; @@ -86,10 +89,10 @@ void render_swap_and_blit(struct render *render) glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - glDisable(GL_TEXTURE_2D); - glUseProgram(0); +// glDisableVertexAttribArray(0); +// glDisableVertexAttribArray(1); +// glDisable(GL_TEXTURE_2D); +// glUseProgram(0); render->back_buffer++; render->back_buffer&=1;