Merge lp:~bregma/compiz/lp-1101594 into lp:compiz/0.9.12
- lp-1101594
- Merge into 0.9.12
Status: | Merged |
---|---|
Approved by: | Christopher Townsend |
Approved revision: | 3936 |
Merged at revision: | 3949 |
Proposed branch: | lp:~bregma/compiz/lp-1101594 |
Merge into: | lp:compiz/0.9.12 |
Diff against target: |
536 lines (+204/-71) 3 files modified
plugins/opengl/include/opengl/texture.h (+127/-33) plugins/opengl/src/privatetexture.h (+22/-3) plugins/opengl/src/texture.cpp (+55/-35) |
To merge this branch: | bzr merge lp:~bregma/compiz/lp-1101594 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Christopher Townsend | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+254656@code.launchpad.net |
Commit message
OpenGL plugin: refine GLTexture API to adhere to class invariants
Description of the change
OpenGL plugin: refactor GLTexture to pass values in the constructor and maintain class invariants instead of using the C-with-classes default-
The uninitialized-
Also, scraped some API docs off compiz.org and added them in to the header while the patient was open on the table.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 3936. By Stephen M. Webb
-
fixed typo in EGL codepath
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3935
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3936
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Christopher Townsend (townsend) wrote : | # |
Ok, seems fine.
Christopher Townsend (townsend) wrote : | # |
Oh, do we need an ABI bump for this?
Christopher Townsend (townsend) wrote : | # |
Ok, all good:)
Preview Diff
1 | === modified file 'plugins/opengl/include/opengl/texture.h' |
2 | --- plugins/opengl/include/opengl/texture.h 2012-09-18 11:32:20 +0000 |
3 | +++ plugins/opengl/include/opengl/texture.h 2015-03-30 22:52:49 +0000 |
4 | @@ -1,6 +1,7 @@ |
5 | /* |
6 | * Copyright © 2008 Dennis Kasprzyk |
7 | * Copyright © 2007 Novell, Inc. |
8 | + * Copyright 2015 Canonical Ltd. |
9 | * |
10 | * Permission to use, copy, modify, distribute, and sell this software |
11 | * and its documentation for any purpose is hereby granted without |
12 | @@ -71,7 +72,44 @@ |
13 | class PrivateTexture; |
14 | |
15 | /** |
16 | - * Class which represents an openGL texture |
17 | + * An abstract representation of an OpenGL texture. |
18 | + * |
19 | + * Enabling and disabling the texture, and drawing it with OpenGL |
20 | + * -------------------------------------------------------------- |
21 | + * |
22 | + * Because there are different texture binding backends, it is not safe to |
23 | + * enable the texture target using OpenGL directly. Instead, you should use the |
24 | + * ::enable () and ::disable () member functions. The ::enable () member |
25 | + * function also allows you to specifiy a level of texture filtering, either |
26 | + * Fast or Good. If you are drawing the texture at a smaller size then the |
27 | + * render size, then it should be safe to use the Fast filter. |
28 | + * |
29 | + * Getting OpenGL information about the texture |
30 | + * -------------------------------------------- |
31 | + * |
32 | + * It is possible to get the ::name () and ::target () of the texture to use |
33 | + * that data for OpenGL purposes. |
34 | + * |
35 | + * Mipmapping |
36 | + * ---------- |
37 | + * |
38 | + * Compiz also supports a mipmapping filter to make textures appear smoother |
39 | + * when viewed at angles. To enable this you can use the ::setMipmap and |
40 | + * ::mipmap functions in order to enable this. Mipmapping is not available on |
41 | + * certain hardware. In this case, the function will simply fail silently. |
42 | + * |
43 | + * Overloading the binding of textures |
44 | + * ----------------------------------- |
45 | + * |
46 | + * For whatever reason, you may wish to write your own texture binding method |
47 | + * which overloads the standard GLX_ext_texture_from_pixmap method. It is |
48 | + * possible to do this by overloading the ::enable () and ::disable () methods |
49 | + * of the GLTexture through your own class. Then on your plugin's init function |
50 | + * you should use GLTexture::BindPixmapHandle hnd = GLScreen::get |
51 | + * (screen)->registerBindPixmap (YourPixmap::bindPixmapToTexture) and on fini |
52 | + * you must also call GLScreen::get (screen)->unregistrerBindPixmap (hnd). |
53 | + * |
54 | + * A sample implementation can be found in the Copy To Texture plugin. |
55 | */ |
56 | class GLTexture : public CompRect { |
57 | public: |
58 | @@ -81,6 +119,29 @@ |
59 | Good |
60 | } Filter; |
61 | |
62 | + /** |
63 | + * a texture matrix |
64 | + * |
65 | + * Texture Matrix manipulation |
66 | + * |
67 | + * Since all textures are 2D, it is possible to perform basic 2D |
68 | + * Manipulation operations on the texture. |
69 | + * |
70 | + * Member variable | Function |
71 | + * ----------------|---------- |
72 | + * .x0 | X Position on the screen |
73 | + * .y0 | Y Position on the screen |
74 | + * .xx | X Scale Factor |
75 | + * .yy | Y Scale Factor |
76 | + * .xy | X Shear Factor |
77 | + * .yx | Y Shear Factor |
78 | + * |
79 | + * The COMP_TEX_COORD functions return matrix-adjusted values for |
80 | + * texture positions. The "real" value of your co-ordinate on the |
81 | + * texture itself should be inputted into these functions, and these |
82 | + * functions will return the appropriate number to feed to functions |
83 | + * such as glTexCoord2f. |
84 | + */ |
85 | typedef struct { |
86 | float xx; float yx; |
87 | float xy; float yy; |
88 | @@ -90,8 +151,20 @@ |
89 | typedef std::vector<Matrix> MatrixList; |
90 | |
91 | /** |
92 | - * Class which represents a list of openGL textures, |
93 | - * usually used for texture tiling |
94 | + * a list of OpenGL textures, usually used for texture tiling |
95 | + * |
96 | + * In order to overcome hardware maximum texture size limitations, |
97 | + * Compiz supports tiled texturing. As such, all texture generation |
98 | + * functions (such as bindPixmapTotexture, imageDataToTexture, |
99 | + * readImageToTexture, etc) will all return a GLTexture:List. When |
100 | + * rendering these textures you must loop through each texture in the |
101 | + * list in order that you render each part of the texture that the user |
102 | + * sees. |
103 | + * |
104 | + * On especially small textures, it is ok to directly access the first |
105 | + * item in the list for the sake of optimization, however whenever it is |
106 | + * not clear what the size of the texture is, you should always loop the |
107 | + * list. |
108 | */ |
109 | class List : public std::vector <GLTexture *> { |
110 | |
111 | @@ -112,23 +185,23 @@ |
112 | public: |
113 | |
114 | /** |
115 | - * Returns the openGL texture name |
116 | + * Returns the OpenGL texture name. |
117 | */ |
118 | GLuint name () const; |
119 | |
120 | /** |
121 | - * Returns the openGL texture target |
122 | + * Returns the OpenGL texture target. |
123 | */ |
124 | GLenum target () const; |
125 | |
126 | /** |
127 | - * Returns the openGL texture filter |
128 | + * Returns the openGL texture filter. |
129 | */ |
130 | GLenum filter () const; |
131 | |
132 | /** |
133 | * Returns a 2D 2x3 matrix describing the transformation of |
134 | - * the texture |
135 | + * this texture. |
136 | */ |
137 | const Matrix & matrix () const; |
138 | |
139 | @@ -148,42 +221,41 @@ |
140 | virtual void disable (); |
141 | |
142 | /** |
143 | - * Returns true if this texture is MipMapped |
144 | + * Returns true if this texture is MipMapped. |
145 | */ |
146 | bool mipmap () const; |
147 | |
148 | /** |
149 | - * Sets if this texture should be MipMapped |
150 | + * Sets if this texture should be MipMapped. |
151 | */ |
152 | void setMipmap (bool); |
153 | |
154 | /** |
155 | - * Sets the openGL filter which should be used on this |
156 | - * texture |
157 | + * Sets the openGL filter which should be used on this texture. |
158 | */ |
159 | void setFilter (GLenum); |
160 | void setWrap (GLenum); |
161 | |
162 | /** |
163 | - * Increases the reference count of a texture |
164 | + * Increases the reference count of a texture. |
165 | */ |
166 | static void incRef (GLTexture *); |
167 | |
168 | /** |
169 | - * Decreases the reference count of a texture |
170 | + * Decreases the reference count of a texture. |
171 | */ |
172 | static void decRef (GLTexture *); |
173 | |
174 | /** |
175 | - * Returns a GLTexture::List with the contents of |
176 | - * some pixmap |
177 | + * Creates a collection of GLTextures from an X11 pixmap. |
178 | + * @param pixmap pixmap data which should be converted |
179 | + * into texture data |
180 | + * @param width width of the texture |
181 | + * @param height height of the texture |
182 | + * @param depth color depth of the texture |
183 | + * @param source whether the pixmap lifecycle is managed externally |
184 | * |
185 | - * @param pixmap Specifies the pixmap data which should be converted |
186 | - * into texture data |
187 | - * @param width Specifies the width of the texture |
188 | - * @param height Specifies the height of the texture |
189 | - * @param depth Specifies the color depth of the texture |
190 | - * @param source Whether the pixmap lifecycle is managed externall |
191 | + * @returns a GLTexture::List with the contents of the pixmap. |
192 | */ |
193 | static List bindPixmapToTexture (Pixmap pixmap, |
194 | int width, |
195 | @@ -193,16 +265,23 @@ |
196 | = compiz::opengl::InternallyManaged); |
197 | |
198 | /** |
199 | - * Returns a GLTexture::List with the contents of of |
200 | - * a raw image buffer |
201 | + * Creates a collection of GLTextures from a raw image buffer. |
202 | + * @param image a raw image buffer which should be converted |
203 | + * into texture data |
204 | + * @param size size of this new texture |
205 | * |
206 | - * @param image Specifies a raw image buffer which should be converted |
207 | - * into texture data |
208 | - * @param size Specifies the size of this new texture |
209 | + * @returns a GLTexture::List with the contents of of |
210 | + * a raw image buffer. |
211 | */ |
212 | - static List imageBufferToTexture (const char *image, |
213 | - CompSize size); |
214 | + static List imageBufferToTexture (const char *image, CompSize size); |
215 | |
216 | + /** |
217 | + * Creates a collection of GLTextures from raw pixel data. |
218 | + * @param image raw pixel data |
219 | + * @param size size of the raw pixel data |
220 | + * @param format GL format of the raw pixel data (eg. GL_RGBA) |
221 | + * @param type GL data type of the raw pixel data (eg. GL_FLOAT) |
222 | + */ |
223 | static List imageDataToTexture (const char *image, |
224 | CompSize size, |
225 | GLenum format, |
226 | @@ -212,10 +291,10 @@ |
227 | * Uses image loading plugins to read an image from the disk and |
228 | * return a GLTexture::List with its contents |
229 | * |
230 | - * @param imageFileName The filename of the image |
231 | - * @param pluginName The name of the plugin, used to find |
232 | - * the default image path |
233 | - * @param size The size of this new texture |
234 | + * @param imageFileName filename of the image |
235 | + * @param pluginName name of the plugin, used to find the default |
236 | + * image path |
237 | + * @param size size of this new texture |
238 | */ |
239 | static List readImageToTexture (CompString &imageFileName, |
240 | CompString &pluginName, |
241 | @@ -224,10 +303,25 @@ |
242 | friend class PrivateTexture; |
243 | |
244 | protected: |
245 | + /** |
246 | + * Consrtucts a defauly empty GLTexture. |
247 | + * |
248 | + * @deprecated This function is only for ABI backwards compatibility and |
249 | + * will be removed in the future. |
250 | + */ |
251 | GLTexture (); |
252 | + |
253 | + /** Constructs an OpenGL texture. */ |
254 | + GLTexture (int width, int height, GLenum target, Matrix const& m, bool mipmap); |
255 | virtual ~GLTexture (); |
256 | |
257 | - void setData (GLenum target, Matrix &m, bool mipmap); |
258 | + /** |
259 | + * Initializer. |
260 | + * |
261 | + * @deprecated This function is only for ABI backwards compatibility and |
262 | + * will be removed in the future. |
263 | + */ |
264 | + void setData (GLenum target, Matrix const& m, bool mipmap); |
265 | |
266 | private: |
267 | PrivateTexture *priv; |
268 | |
269 | === modified file 'plugins/opengl/src/privatetexture.h' |
270 | --- plugins/opengl/src/privatetexture.h 2012-09-18 11:32:20 +0000 |
271 | +++ plugins/opengl/src/privatetexture.h 2015-03-30 22:52:49 +0000 |
272 | @@ -2,6 +2,7 @@ |
273 | * Copyright © 2008 Dennis Kasprzyk |
274 | * Copyright © 2007 Novell, Inc. |
275 | * Copyright © 2011 Linaro Ltd. |
276 | + * Copyright 2015 Canonical Ltd. |
277 | * |
278 | * Permission to use, copy, modify, distribute, and sell this software |
279 | * and its documentation for any purpose is hereby granted without |
280 | @@ -49,7 +50,10 @@ |
281 | |
282 | class PrivateTexture { |
283 | public: |
284 | - PrivateTexture (GLTexture *); |
285 | + PrivateTexture (GLTexture* texture, |
286 | + GLenum target, |
287 | + GLTexture::Matrix const& matrix, |
288 | + bool mipmap); |
289 | ~PrivateTexture (); |
290 | |
291 | static GLTexture::List loadImageData (const char *image, |
292 | @@ -74,7 +78,6 @@ |
293 | #ifdef USE_GLES |
294 | class EglTexture : public GLTexture { |
295 | public: |
296 | - EglTexture (); |
297 | ~EglTexture (); |
298 | |
299 | void enable (Filter filter); |
300 | @@ -85,6 +88,13 @@ |
301 | int depth, |
302 | compiz::opengl::PixmapSource source); |
303 | |
304 | + private: |
305 | + EglTexture (GLenum target, |
306 | + GLTexture::Matrix const& matrix, |
307 | + bool mipmap, |
308 | + int width, |
309 | + int height); |
310 | + |
311 | public: |
312 | bool damaged; |
313 | Damage damage; |
314 | @@ -96,7 +106,6 @@ |
315 | |
316 | class TfpTexture : public GLTexture { |
317 | public: |
318 | - TfpTexture (); |
319 | ~TfpTexture (); |
320 | |
321 | void enable (Filter filter); |
322 | @@ -109,6 +118,16 @@ |
323 | int depth, |
324 | compiz::opengl::PixmapSource source); |
325 | |
326 | + private: |
327 | + TfpTexture (GLenum target, |
328 | + GLTexture::Matrix const& matrix, |
329 | + bool mipmap, |
330 | + Pixmap pixmap, |
331 | + int width, |
332 | + int height, |
333 | + Pixmap x11Pixmap, |
334 | + compiz::opengl::PixmapSource source); |
335 | + |
336 | public: |
337 | Pixmap x11Pixmap; |
338 | GLXPixmap pixmap; |
339 | |
340 | === modified file 'plugins/opengl/src/texture.cpp' |
341 | --- plugins/opengl/src/texture.cpp 2014-03-03 16:20:06 +0000 |
342 | +++ plugins/opengl/src/texture.cpp 2015-03-30 22:52:49 +0000 |
343 | @@ -1,5 +1,6 @@ |
344 | /* |
345 | * Copyright © 2005 Novell, Inc. |
346 | + * Copyright 2015 Canonical Ltd. |
347 | * |
348 | * Permission to use, copy, modify, distribute, and sell this software |
349 | * and its documentation for any purpose is hereby granted without |
350 | @@ -48,7 +49,7 @@ |
351 | std::map<Damage, TfpTexture*> boundPixmapTex; |
352 | #endif |
353 | |
354 | -static GLTexture::Matrix _identity_matrix = { |
355 | +static const GLTexture::Matrix _identity_matrix = { |
356 | 1.0f, 0.0f, |
357 | 0.0f, 1.0f, |
358 | 0.0f, 0.0f |
359 | @@ -107,7 +108,13 @@ |
360 | |
361 | GLTexture::GLTexture () : |
362 | CompRect (0, 0, 0, 0), |
363 | - priv (new PrivateTexture (this)) |
364 | + priv (new PrivateTexture (this, GL_TEXTURE_2D, _identity_matrix, true)) |
365 | +{ |
366 | +} |
367 | + |
368 | +GLTexture::GLTexture (int width, int height, GLenum target, Matrix const& matrix, bool mipmap) : |
369 | + CompRect (0, 0, width, height), |
370 | + priv (new PrivateTexture (this, target, matrix, mipmap)) |
371 | { |
372 | } |
373 | |
374 | @@ -117,14 +124,17 @@ |
375 | delete priv; |
376 | } |
377 | |
378 | -PrivateTexture::PrivateTexture (GLTexture *texture) : |
379 | +PrivateTexture::PrivateTexture (GLTexture* texture, |
380 | + GLenum target, |
381 | + GLTexture::Matrix const& matrix, |
382 | + bool mipmap) : |
383 | texture (texture), |
384 | name (0), |
385 | - target (GL_TEXTURE_2D), |
386 | + target (target), |
387 | filter (GL_NEAREST), |
388 | wrap (GL_CLAMP_TO_EDGE), |
389 | - matrix (_identity_matrix), |
390 | - mipmap (true), |
391 | + matrix (matrix), |
392 | + mipmap (mipmap), |
393 | mipmapSupport (false), |
394 | initial (true), |
395 | refCount (1) |
396 | @@ -255,7 +265,7 @@ |
397 | } |
398 | |
399 | void |
400 | -GLTexture::setData (GLenum target, Matrix &m, bool mipmap) |
401 | +GLTexture::setData (GLenum target, Matrix const& m, bool mipmap) |
402 | { |
403 | priv->target = target; |
404 | priv->matrix = m; |
405 | @@ -306,9 +316,6 @@ |
406 | return GLTexture::List (); |
407 | |
408 | GLTexture::List rv (1); |
409 | - GLTexture *t = new GLTexture (); |
410 | - rv[0] = t; |
411 | - |
412 | GLTexture::Matrix matrix = _identity_matrix; |
413 | GLint internalFormat; |
414 | GLenum target; |
415 | @@ -341,10 +348,11 @@ |
416 | } |
417 | #endif |
418 | |
419 | - t->setData (target, matrix, mipmap); |
420 | - t->setGeometry (0, 0, width, height); |
421 | + GLTexture* t = new GLTexture (width, height, target, matrix, mipmap); |
422 | t->setFilter (GL_NEAREST); |
423 | t->setWrap (GL_CLAMP_TO_EDGE); |
424 | + rv[0] = t; |
425 | + |
426 | |
427 | #ifdef USE_GLES |
428 | // For GLES2 no format conversion is allowed, i.e., format must equal internalFormat |
429 | @@ -468,7 +476,12 @@ |
430 | } |
431 | |
432 | #ifdef USE_GLES |
433 | -EglTexture::EglTexture () : |
434 | +EglTexture::EglTexture (GLenum target, |
435 | + GLTexture::Matrix const& matrix, |
436 | + bool mipmap, |
437 | + int width, |
438 | + int height) : |
439 | + GLTexture (width, height, target, matrix, mipmap), |
440 | damaged (true), |
441 | damage (None), |
442 | updateMipMap (true) |
443 | @@ -489,16 +502,19 @@ |
444 | } |
445 | |
446 | GLTexture::List |
447 | -EglTexture::bindPixmapToTexture (Pixmap pixmap, |
448 | - int width, |
449 | - int height, |
450 | - int depth, |
451 | - compiz::opengl::PixmapSource source) |
452 | +EglTexture::bindPixmapToTexture (Pixmap pixmap, |
453 | + int width, |
454 | + int height, |
455 | + int depth, |
456 | + cgl::PixmapSource source) |
457 | { |
458 | GLTexture::List rv (1); |
459 | EglTexture *tex = NULL; |
460 | EGLImageKHR eglImage = NULL; |
461 | + GLenum texTarget = GL_TEXTURE_2D; |
462 | GLTexture::Matrix matrix = _identity_matrix; |
463 | + bool mipmap = GL::textureNonPowerOfTwoMipmap || |
464 | + (POWER_OF_TWO (width) && POWER_OF_TWO (height)); |
465 | |
466 | const EGLint img_attribs[] = { |
467 | EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
468 | @@ -521,23 +537,19 @@ |
469 | matrix.yy = 1.0f / height; |
470 | matrix.y0 = 0.0f; |
471 | |
472 | - tex = new EglTexture (); |
473 | - tex->setData (GL_TEXTURE_2D, matrix, |
474 | - GL::textureNonPowerOfTwoMipmap || |
475 | - (POWER_OF_TWO (width) && POWER_OF_TWO (height))); |
476 | - tex->setGeometry (0, 0, width, height); |
477 | + tex = new EglTexture (texTarget, matrix, mipmap, width, height); |
478 | |
479 | rv[0] = tex; |
480 | |
481 | - glBindTexture (GL_TEXTURE_2D, tex->name ()); |
482 | + glBindTexture (texTarget, tex->name ()); |
483 | |
484 | - GL::eglImageTargetTexture (GL_TEXTURE_2D, (GLeglImageOES)eglImage); |
485 | + GL::eglImageTargetTexture (texTarget, (GLeglImageOES)eglImage); |
486 | GL::destroyImage (eglGetDisplay (screen->dpy ()), eglImage); |
487 | |
488 | tex->setFilter (GL_NEAREST); |
489 | tex->setWrap (GL_CLAMP_TO_EDGE); |
490 | |
491 | - glBindTexture (GL_TEXTURE_2D, 0); |
492 | + glBindTexture (texTarget, 0); |
493 | |
494 | tex->damage = XDamageCreate (screen->dpy (), pixmap, |
495 | XDamageReportBoundingBox); |
496 | @@ -609,11 +621,21 @@ |
497 | } |
498 | } |
499 | |
500 | -TfpTexture::TfpTexture () : |
501 | - pixmap (0), |
502 | +TfpTexture::TfpTexture (GLenum target, |
503 | + GLTexture::Matrix const& matrix, |
504 | + bool mipmap, |
505 | + Pixmap pixmap, |
506 | + int width, |
507 | + int height, |
508 | + Pixmap x11Pixmap, |
509 | + cgl::PixmapSource source) : |
510 | + GLTexture (width, height, target, matrix, mipmap), |
511 | + x11Pixmap (x11Pixmap), |
512 | + pixmap (pixmap), |
513 | damaged (true), |
514 | damage (None), |
515 | - updateMipMap (true) |
516 | + updateMipMap (true), |
517 | + source (source) |
518 | { |
519 | } |
520 | |
521 | @@ -791,12 +813,10 @@ |
522 | return GLTexture::List (); |
523 | } |
524 | |
525 | - tex = new TfpTexture (); |
526 | - tex->setData (texTarget, matrix, mipmap); |
527 | - tex->setGeometry (0, 0, width, height); |
528 | - tex->pixmap = glxPixmap; |
529 | - tex->x11Pixmap = pixmap; |
530 | - tex->source = source; |
531 | + tex = new TfpTexture (texTarget, matrix, mipmap, |
532 | + glxPixmap, |
533 | + width, height, |
534 | + pixmap, source); |
535 | |
536 | rv[0] = tex; |
537 |
FAILED: Continuous integration, rev:3935 jenkins. qa.ubuntu. com/job/ compiz- ci/41/ jenkins. qa.ubuntu. com/job/ compiz- vivid-amd64- ci/31 jenkins. qa.ubuntu. com/job/ compiz- vivid-armhf- ci/31/console jenkins. qa.ubuntu. com/job/ compiz- vivid-i386- ci/31
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/compiz- ci/41/rebuild
http://