Subversion Repositories Kolibri OS

Rev

Rev 4517 | Rev 4525 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "render.h"
  6. #include <i915_drm.h>
  7. #include <kos32sys.h>
  8.  
  9. static int drm_ioctl(int fd, unsigned long request, void *arg)
  10. {
  11.     ioctl_t  io;
  12.  
  13.     io.handle   = fd;
  14.     io.io_code  = request;
  15.     io.input    = arg;
  16.     io.inp_size = 64;
  17.     io.output   = NULL;
  18.     io.out_size = 0;
  19.  
  20.     return call_service(&io);
  21. }
  22.  
  23. void render_swap_and_blit(struct render *render)
  24. {
  25.     char proc_info[1024];
  26.     struct drm_i915_mask_update update;
  27.  
  28.     EGLContext context;
  29.     EGLSurface draw, read;
  30.     int winx, winy, winw, winh;
  31.  
  32.     float xscale, yscale;
  33.     float *vertices  = render->vertices;
  34.     float *texcoords = render->tc_src;
  35.     int r, b;
  36.  
  37.     if(render == NULL)
  38.         return;
  39.  
  40.     get_proc_info(proc_info);
  41.  
  42.     winx = *(uint32_t*)(proc_info+34);
  43.     winy = *(uint32_t*)(proc_info+38);
  44.     winw = *(uint32_t*)(proc_info+42)+1;
  45.     winh = *(uint32_t*)(proc_info+46)+1;
  46.  
  47.     context = eglGetCurrentContext();
  48.     draw = eglGetCurrentSurface(EGL_DRAW);
  49.     read = eglGetCurrentSurface(EGL_READ);
  50.  
  51.     eglSwapBuffers(render->dpy,draw);
  52.  
  53.     if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
  54.     {
  55.         printf("failed to make window current");
  56.         goto err1;
  57.     };
  58.  
  59. #if 0
  60.     glUseProgram(render->blit_prog);
  61.     glUniform1i(render->sampler, 0);
  62.  
  63.     glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices);
  64.     glEnableVertexAttribArray(0);
  65.  
  66.     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->texcoords);
  67.     glEnableVertexAttribArray(1);
  68.  
  69. #endif
  70.  
  71.     update.handle = render->mask_handle;
  72.     update.bo_map = (int)render->mask_buffer;
  73.     drm_ioctl(render->fd, SRV_MASK_UPDATE, &update);
  74.  
  75.     glActiveTexture(GL_TEXTURE0);
  76.     glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
  77.     glTexParameteri(GL_TEXTURE_2D,
  78.                   GL_TEXTURE_MIN_FILTER,
  79.                   GL_NEAREST);
  80.     glTexParameteri(GL_TEXTURE_2D,
  81.                   GL_TEXTURE_MAG_FILTER,
  82.                   GL_NEAREST);
  83.  
  84.  
  85.     xscale = 1.0/render->scr_width;
  86.     yscale = 1.0/render->scr_height;
  87.  
  88.     r = winx + render->dx + render->width;
  89.     b = winy + render->dy + render->height;
  90.  
  91.     float t0, t1, t2, t5;
  92.  
  93.     vertices[0]     = t0 = 2*(winx+render->dx)*xscale - 1.0;
  94.     vertices[1 * 2] = t2 = 2*r*xscale - 1.0;
  95.  
  96.     vertices[2 * 2] = t2;
  97.     vertices[3 * 2] = t0;
  98.  
  99.     vertices[1]     = t1 = 2*(winy+render->dy)*yscale - 1.0;
  100.     vertices[2*2+1] = t5 = 2*b*yscale - 1.0;
  101.     vertices[1*2+1] = t1;
  102.     vertices[3*2+1] = t5;
  103.  
  104.     texcoords[0]    = 0.0;
  105.     texcoords[1]    = 0.0;
  106.     texcoords[1*2]  = 1.0;
  107.     texcoords[1*2+1]= 0.0;
  108.     texcoords[2*2]  = 1.0;
  109.     texcoords[2*2+1]= 1.0;
  110.     texcoords[3*2]  = 0.0;
  111.     texcoords[3*2+1]= 1.0;
  112.  
  113.     texcoords = render->tc_mask;
  114.  
  115.     xscale = 1.0/winw;
  116.     yscale = 1.0/winh;
  117.  
  118.     texcoords[0]    = render->dx * xscale;
  119.     texcoords[1]    = render->dy * yscale;
  120.     texcoords[1*2]  = (render->dx+render->width)*xscale;
  121.     texcoords[1*2+1]= render->dy * yscale;
  122.     texcoords[2*2]  = (render->dx+render->width)*xscale;
  123.     texcoords[2*2+1]= (render->dy+render->height)*yscale;
  124.     texcoords[3*2]  = render->dx * xscale;
  125.     texcoords[3*2+1]= (render->dy+render->height)*yscale;
  126.  
  127.  
  128.     glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  129.     glFlush();
  130.  
  131. //    glDisableVertexAttribArray(0);
  132. //    glDisableVertexAttribArray(1);
  133. //    glDisable(GL_TEXTURE_2D);
  134. //    glUseProgram(0);
  135.  
  136.     render->back_buffer++;
  137.     render->back_buffer&=1;
  138.  
  139. err1:
  140.     eglMakeCurrent(render->dpy, draw, read, context);
  141. }
  142.  
  143.