forked from KolibriOS/kolibrios
mesa egl: GL blitter support code.
blitter: single set of the texture coordinates. git-svn-id: svn://kolibrios.org@4525 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7ea58d1906
commit
a95c356dc8
@ -273,6 +273,8 @@ typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dp
|
||||
#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 /* EGL_IMAGE_FORMAT_MESA attribute value */
|
||||
#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */
|
||||
#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4
|
||||
#define EGL_DRM_BUFFER_FORMAT_R8_MESA 0x31D5 /* EGL_IMAGE_FORMAT_MESA attribute value */
|
||||
|
||||
#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001 /* EGL_DRM_BUFFER_USE_MESA bits */
|
||||
#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002 /* EGL_DRM_BUFFER_USE_MESA bits */
|
||||
#define EGL_DRM_BUFFER_FRONT 0x0000
|
||||
|
@ -1204,6 +1204,11 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
|
||||
format = __DRI_IMAGE_FORMAT_ARGB8888;
|
||||
pitch = attrs.DRMBufferStrideMESA;
|
||||
break;
|
||||
case EGL_DRM_BUFFER_FORMAT_R8_MESA:
|
||||
format = __DRI_IMAGE_FORMAT_R8;
|
||||
pitch = attrs.DRMBufferStrideMESA;
|
||||
break;
|
||||
|
||||
default:
|
||||
_eglError(EGL_BAD_PARAMETER,
|
||||
"dri2_create_image_khr: unsupported pixmap depth");
|
||||
|
@ -691,15 +691,6 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
|
||||
surf[0] |= 1 << BRW_SURFACE_WRITEDISABLE_A_SHIFT;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
printf("brw_update_renderbuffer_surface\n"
|
||||
"bind bo(handle=%d format=%d width=%d height=%d\n"
|
||||
"pitch=%d, tiling=%d\n"
|
||||
"ss[0] %x ss[1] %x ss[2] %x ss[3] %x ss[4] %x ss[5] %x\n",
|
||||
region->bo->handle, format, rb->Width, rb->Height,
|
||||
region->pitch, region->tiling,
|
||||
surf[0],surf[1],surf[2],surf[3], surf[4],surf[5]);
|
||||
#endif
|
||||
|
||||
drm_intel_bo_emit_reloc(brw->batch.bo,
|
||||
brw->wm.surf_offset[unit] + 4,
|
||||
|
@ -140,6 +140,8 @@ static void
|
||||
set_verbose_flags(const char *str)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
MESA_VERBOSE = VERBOSE_TEXTURE;
|
||||
|
||||
struct option {
|
||||
const char *name;
|
||||
GLbitfield flag;
|
||||
@ -168,6 +170,7 @@ set_verbose_flags(const char *str)
|
||||
if (strstr(str, opts[i].name) || strcmp(str, "all") == 0)
|
||||
MESA_VERBOSE |= opts[i].flag;
|
||||
}
|
||||
MESA_VERBOSE|= VERBOSE_TEXTURE;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -181,6 +184,8 @@ static void
|
||||
set_debug_flags(const char *str)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
MESA_DEBUG_FLAGS = DEBUG_INCOMPLETE_TEXTURE|DEBUG_INCOMPLETE_FBO;
|
||||
|
||||
struct option {
|
||||
const char *name;
|
||||
GLbitfield flag;
|
||||
@ -201,6 +206,7 @@ set_debug_flags(const char *str)
|
||||
if (strstr(str, opts[i].name))
|
||||
MESA_DEBUG_FLAGS |= opts[i].flag;
|
||||
}
|
||||
MESA_DEBUG_FLAGS = DEBUG_INCOMPLETE_TEXTURE|DEBUG_INCOMPLETE_FBO;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -89,24 +89,20 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
const char *vs_src =
|
||||
"attribute vec4 v_position;\n"
|
||||
"attribute vec4 v_texcoord0;\n"
|
||||
"attribute vec4 v_texcoord1;\n"
|
||||
"varying vec2 source_texture;\n"
|
||||
"varying vec2 mask_texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = v_position;\n"
|
||||
" source_texture = v_texcoord0.xy;\n"
|
||||
" mask_texture = v_texcoord1.xy;\n"
|
||||
"}\n";
|
||||
|
||||
const char *fs_src =
|
||||
"varying vec2 source_texture;\n"
|
||||
"varying vec2 mask_texture;\n"
|
||||
"uniform sampler2D sampler_src;\n"
|
||||
"uniform sampler2D sampler_mask;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" float ca = texture2D(sampler_mask, mask_texture).r;\n"
|
||||
" float ca = texture2D(sampler_mask, source_texture).r;\n"
|
||||
" gl_FragColor = vec4(texture2D(sampler_src, source_texture).rgb, ca);\n"
|
||||
"}\n";
|
||||
|
||||
@ -224,8 +220,7 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
render->back_buffer = EGL_DRM_BUFFER_BACK;
|
||||
|
||||
render->back_buffer = EGL_DRM_BUFFER_FRONT;
|
||||
|
||||
render->screen = px_create_image(dpy,context,fb.width,fb.height,
|
||||
fb.pitch,fb.name);
|
||||
@ -315,7 +310,6 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
glAttachShader(render->blit_prog, fs_shader);
|
||||
glBindAttribLocation(render->blit_prog, 0, "v_position");
|
||||
glBindAttribLocation(render->blit_prog, 1, "v_texcoord0");
|
||||
glBindAttribLocation(render->blit_prog, 2, "v_texcoord1");
|
||||
|
||||
glLinkProgram(render->blit_prog);
|
||||
glGetProgramiv(render->blit_prog, GL_LINK_STATUS, &ret);
|
||||
@ -346,9 +340,6 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->tc_src);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->tc_mask);
|
||||
glEnableVertexAttribArray(2);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@ -396,75 +387,94 @@ err:
|
||||
|
||||
void create_mask(struct render *render)
|
||||
{
|
||||
static EGLint attrib[] =
|
||||
{
|
||||
EGL_GL_TEXTURE_LEVEL_KHR, 0,
|
||||
EGL_NONE
|
||||
};
|
||||
struct drm_i915_gem_mmap_gtt mmap_arg;
|
||||
struct drm_i915_gem_create create;
|
||||
struct drm_gem_flink flink;
|
||||
|
||||
struct drm_i915_gem_mmap mmap_arg;
|
||||
EGLint handle, stride;
|
||||
int winw, winh, pitch;
|
||||
void *data;
|
||||
int ret;
|
||||
GLuint mask_handle, mask_name;
|
||||
EGLImageKHR mask_image;
|
||||
|
||||
|
||||
glGenTextures(1, &render->tx_mask);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err1;
|
||||
return;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_mask);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err2;
|
||||
goto err1;
|
||||
|
||||
|
||||
pitch = (render->width+15) & ~15;
|
||||
|
||||
create.size = pitch *render->height;
|
||||
create.handle = 0;
|
||||
ret = drm_ioctl(render->fd, DRM_IOCTL_I915_GEM_CREATE, &create);
|
||||
if(ret != 0)
|
||||
goto err1;
|
||||
|
||||
flink.handle = create.handle;
|
||||
ret = drm_ioctl(render->fd, DRM_IOCTL_GEM_FLINK, &flink);
|
||||
if (ret != 0)
|
||||
goto err2;
|
||||
|
||||
mask_handle = create.handle;
|
||||
mask_name = flink.name;
|
||||
|
||||
printf("create mask bo handle %d name %d\n", create.handle, flink.name);
|
||||
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_DRM_BUFFER_STRIDE_MESA, 0,
|
||||
EGL_DRM_BUFFER_FORMAT_MESA,
|
||||
EGL_DRM_BUFFER_FORMAT_R8_MESA,
|
||||
EGL_DRM_BUFFER_USE_MESA,
|
||||
EGL_DRM_BUFFER_USE_SHARE_MESA,
|
||||
EGL_NONE
|
||||
};
|
||||
attribs[1] = pitch;
|
||||
attribs[3] = render->height;
|
||||
attribs[5] = pitch;
|
||||
|
||||
mask_image = eglCreateImageKHR(render->dpy, render->context, EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)mask_name, attribs);
|
||||
|
||||
printf("create mask image %p\n", mask_image);
|
||||
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
winw = render->width+10;
|
||||
winh = render->height+20+5;
|
||||
|
||||
pitch = (winw+3) & -4;
|
||||
|
||||
data = user_alloc(pitch * winh);
|
||||
|
||||
memset(data, 0x20, pitch * winh);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, winw, winh, 0,
|
||||
GL_RED,GL_UNSIGNED_BYTE, data);
|
||||
|
||||
user_free(data);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, mask_image);
|
||||
|
||||
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.handle = mask_handle;
|
||||
mmap_arg.offset = 0;
|
||||
// mmap_arg.size = stride * winh;
|
||||
if (drm_ioctl(render->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
|
||||
mmap_arg.size = pitch * 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*winh);
|
||||
__FUNCTION__, mask_image, mask_handle, pitch * render->height);
|
||||
goto err3;
|
||||
}
|
||||
|
||||
render->mask_buffer = (void *)(uintptr_t)mmap_arg.offset;
|
||||
render->mask_handle = handle;
|
||||
|
||||
printf("%s: mmap image %p handle=%d, stride %d %d bytes to %p\n",
|
||||
__FUNCTION__, render->mask, handle, stride, stride*winh, render->mask_buffer);
|
||||
render->mask_handle = mask_handle;
|
||||
render->mask_name = mask_name;
|
||||
render->mask_buffer = (void *)(uintptr_t)mmap_arg.addr_ptr;
|
||||
render->mask_image = mask_image;
|
||||
|
||||
return;
|
||||
|
||||
err3:
|
||||
eglDestroyImageKHR(render->dpy, render->mask);
|
||||
// eglDestroyImageKHR(render->dpy, render->mask);
|
||||
err2:
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
err1:
|
||||
|
@ -23,12 +23,16 @@ struct render
|
||||
EGLint width, height;
|
||||
EGLint scr_width, scr_height;
|
||||
GLuint framebuffer;
|
||||
EGLImageKHR screen, front, back, mask;
|
||||
EGLImageKHR screen, front, back;
|
||||
GLuint tx_buffers[2];
|
||||
GLuint tx_screen;
|
||||
GLuint tx_mask;
|
||||
|
||||
GLuint mask_handle;
|
||||
void *mask_buffer;
|
||||
GLuint mask_name;
|
||||
void *mask_buffer;
|
||||
EGLImageKHR mask_image;
|
||||
|
||||
int back_buffer;
|
||||
GLuint blit_prog;
|
||||
GLint sampler, sm_mask;
|
||||
|
@ -50,27 +50,27 @@ void render_swap_and_blit(struct render *render)
|
||||
|
||||
eglSwapBuffers(render->dpy,draw);
|
||||
|
||||
render->back_buffer++;
|
||||
render->back_buffer&=1;
|
||||
|
||||
update.handle = render->mask_handle;
|
||||
update.dx = render->dx;
|
||||
update.dy = render->dy;
|
||||
update.width = render->width;
|
||||
update.height = render->height;
|
||||
update.bo_pitch = (render->width+15) & ~15;
|
||||
update.bo_map = (int)render->mask_buffer;
|
||||
|
||||
if(drm_ioctl(render->fd, 45, &update))
|
||||
return;
|
||||
|
||||
|
||||
if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
|
||||
{
|
||||
printf("failed to make window current");
|
||||
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
|
||||
|
||||
update.handle = render->mask_handle;
|
||||
update.bo_map = (int)render->mask_buffer;
|
||||
drm_ioctl(render->fd, SRV_MASK_UPDATE, &update);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
|
||||
@ -110,21 +110,6 @@ void render_swap_and_blit(struct render *render)
|
||||
texcoords[3*2] = 0.0;
|
||||
texcoords[3*2+1]= 1.0;
|
||||
|
||||
texcoords = render->tc_mask;
|
||||
|
||||
xscale = 1.0/winw;
|
||||
yscale = 1.0/winh;
|
||||
|
||||
texcoords[0] = render->dx * xscale;
|
||||
texcoords[1] = render->dy * yscale;
|
||||
texcoords[1*2] = (render->dx+render->width)*xscale;
|
||||
texcoords[1*2+1]= render->dy * yscale;
|
||||
texcoords[2*2] = (render->dx+render->width)*xscale;
|
||||
texcoords[2*2+1]= (render->dy+render->height)*yscale;
|
||||
texcoords[3*2] = render->dx * xscale;
|
||||
texcoords[3*2+1]= (render->dy+render->height)*yscale;
|
||||
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glFlush();
|
||||
|
||||
@ -133,8 +118,6 @@ void render_swap_and_blit(struct render *render)
|
||||
// glDisable(GL_TEXTURE_2D);
|
||||
// glUseProgram(0);
|
||||
|
||||
render->back_buffer++;
|
||||
render->back_buffer&=1;
|
||||
|
||||
err1:
|
||||
eglMakeCurrent(render->dpy, draw, read, context);
|
||||
|
Loading…
Reference in New Issue
Block a user