Subversion Repositories Kolibri OS

Rev

Rev 4525 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4525 Rev 4526
1
#include 
1
#include 
2
#include 
2
#include 
3
#include 
3
#include 
4
 
4
 
5
#include "render.h"
5
#include "render.h"
6
#include 
6
#include 
7
#include 
7
#include 
-
 
8
 
-
 
9
#define WIN_STATE_MINIMIZED  0x02
-
 
10
#define WIN_STATE_ROLLED     0x04
8
 
11
 
9
static int drm_ioctl(int fd, unsigned long request, void *arg)
12
static int drm_ioctl(int fd, unsigned long request, void *arg)
10
{
13
{
11
    ioctl_t  io;
14
    ioctl_t  io;
12
 
15
 
13
    io.handle   = fd;
16
    io.handle   = fd;
14
    io.io_code  = request;
17
    io.io_code  = request;
15
    io.input    = arg;
18
    io.input    = arg;
16
    io.inp_size = 64;
19
    io.inp_size = 64;
17
    io.output   = NULL;
20
    io.output   = NULL;
18
    io.out_size = 0;
21
    io.out_size = 0;
19
 
22
 
20
    return call_service(&io);
23
    return call_service(&io);
21
}
24
}
22
 
25
 
23
void render_swap_and_blit(struct render *render)
26
void render_swap_and_blit(struct render *render)
24
{
27
{
25
    char proc_info[1024];
28
    char proc_info[1024];
26
    struct drm_i915_mask_update update;
29
    struct drm_i915_mask_update update;
27
 
30
 
28
    EGLContext context;
31
    EGLContext context;
29
    EGLSurface draw, read;
32
    EGLSurface draw, read;
30
    int winx, winy, winw, winh;
33
    uint32_t winx, winy, winw, winh;
31
 
-
 
-
 
34
    uint8_t  state;
32
    float xscale, yscale;
35
    float xscale, yscale;
33
    float *vertices  = render->vertices;
36
    float *vertices  = render->vertices;
34
    float *texcoords = render->tc_src;
37
    float *texcoords = render->tc_src;
35
    int r, b;
38
    int r, b;
36
 
39
 
37
    if(render == NULL)
40
    if(render == NULL)
38
        return;
41
        return;
39
 
42
 
40
    get_proc_info(proc_info);
43
    get_proc_info(proc_info);
41
 
44
 
42
    winx = *(uint32_t*)(proc_info+34);
45
    winx = *(uint32_t*)(proc_info+34);
43
    winy = *(uint32_t*)(proc_info+38);
46
    winy = *(uint32_t*)(proc_info+38);
44
    winw = *(uint32_t*)(proc_info+42)+1;
47
    winw = *(uint32_t*)(proc_info+42)+1;
45
    winh = *(uint32_t*)(proc_info+46)+1;
48
    winh = *(uint32_t*)(proc_info+46)+1;
-
 
49
    state  = *(uint8_t*)(proc_info+70);
-
 
50
 
-
 
51
    if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED))
-
 
52
        return;
46
 
53
 
47
    context = eglGetCurrentContext();
54
    context = eglGetCurrentContext();
48
    draw = eglGetCurrentSurface(EGL_DRAW);
55
    draw = eglGetCurrentSurface(EGL_DRAW);
49
    read = eglGetCurrentSurface(EGL_READ);
56
    read = eglGetCurrentSurface(EGL_READ);
50
 
57
 
51
    eglSwapBuffers(render->dpy,draw);
58
    eglSwapBuffers(render->dpy,draw);
52
 
59
 
53
    render->back_buffer++;
60
    render->back_buffer++;
54
    render->back_buffer&=1;
61
    render->back_buffer&=1;
55
 
62
 
56
    update.handle = render->mask_handle;
63
    update.handle = render->mask_handle;
57
    update.dx     = render->dx;
64
    update.dx     = render->dx;
58
    update.dy     = render->dy;
65
    update.dy     = render->dy;
59
    update.width  = render->width;
66
    update.width  = render->width;
60
    update.height = render->height;
67
    update.height = render->height;
61
    update.bo_pitch = (render->width+15) & ~15;
68
    update.bo_pitch = (render->width+15) & ~15;
62
    update.bo_map = (int)render->mask_buffer;
69
    update.bo_map = (int)render->mask_buffer;
63
 
70
 
64
    if(drm_ioctl(render->fd, 45, &update))
71
    if(drm_ioctl(render->fd, 45, &update))
65
        return;
72
        return;
66
 
-
 
67
 
73
 
68
    if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
74
    if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
69
    {
75
    {
70
        printf("failed to make window current");
76
        printf("failed to make window current");
71
        goto err1;
77
        goto err1;
72
    };
78
    };
73
 
-
 
74
 
79
 
75
    glActiveTexture(GL_TEXTURE0);
80
    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
 
81
    glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
84
 
82
 
85
    xscale = 1.0/render->scr_width;
83
    xscale = 1.0/render->scr_width;
86
    yscale = 1.0/render->scr_height;
84
    yscale = 1.0/render->scr_height;
87
 
85
 
88
    r = winx + render->dx + render->width;
86
    r = winx + render->dx + render->width;
89
    b = winy + render->dy + render->height;
87
    b = winy + render->dy + render->height;
90
 
88
 
91
    float t0, t1, t2, t5;
89
    float t0, t1, t2, t5;
92
 
90
 
93
    vertices[0]     = t0 = 2*(winx+render->dx)*xscale - 1.0;
91
    vertices[0]     = t0 = 2*(winx+render->dx)*xscale - 1.0;
94
    vertices[1 * 2] = t2 = 2*r*xscale - 1.0;
92
    vertices[1 * 2] = t2 = 2*r*xscale - 1.0;
95
 
93
 
96
    vertices[2 * 2] = t2;
94
    vertices[2 * 2] = t2;
97
    vertices[3 * 2] = t0;
95
    vertices[3 * 2] = t0;
98
 
96
 
99
    vertices[1]     = t1 = 2*(winy+render->dy)*yscale - 1.0;
97
    vertices[1]     = t1 = 2*(winy+render->dy)*yscale - 1.0;
100
    vertices[2*2+1] = t5 = 2*b*yscale - 1.0;
98
    vertices[2*2+1] = t5 = 2*b*yscale - 1.0;
101
    vertices[1*2+1] = t1;
99
    vertices[1*2+1] = t1;
102
    vertices[3*2+1] = t5;
100
    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
 
101
 
113
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
102
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
114
    glFlush();
-
 
115
 
-
 
116
//    glDisableVertexAttribArray(0);
-
 
117
//    glDisableVertexAttribArray(1);
-
 
118
//    glDisable(GL_TEXTURE_2D);
-
 
119
//    glUseProgram(0);
-
 
120
 
103
//    glFlush();
121
 
104
 
122
err1:
105
err1:
123
    eglMakeCurrent(render->dpy, draw, read, context);
106
    eglMakeCurrent(render->dpy, draw, read, context);
124
}
107
}