VIGS: add h/w conversion from ARGB to XBGR
[sdk/emulator/qemu.git] / hw / vigs / vigs_gl_backend.h
1 /*
2  * vigs
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  * Stanislav Vorobiov <s.vorobiov@samsung.com>
8  * Jinhyung Jo <jinhyung.jo@samsung.com>
9  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  *
25  * Contributors:
26  * - S-Core Co., Ltd
27  *
28  */
29
30 #ifndef _QEMU_VIGS_GL_BACKEND_H
31 #define _QEMU_VIGS_GL_BACKEND_H
32
33 #include "vigs_types.h"
34 #include "vigs_backend.h"
35 #include "vigs_vector.h"
36 #include <GL/gl.h>
37 #include <GL/glext.h>
38 #include "winsys_gl.h"
39
40 #define TEXTURE_NUM 5
41
42 struct vigs_gl_pool;
43
44 struct vigs_gl_backend
45 {
46     struct vigs_backend base;
47
48     struct winsys_gl_info ws_info;
49
50     bool is_gl_2;
51
52     bool (*has_current)(struct vigs_gl_backend */*gl_backend*/);
53
54     bool (*make_current)(struct vigs_gl_backend */*gl_backend*/,
55                          bool /*enable*/);
56
57     bool (*read_pixels_make_current)(struct vigs_gl_backend */*gl_backend*/,
58                                      bool /*enable*/);
59
60     /*
61      * Mandatory GL functions and extensions.
62      * @{
63      */
64
65     void (GLAPIENTRY *GenTextures)(GLsizei n, GLuint *textures);
66     void (GLAPIENTRY *DeleteTextures)(GLsizei n, const GLuint *textures);
67     void (GLAPIENTRY *BindTexture)(GLenum target, GLuint texture);
68     void (GLAPIENTRY *CullFace)(GLenum mode);
69     void (GLAPIENTRY *TexParameterf)(GLenum target, GLenum pname, GLfloat param);
70     void (GLAPIENTRY *TexParameterfv)(GLenum target, GLenum pname, const GLfloat *params);
71     void (GLAPIENTRY *TexParameteri)(GLenum target, GLenum pname, GLint param);
72     void (GLAPIENTRY *TexParameteriv)(GLenum target, GLenum pname, const GLint *params);
73     void (GLAPIENTRY *TexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
74     void (GLAPIENTRY *TexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
75     void (GLAPIENTRY *Clear)(GLbitfield mask);
76     void (GLAPIENTRY *ClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
77     void (GLAPIENTRY *Disable)(GLenum cap);
78     void (GLAPIENTRY *Enable)(GLenum cap);
79     void (GLAPIENTRY *Finish)(void);
80     void (GLAPIENTRY *Flush)(void);
81     void (GLAPIENTRY *PixelStorei)(GLenum pname, GLint param);
82     void (GLAPIENTRY *ReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
83     void (GLAPIENTRY *Viewport)(GLint x, GLint y, GLsizei width, GLsizei height);
84     void (GLAPIENTRY *GenFramebuffers)(GLsizei n, GLuint *framebuffers);
85     void (GLAPIENTRY *GenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
86     void (GLAPIENTRY *DeleteFramebuffers)(GLsizei n, const GLuint *framebuffers);
87     void (GLAPIENTRY *DeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers);
88     void (GLAPIENTRY *BindFramebuffer)(GLenum target, GLuint framebuffer);
89     void (GLAPIENTRY *BindRenderbuffer)(GLenum target, GLuint renderbuffer);
90     void (GLAPIENTRY *RenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
91     void (GLAPIENTRY *FramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
92     void (GLAPIENTRY *FramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
93     void (GLAPIENTRY *GetIntegerv)(GLenum pname, GLint *params);
94     const GLubyte *(GLAPIENTRY *GetString)(GLenum name);
95     void (GLAPIENTRY *DrawArrays)(GLenum mode, GLint first, GLsizei count);
96     void (GLAPIENTRY *BlendFunc)(GLenum sfactor, GLenum dfactor);
97     void (GLAPIENTRY *GenBuffers)(GLsizei n, GLuint *buffers);
98     void (GLAPIENTRY *DeleteBuffers)(GLsizei n, const GLuint *buffers);
99     void (GLAPIENTRY *BindBuffer)(GLenum target, GLuint buffer);
100     void (GLAPIENTRY *BufferData)(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
101     void (GLAPIENTRY *BufferSubData)(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
102     GLvoid *(GLAPIENTRY *MapBuffer)(GLenum target, GLenum access);
103     GLboolean (GLAPIENTRY *UnmapBuffer)(GLenum target);
104     GLuint (GLAPIENTRY* CreateProgram)(void);
105     GLuint (GLAPIENTRY* CreateShader)(GLenum type);
106     void (GLAPIENTRY* CompileShader)(GLuint shader);
107     void (GLAPIENTRY* AttachShader)(GLuint program, GLuint shader);
108     void (GLAPIENTRY* LinkProgram)(GLuint program);
109     void (GLAPIENTRY* GetProgramiv)(GLuint program, GLenum pname, GLint* params);
110     void (GLAPIENTRY* GetProgramInfoLog)(GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
111     void (GLAPIENTRY* GetShaderiv)(GLuint shader, GLenum pname, GLint* params);
112     void (GLAPIENTRY* GetShaderInfoLog)(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
113     void (GLAPIENTRY* DetachShader)(GLuint program, GLuint shader);
114     void (GLAPIENTRY* DeleteProgram)(GLuint program);
115     void (GLAPIENTRY* DeleteShader)(GLuint shader);
116     void (GLAPIENTRY* DisableVertexAttribArray)(GLuint index);
117     void (GLAPIENTRY* EnableVertexAttribArray)(GLuint index);
118     void (GLAPIENTRY* ShaderSource)(GLuint shader, GLsizei count, const GLchar** string, const GLint* length);
119     void (GLAPIENTRY* UseProgram)(GLuint program);
120     GLint (GLAPIENTRY* GetAttribLocation)(GLuint program, const GLchar* name);
121     GLint (GLAPIENTRY* GetUniformLocation)(GLuint program, const GLchar* name);
122     void (GLAPIENTRY* VertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
123     void (GLAPIENTRY* Uniform4fv)(GLint location, GLsizei count, const GLfloat* value);
124     void (GLAPIENTRY* UniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
125     void (GLAPIENTRY* Uniform2fv)(GLint location, GLsizei count, const GLfloat* value);
126     void (GLAPIENTRY* Uniform1f)(GLint location, GLfloat v0);
127     void (GLAPIENTRY* Uniform1i)(GLint location, GLint v0);
128     void (GLAPIENTRY* Uniform2f)(GLint location, GLfloat v0, GLfloat v1);
129     void (GLAPIENTRY* ActiveTexture)(GLenum texture);
130
131     /*
132      * @}
133      */
134
135     /*
136      * Only OpenGL 2.1 + GL_ARB_map_buffer_range or OpenGL 3.1+ core.
137      */
138     GLvoid *(GLAPIENTRY *MapBufferRange)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
139
140     /*
141      * OpenGL 3.1+ core functions and extensions.
142      * @{
143      */
144
145     void (GLAPIENTRY* GenVertexArrays)(GLsizei n, GLuint* arrays);
146     void (GLAPIENTRY* BindVertexArray)(GLuint array);
147     void (GLAPIENTRY* DeleteVertexArrays)(GLsizei n, const GLuint* arrays);
148
149     /*
150      * @}
151      */
152
153     struct vigs_gl_pool *tex_pool;
154     struct vigs_gl_pool *fb_pool;
155
156     /*
157      * General purpose vectors.
158      * @{
159      */
160
161     struct vigs_vector v1;
162     struct vigs_vector v2;
163
164     /*
165      * @}
166      */
167
168     /*
169      * Rendering thread related.
170      * @{
171      */
172
173     GLuint vao;
174
175     GLuint tex_prog_vs_id;
176     GLuint tex_prog_fs_id;
177     GLuint tex_prog_id;
178     GLint tex_prog_proj_loc;
179     GLint tex_prog_vertCoord_loc;
180     GLint tex_prog_texCoord_loc;
181
182     GLuint color_prog_vs_id;
183     GLuint color_prog_fs_id;
184     GLuint color_prog_id;
185     GLint color_prog_proj_loc;
186     GLint color_prog_vertCoord_loc;
187     GLint color_prog_color_loc;
188
189     GLuint nv21_prog_vs_id;
190     GLuint nv21_prog_fs_id;
191     GLuint nv21_prog_id;
192     GLint nv21_prog_proj_loc;
193     GLint nv21_prog_vertCoord_loc;
194     GLint nv21_prog_texCoord_loc;
195     GLint nv21_prog_size_loc;
196     GLint nv21_prog_ytexSize_loc;
197     GLint nv21_prog_ctexSize_loc;
198     GLint nv21_prog_ytex_loc;
199     GLint nv21_prog_ctex_loc;
200
201     GLuint yuv420_prog_vs_id;
202     GLuint yuv420_prog_fs_id;
203     GLuint yuv420_prog_id;
204     GLint yuv420_prog_proj_loc;
205     GLint yuv420_prog_vertCoord_loc;
206     GLint yuv420_prog_texCoord_loc;
207     GLint yuv420_prog_size_loc;
208     GLint yuv420_prog_ytexSize_loc;
209     GLint yuv420_prog_utexSize_loc;
210     GLint yuv420_prog_vtexSize_loc;
211     GLint yuv420_prog_ytex_loc;
212     GLint yuv420_prog_utex_loc;
213     GLint yuv420_prog_vtex_loc;
214
215     GLuint xbgr_prog_fs_id;
216     GLuint xbgr_prog_id;
217     GLint xbgr_prog_proj_loc;
218     GLint xbgr_prog_vertCoord_loc;
219     GLint xbgr_prog_texCoord_loc;
220
221     GLuint vbo;
222     uint32_t vbo_size;
223
224     GLuint cur_prog_id;
225
226     /*
227      * @}
228      * Display thread related.
229      * @{
230      */
231
232     struct dpy_item {
233         GLuint tex;
234         uint32_t width;
235         uint32_t height;
236
237         bool available;
238         QemuMutex mutex;
239     } dpy_items[TEXTURE_NUM], *current_dpy;
240
241     uint32_t dpy_idx;
242
243     GLuint dpy_fb;
244
245     /*
246      * @}
247      */
248 };
249
250 bool vigs_gl_backend_init(struct vigs_gl_backend *gl_backend);
251
252 void vigs_gl_backend_cleanup(struct vigs_gl_backend *gl_backend);
253
254 #endif