summaryrefslogtreecommitdiffstats
path: root/mutter-use-cogl-texrect-api.patch
blob: 11950b3b17289cd6fe1e5613ab75efa29e5b8162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
From ed358c8f4b1200e8532dcc0b249f51752d2695eb Mon Sep 17 00:00:00 2001
From: Neil Roberts <neil@linux.intel.com>
Date: Fri, 23 Mar 2012 18:51:25 +0000
Subject: meta-texture-rectangle: Use Cogl's API to create a rectangle texture

Cogl now has public experimental API to create a rectangle texture
which we can use instead of creating a foreign texture with GL. This
avoids Mutter depending on Cogl including a GL header from its public
headers which it might not do in future.

https://bugzilla.gnome.org/show_bug.cgi?id=672711
---
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index 182d23b..ae21945 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -250,7 +250,6 @@ meta_shaped_texture_ensure_mask (MetaShapedTexture *stex)
       int i;
       int n_rects;
       int stride;
-      GLenum paint_gl_target;
 
       /* If we have no shape region and no (or an empty) overlay region, we
        * don't need to create a full mask texture, so quit early. */
@@ -293,26 +292,14 @@ meta_shaped_texture_ensure_mask (MetaShapedTexture *stex)
 
       install_overlay_path (stex, mask_data, tex_width, tex_height, stride);
 
-      cogl_texture_get_gl_texture (paint_tex, NULL, &paint_gl_target);
-
-#ifdef GL_TEXTURE_RECTANGLE_ARB
-      if (paint_gl_target == GL_TEXTURE_RECTANGLE_ARB)
-        {
-          priv->mask_texture
-            = meta_texture_rectangle_new (tex_width, tex_height,
-                                          0, /* flags */
-                                          /* data format */
-                                          COGL_PIXEL_FORMAT_A_8,
-                                          /* internal GL format */
-                                          GL_ALPHA,
-                                          /* internal cogl format */
-                                          COGL_PIXEL_FORMAT_A_8,
-                                          /* rowstride */
-                                          stride,
-                                          mask_data);
-        }
+      if (meta_texture_rectangle_check (paint_tex))
+        priv->mask_texture = meta_texture_rectangle_new (tex_width, tex_height,
+                                                         COGL_PIXEL_FORMAT_A_8,
+                                                         COGL_PIXEL_FORMAT_A_8,
+                                                         stride,
+                                                         mask_data,
+                                                         NULL /* error */);
       else
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
         {
 	  /* Note: we don't allow slicing for this texture because we
            * need to use it with multi-texturing which doesn't support
diff --git a/src/compositor/meta-texture-rectangle.c b/src/compositor/meta-texture-rectangle.c
index d699729..af6817f 100644
--- a/src/compositor/meta-texture-rectangle.c
+++ b/src/compositor/meta-texture-rectangle.c
@@ -5,7 +5,7 @@
  *
  * Authored By Neil Roberts  <neil@linux.intel.com>
  *
- * Copyright (C) 2011 Intel Corporation
+ * Copyright (C) 2011, 2012 Intel Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -25,94 +25,77 @@
 
 #include <config.h>
 
-#include "meta-texture-rectangle.h"
-
-#ifdef GL_TEXTURE_RECTANGLE_ARB
+#define CLUTTER_ENABLE_EXPERIMENTAL_API
+#define COGL_ENABLE_EXPERIMENTAL_API
 
-static void (* pf_glGetIntegerv) (GLenum pname, GLint *params);
-static void (* pf_glTexImage2D) (GLenum target, GLint level,
-                                 GLint internalFormat,
-                                 GLsizei width, GLsizei height,
-                                 GLint border, GLenum format, GLenum type,
-                                 const GLvoid *pixels);
-static void (* pf_glGenTextures) (GLsizei n, GLuint *textures);
-static void (* pf_glDeleteTextures) (GLsizei n, const GLuint *texture);
-static void (* pf_glBindTexture) (GLenum target, GLuint texture);
-
-static void
-rectangle_texture_destroy_cb (void *user_data)
-{
-  GLuint tex = GPOINTER_TO_UINT (user_data);
-
-  pf_glDeleteTextures (1, &tex);
-}
-
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
+#include <clutter/clutter.h>
+#include "meta-texture-rectangle.h"
 
-CoglHandle
+CoglTexture *
 meta_texture_rectangle_new (unsigned int width,
                             unsigned int height,
-                            CoglTextureFlags flags,
                             CoglPixelFormat format,
-                            GLenum internal_gl_format,
-                            GLenum internal_format,
+                            CoglPixelFormat internal_format,
                             unsigned int rowstride,
-                            const guint8 *data)
+                            const guint8 *data,
+                            GError **error)
 {
-  CoglHandle cogl_tex = COGL_INVALID_HANDLE;
-
-#ifdef GL_TEXTURE_RECTANGLE_ARB
-
-  static CoglUserDataKey user_data_key;
-  GLint old_binding;
-  GLuint tex;
-
-  if (pf_glGenTextures == NULL)
-    {
-      pf_glGetIntegerv = (void *) cogl_get_proc_address ("glGetIntegerv");
-      pf_glTexImage2D = (void *) cogl_get_proc_address ("glTexImage2D");
-      pf_glGenTextures = (void *) cogl_get_proc_address ("glGenTextures");
-      pf_glDeleteTextures = (void *) cogl_get_proc_address ("glDeleteTextures");
-      pf_glBindTexture = (void *) cogl_get_proc_address ("glBindTexture");
-    }
-
-  pf_glGenTextures (1, &tex);
-  pf_glGetIntegerv (GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
-  pf_glBindTexture (GL_TEXTURE_RECTANGLE_ARB, tex);
-  pf_glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0,
-                   internal_gl_format, width, height,
-                   0, internal_gl_format,
-                   GL_UNSIGNED_BYTE, NULL);
-  pf_glBindTexture (GL_TEXTURE_RECTANGLE_ARB, old_binding);
+  ClutterBackend *backend =
+    clutter_get_default_backend ();
+  CoglContext *context =
+    clutter_backend_get_cogl_context (backend);
+  CoglTextureRectangle *tex_rect;
+
+  tex_rect = cogl_texture_rectangle_new_with_size (context,
+                                                   width, height,
+                                                   internal_format,
+                                                   error);
+  if (tex_rect == NULL)
+    return NULL;
 
-  cogl_tex = cogl_texture_new_from_foreign (tex,
-                                            GL_TEXTURE_RECTANGLE_ARB,
-                                            width, height,
-                                            0, 0, /* no waste */
-                                            internal_format);
-
-  /* Cogl won't destroy the GL texture when a foreign texture is used
-     so we need to destroy it manually. We can set a destroy
-     notification callback to do this transparently */
-  cogl_object_set_user_data (cogl_tex,
-                             &user_data_key,
-                             GUINT_TO_POINTER (tex),
-                             rectangle_texture_destroy_cb);
-
-  /* Use cogl_texture_set_region instead of uploading the data
-     directly with GL calls so that we can let Cogl deal with setting
-     the pixel store parameters and handling format conversion */
   if (data)
-    cogl_texture_set_region (cogl_tex,
-                             0, 0, /* src x/y */
-                             0, 0, /* dst x/y */
-                             width, height, /* dst width/height */
-                             width, height, /* src width/height */
+    cogl_texture_set_region (COGL_TEXTURE (tex_rect),
+                             0, 0, /* src_x/y */
+                             0, 0, /* dst_x/y */
+                             width, height, /* dst_width/height */
+                             width, height, /* width/height */
                              format,
                              rowstride,
                              data);
 
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
+  return COGL_TEXTURE (tex_rect);
+}
+
+static void
+texture_rectangle_check_cb (CoglTexture *sub_texture,
+                            const float *sub_texture_coords,
+                            const float *meta_coords,
+                            void *user_data)
+{
+  gboolean *result = user_data;
+
+  if (cogl_is_texture_rectangle (sub_texture))
+    *result = TRUE;
+}
+
+/* Determines if the given texture is using a rectangle texture as its
+ * primitive texture type. Eventually this function could be replaced
+ * with cogl_texture_get_type if Cogl makes that public.
+ *
+ * http://git.gnome.org/browse/cogl/commit/?h=8012eee31
+ */
+gboolean
+meta_texture_rectangle_check (CoglTexture *texture)
+{
+  gboolean result = FALSE;
+
+  cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture),
+                                       0.0f, 0.0f, /* tx_1 / ty_1 */
+                                       1.0f, 1.0f, /* tx_2 / ty_2 */
+                                       COGL_PIPELINE_WRAP_MODE_REPEAT,
+                                       COGL_PIPELINE_WRAP_MODE_REPEAT,
+                                       texture_rectangle_check_cb,
+                                       &result);
 
-  return cogl_tex;
+  return result;
 }
diff --git a/src/compositor/meta-texture-rectangle.h b/src/compositor/meta-texture-rectangle.h
index b777316..7372b29 100644
--- a/src/compositor/meta-texture-rectangle.h
+++ b/src/compositor/meta-texture-rectangle.h
@@ -30,15 +30,17 @@
 
 G_BEGIN_DECLS
 
-CoglHandle
+CoglTexture *
 meta_texture_rectangle_new (unsigned int width,
                             unsigned int height,
-                            CoglTextureFlags flags,
                             CoglPixelFormat format,
-                            GLenum internal_gl_format,
-                            GLenum internal_format,
+                            CoglPixelFormat internal_format,
                             unsigned int rowstride,
-                            const guint8 *data);
+                            const guint8 *data,
+                            GError **error);
+
+gboolean
+meta_texture_rectangle_check (CoglTexture *texture);
 
 G_END_DECLS
 
diff --git a/src/compositor/meta-texture-tower.c b/src/compositor/meta-texture-tower.c
index 0025472..2dee777 100644
--- a/src/compositor/meta-texture-tower.c
+++ b/src/compositor/meta-texture-tower.c
@@ -98,18 +98,6 @@ meta_texture_tower_free (MetaTextureTower *tower)
   g_slice_free (MetaTextureTower, tower);
 }
 
-#ifdef GL_TEXTURE_RECTANGLE_ARB
-static gboolean
-texture_is_rectangle (CoglHandle texture)
-{
-  GLuint gl_tex;
-  GLenum gl_target;
-
-  cogl_texture_get_gl_texture (texture, &gl_tex, &gl_target);
-  return gl_target == GL_TEXTURE_RECTANGLE_ARB;
-}
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
-
 /**
  * meta_texture_tower_set_base_texture:
  * @tower: a #MetaTextureTower
@@ -354,13 +342,11 @@ get_paint_level (int width, int height)
     return (int)(0.5 + lambda);
 }
 
-#ifdef GL_TEXTURE_RECTANGLE_ARB
 static gboolean
 is_power_of_two (int x)
 {
   return (x & (x - 1)) == 0;
 }
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
 
 static void
 texture_tower_create_texture (MetaTextureTower *tower,
@@ -368,25 +354,23 @@ texture_tower_create_texture (MetaTextureTower *tower,
                               int               width,
                               int               height)
 {
-#ifdef GL_TEXTURE_RECTANGLE_ARB
   if ((!is_power_of_two (width) || !is_power_of_two (height)) &&
-      texture_is_rectangle (tower->textures[level - 1]))
+      meta_texture_rectangle_check (tower->textures[level - 1]))
     {
       tower->textures[level] =
         meta_texture_rectangle_new (width, height,
-                                    0, /* flags */
                                     /* data format */
                                     TEXTURE_FORMAT,
-                                    /* internal GL format */
-                                    GL_RGBA,
                                     /* internal cogl format */
                                     TEXTURE_FORMAT,
                                     /* rowstride */
                                     width * 4,
+                                    /* data */
+                                    NULL,
+                                    /* error */
                                     NULL);
     }
   else
-#endif /* GL_TEXTURE_RECTANGLE_ARB */
     {
       tower->textures[level] = cogl_texture_new_with_size (width, height,
                                                            COGL_TEXTURE_NO_AUTO_MIPMAP,
--
cgit v0.9.0.2