summaryrefslogtreecommitdiff
path: root/beryl-plugins/src/blurfx.h
diff options
context:
space:
mode:
authorquinn <quinn@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-09-27 23:19:52 +0000
committerquinn <quinn@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-09-27 23:19:52 +0000
commit4c9796dddab60529fff57638d3cb0d8ca830a3fe (patch)
tree1c54f385f71dc9897381c7b266ff1090137a74e1 /beryl-plugins/src/blurfx.h
parent6e36e85e06f7cf5edc75016bc2bb2612c0ee80c1 (diff)
downloadmarex-dev-4c9796dddab60529fff57638d3cb0d8ca830a3fe.tar.gz
marex-dev-4c9796dddab60529fff57638d3cb0d8ca830a3fe.tar.bz2
move in beryl-plugins
git-svn-id: file:///beryl/trunk@325 d7aaf104-2d23-0410-ae22-9d23157bf5a3
Diffstat (limited to 'beryl-plugins/src/blurfx.h')
-rw-r--r--beryl-plugins/src/blurfx.h378
1 files changed, 378 insertions, 0 deletions
diff --git a/beryl-plugins/src/blurfx.h b/beryl-plugins/src/blurfx.h
new file mode 100644
index 0000000..bf66d9f
--- /dev/null
+++ b/beryl-plugins/src/blurfx.h
@@ -0,0 +1,378 @@
+/**
+ *
+ * Beryl blur and reflection effect plugin
+ *
+ * blurfx.h
+ *
+ * Copyright : (C) 2006 by Dennis Kasprzyk
+ * E-mail : dennis.kasprzyk@rwth-aachen.de
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ **/
+
+#ifndef BLURFX_H_
+#define BLURFX_H_
+
+#include "blurfx_shader.h"
+
+#define GET_BLURFX_DISPLAY(d) \
+ ((BlurfxDisplay *) (d)->privates[displayPrivateIndex].ptr)
+
+#define BLURFX_DISPLAY(d) \
+ BlurfxDisplay *bd = GET_BLURFX_DISPLAY (d)
+
+#define GET_BLURFX_SCREEN(s, bd) \
+ ((BlurfxScreen *) (s)->privates[(bd)->screenPrivateIndex].ptr)
+
+#define BLURFX_SCREEN(s) \
+ BlurfxScreen *bs = GET_BLURFX_SCREEN (s, GET_BLURFX_DISPLAY (s->display))
+
+#define GET_BLURFX_WINDOW(w, bs) \
+ ((BlurfxWindow *) (w)->privates[(bs)->windowPrivateIndex].ptr)
+
+#define BLURFX_WINDOW_PTR(w) \
+ GET_BLURFX_WINDOW (w, \
+ GET_BLURFX_SCREEN (w->screen, \
+ GET_BLURFX_DISPLAY (w->screen->display)))
+
+#define BLURFX_WINDOW(w) \
+ BlurfxWindow *bw = BLURFX_WINDOW_PTR(w)
+
+
+#define WIN_X(w) ((w)->attrib.x - (w)->output.left)
+#define WIN_Y(w) ((w)->attrib.y - (w)->output.top)
+#define WIN_W(w) ((w)->width + (w)->output.left + (w)->output.right)
+#define WIN_H(w) ((w)->height + (w)->output.top + (w)->output.bottom)
+#define WIN_XO(w) ((w)->attrib.x - (w)->input.left)
+#define WIN_YO(w) ((w)->attrib.y - (w)->input.top)
+#define WIN_WO(w) ((w)->width + (w)->input.left + (w)->input.right)
+#define WIN_HO(w) ((w)->height + (w)->input.top + (w)->input.bottom)
+
+#define WINDOW_INPUT_INVISIBLE(w) \
+ ((w)->attrib.map_state != IsViewable || \
+ (!(w)->damaged) || \
+ (w)->attrib.x + (w)->width + (w)->input.right <= 0 || \
+ (w)->attrib.y + (w)->height + (w)->input.bottom <= 0 || \
+ (w)->attrib.x - (w)->input.left >= (w)->screen->width || \
+ (w)->attrib.y - (w)->input.top >= (w)->screen->height)
+
+
+#define BFX_ADD_RECT(data, m, x1, y1, x2, y2) \
+ *(data)++ = COMP_TEX_COORD_X (&m, x1); \
+*(data)++ = COMP_TEX_COORD_Y (&m, y2); \
+*(data)++ = (x1); \
+*(data)++ = (y2); \
+*(data)++ = COMP_TEX_COORD_X (&m, x2); \
+*(data)++ = COMP_TEX_COORD_Y (&m, y2); \
+*(data)++ = (x2); \
+*(data)++ = (y2); \
+*(data)++ = COMP_TEX_COORD_X (&m, x2); \
+*(data)++ = COMP_TEX_COORD_Y (&m, y1); \
+*(data)++ = (x2); \
+*(data)++ = (y1); \
+*(data)++ = COMP_TEX_COORD_X (&m, x1); \
+*(data)++ = COMP_TEX_COORD_Y (&m, y1); \
+*(data)++ = (x1); \
+*(data)++ = (y1)
+
+#define MULTM(x,y,z) \
+ z[0] = x[0] * y[0] + x[4] * y[1] + x[8] * y[2] + x[12] * y[3]; \
+z[1] = x[1] * y[0] + x[5] * y[1] + x[9] * y[2] + x[13] * y[3]; \
+z[2] = x[2] * y[0] + x[6] * y[1] + x[10] * y[2] + x[14] * y[3]; \
+z[3] = x[3] * y[0] + x[7] * y[1] + x[11] * y[2] + x[15] * y[3]; \
+z[4] = x[0] * y[4] + x[4] * y[5] + x[8] * y[6] + x[12] * y[7]; \
+z[5] = x[1] * y[4] + x[5] * y[5] + x[9] * y[6] + x[13] * y[7]; \
+z[6] = x[2] * y[4] + x[6] * y[5] + x[10] * y[6] + x[14] * y[7]; \
+z[7] = x[3] * y[4] + x[7] * y[5] + x[11] * y[6] + x[15] * y[7]; \
+z[8] = x[0] * y[8] + x[4] * y[9] + x[8] * y[10] + x[12] * y[11]; \
+z[9] = x[1] * y[8] + x[5] * y[9] + x[9] * y[10] + x[13] * y[11]; \
+z[10] = x[2] * y[8] + x[6] * y[9] + x[10] * y[10] + x[14] * y[11]; \
+z[11] = x[3] * y[8] + x[7] * y[9] + x[11] * y[10] + x[15] * y[11]; \
+z[12] = x[0] * y[12] + x[4] * y[13] + x[8] * y[14] + x[12] * y[15]; \
+z[13] = x[1] * y[12] + x[5] * y[13] + x[9] * y[14] + x[13] * y[15]; \
+z[14] = x[2] * y[12] + x[6] * y[13] + x[10] * y[14] + x[14] * y[15]; \
+z[15] = x[3] * y[12] + x[7] * y[13] + x[11] * y[14] + x[15] * y[15];
+
+#ifdef GL_DEBUG
+static GLenum gl_error;
+#define GLERR gl_error=glGetError(); if (gl_error != GL_NO_ERROR) { fprintf (stderr,"GL error 0x%X has occured at %s:%d\n",gl_error,__FILE__,__LINE__); }
+#else
+#define GLERR
+#endif
+
+#define BLURFX_DISPLAY_OPTION_MOTION_BLUR_TOGGLE 0
+#define BLURFX_DISPLAY_OPTION_NUM 1
+
+#define BLURFX_DISPLAY_OPTION_MOTION_BLUR_TOGGLE_KEY_DEFAULT "F12"
+#define BLURFX_DISPLAY_OPTION_MOTION_BLUR_TOGGLE_MOD_DEFAULT ControlMask
+
+#define BLURFX_SCREEN_OPTION_BLUR_WINDOWS 0
+#define BLURFX_SCREEN_OPTION_BLUR_DECORATION 1
+#define BLURFX_SCREEN_OPTION_REFLECTION_WINDOWS 2
+#define BLURFX_SCREEN_OPTION_REFLECTION_DECORATION 3
+#define BLURFX_SCREEN_OPTION_BLUR_ON_TRANSFORMED_SCREEN 4
+#define BLURFX_SCREEN_OPTION_BLUR_TRANSFORMED_WINDOW 5
+#define BLURFX_SCREEN_OPTION_BLUR_SHADER 6
+#define BLURFX_SCREEN_OPTION_FORCE_NON_FBO_BLUR 7
+#define BLURFX_SCREEN_OPTION_NON_FBO_BLUR_STRENGTH 8
+#define BLURFX_SCREEN_OPTION_DISABLE_BLUR_ON_SCREENGRAB_OF 9
+#define BLURFX_SCREEN_OPTION_REFLECTION_ON_TRANSFORMED_SCREEN 10
+#define BLURFX_SCREEN_OPTION_REFLECTION_TRANSFORMED_WINDOW 11
+#define BLURFX_SCREEN_OPTION_DISABLE_REFLECTION_ON_SCREENGRAB_OF 12
+#define BLURFX_SCREEN_OPTION_REFLECTION_FILE 13
+#define BLURFX_SCREEN_OPTION_REFLECTION_SCALE 14
+#define BLURFX_SCREEN_OPTION_REFLECTION_PROPORTIONAL 15
+#define BLURFX_SCREEN_OPTION_REFLECTION_USE_IMAGE_COLOR 16
+#define BLURFX_SCREEN_OPTION_REFLECTION_USE_IMAGE_ALPHA 17
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_MODE 18
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_ON_SCREENGRAB_OF 19
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_STRENGTH 20
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_ON_TRANSFORMED_SCREEN 21
+#define BLURFX_SCREEN_OPTION_BLUR_CACHE_TEXTURES 22
+#define BLURFX_SCREEN_OPTION_DISABLE_DECORATION_ALPHADEP 23
+#define BLURFX_SCREEN_OPTION_DISABLE_BLUR_WINDOW_TYPE 24
+#define BLURFX_SCREEN_OPTION_DISABLE_REFLECTION_WINDOW_TYPE 25
+#define BLURFX_SCREEN_OPTION_BLUR_SATURATION 26
+
+#define BLURFX_SCREEN_OPTION_NUM 27
+
+#define BLURFX_SCREEN_OPTION_BLUR_WINDOWS_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_BLUR_DECORATION_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_REFLECTION_WINDOWS_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_REFLECTION_DECORATION_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_BLUR_SHADER_DEFAULT "gaussian 5x5"
+#define BLURFX_SCREEN_OPTION_BLUR_ON_TRANSFORMED_SCREEN_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_BLUR_TRANSFORMED_WINDOW_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_REFLECTION_ON_TRANSFORMED_SCREEN_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_REFLECTION_TRANSFORMED_WINDOW_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_REFLECTION_FILE_DEFAULT ""
+#define BLURFX_SCREEN_OPTION_REFLECTION_SCALE_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_REFLECTION_PROPORTIONAL_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_REFLECTION_USE_IMAGE_COLOR_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_REFLECTION_USE_IMAGE_ALPHA_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_MODE_DEFAULT "simple"
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_STRENGTH_DEFAULT 20.0
+#define BLURFX_SCREEN_OPTION_MOTION_BLUR_ON_TRANSFORMED_SCREEN_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_BLUR_CACHE_TEXTURES_DEFAULT TRUE
+#define BLURFX_SCREEN_OPTION_FORCE_NON_FBO_BLUR_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_NON_FBO_BLUR_STRENGTH_DEFAULT 4
+#define BLURFX_SCREEN_OPTION_DISABLE_DECORATION_ALPHADEP_DEFAULT FALSE
+#define BLURFX_SCREEN_OPTION_BLUR_SATURATION_DEFAULT 100.0
+
+
+#define MODE_NORMAL 0
+#define MODE_OCCLUSION 1
+#define MODE_BLURREFLECTION 2
+
+static char *blurDisable[] = { "switcher" };
+static char *mBlurModes[] = { "simple", "accum", "fbo" };
+static char *blurShaderNames[] = { "gaussian 5x5", "linear 5x5", "gaussian 9x9", "linear 9x9", "gaussian 13x13", "linear 13x13",
+ "gaussian 17x17", "linear 17x17", "gaussian 21x21", "linear 21x21"};
+static const char *blurShader[10][2];
+
+#define LIST_SIZE(l) (sizeof (l) / sizeof (l[0]))
+
+#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
+
+static int displayPrivateIndex = 0;
+
+typedef struct _BlurfxDisplay
+{
+ int screenPrivateIndex;
+ CompOption opt[BLURFX_DISPLAY_OPTION_NUM];
+}BlurfxDisplay;
+
+// our vertex array container
+typedef struct _BlurfxVertArray
+{
+ GLfloat* vertices;
+ GLushort* indices;
+ int vCount;
+ int indexCount;
+ int vertexSize;
+ int indexSize;
+
+}BlurfxVertArray;
+
+// our texture container
+typedef struct _BlurTexture
+{
+ int x;
+ int y;
+ int width;
+ int height;
+ unsigned int handle;
+ GLenum active_filter;
+ unsigned int target;
+
+}BlurTexture;
+
+typedef struct _BlurfxScreen
+{
+ int hasInit; // set to one once initiliazed
+ BlurTexture backTex; // texture which contains the background
+ BlurTexture motionTex; // texture that stores the motion blurred screen
+ BlurTexture blurTempTexV; // temporary texture for blur effect
+ BlurTexture blurTempTexH; // temporary texture for blur effect
+ BlurTexture modTex; // reflection effect texture
+ BlurfxVertArray vertArray; // temporary vertex array
+
+ unsigned int mode; // actual drawing mode
+
+ unsigned int fbo; // framebuffer object for render to texture operations
+ unsigned int fboStatus;
+ Bool fboActive;
+
+ unsigned int blurShaderV; // fragment program handle
+ unsigned int blurShaderH; // fragment program handle
+
+ // functions that we will intercept
+ PreparePaintScreenProc preparePaintScreen;
+ PaintScreenProc paintScreen;
+ PaintTransformedScreenProc paintTransformedScreen;
+ DrawWindowTextureProc drawWindowTexture;
+ PaintWindowProc paintWindow;
+ DamageWindowRectProc damageWindowRect;
+ AddWindowGeometryProc addWindowGeometry;
+
+ int windowPrivateIndex;
+
+ Region screenDamage; // region to calculate damage
+ Region realPaintRegion; // actual paint region
+
+ Region blurredRegion; // already blurred region
+
+ Region occlusion; // region to caclulate occlusion
+ Bool od_active;
+
+ Bool paintingSwitcher;
+
+ Bool motion_blur_active;
+ unsigned int mb_mode; // motion blur mode
+ Bool mb_update; // is an update of the motion blut texture needed
+ float mb_alpha; // motion blur blending value
+ float mb_timer; // motion blur fadeout time
+ Bool mb_activated;
+
+ float downSample; // down sample rate for non FBO mode
+
+ unsigned int noBlurWMask; // window types we disable blur
+ unsigned int noReflectionWMask; // window types we disable reflection
+
+ float pm[16]; // here we store the projection matrix
+
+ int blur_shader;
+
+ // hardware support flags
+ Bool blur_supported;
+ Bool fboBlur_supported;
+ Bool mblur_supported;
+ Bool reflection_supported;
+
+ CompOption opt[BLURFX_SCREEN_OPTION_NUM]; // options
+
+}BlurfxScreen;
+
+typedef struct _BlurfxWindow
+{
+ // last position and scale
+ int lastX;
+ int lastY;
+ float lastXScale;
+ float lastYScale;
+
+ Region clip; // occluted region
+ Region paintRegion; // actual paint region
+ Region texDamage; // blur cache texture damage
+ Region damageRegion; // window damage
+ BlurTexture blurTex; // blur cache texture
+ Region bTexRegion; // blur cache texture damage
+ Bool hasTexture; // is blur cache texture initialized?
+ BlurfxVertArray vertArray; // temprary vertex array
+ BlurfxVertArray decoArray; // decoration without shadow array
+ CompWindow *my_next; // next window
+ Bool texUpdated; // is blur cache texture up to date
+
+ Bool isSwitcher; // is this the switcher window
+
+ float mvm[16]; // here we store the model view matrix
+ Bool mvm_updated; // is the model view matrix up to date
+
+}BlurfxWindow;
+
+
+static Bool blurfxInit (CompPlugin *p);
+static void blurfxFini (CompPlugin *p);
+static Bool blurfxInitDisplay (CompPlugin *p, CompDisplay *d);
+static void blurfxFiniDisplay (CompPlugin *p, CompDisplay *d);
+static Bool blurfxInitScreen (CompPlugin *p, CompScreen *s);
+static void blurfxFiniScreen (CompPlugin *p, CompScreen *s);
+static Bool blurfxInitWindow (CompPlugin *p, CompWindow *w);
+static void blurfxFiniWindow (CompPlugin *p, CompWindow *w);
+static CompOption* blurfxGetDisplayOptions (CompDisplay *display, int *count);
+static Bool blurfxSetDisplayOption (CompDisplay *display, char *name, CompOptionValue *value);
+static void blurfxDisplayInitOptions (BlurfxDisplay *bd,Display *display);
+static Bool blurfxSetScreenOption (CompScreen *s, char *name, CompOptionValue *value);
+static CompOption* blurfxGetScreenOptions (CompScreen *s, int *count);
+static void blurfxScreenInitOptions (BlurfxScreen *bs, Display *display);
+static void blurfxPreparePaintScreen (CompScreen *s, int ms);
+static Bool blurfxPaintScreen(CompScreen *s, const ScreenPaintAttrib *sa, Region region, unsigned int mask);
+static void blurfxPaintTransformedScreen(CompScreen *s, const ScreenPaintAttrib *sa, unsigned int mask);
+static Bool blurfxPaintWindow (CompWindow *w, const WindowPaintAttrib *attrib, Region region, unsigned int mask);
+static void blurfxDrawWindowTexture(CompWindow *w,CompTexture *texture, const WindowPaintAttrib *attrib, unsigned int mask);
+static void blurfxAddWindowGeometry (CompWindow *w, CompMatrix *m, int nM, Region region, Region clip);
+static Bool blurfxDamageWindowRect (CompWindow *w, Bool initial, BoxPtr box);
+static void updateBlur(CompWindow *w, CompScreen *s, const WindowPaintAttrib *attrib, unsigned int mask, CompTextureFilter filter);
+static void updateBlurTexture(CompWindow *w, CompScreen *s, const WindowPaintAttrib *attrib, unsigned int mask, CompTextureFilter filter);
+static void updateBlurTextureSize(CompWindow *w, CompScreen *s, const WindowPaintAttrib *attrib, unsigned int mask);
+static void updateBlurNoFBO(CompWindow *w, CompScreen *s, const WindowPaintAttrib *attrib, unsigned int mask);
+static void updateBlurTextureNoFBO(CompWindow *w, CompScreen *s, const WindowPaintAttrib *attrib, unsigned int mask);
+static void drawBlur(CompWindow *w, CompScreen *s, CompTexture *texture, const WindowPaintAttrib *attrib, int mask, CompTextureFilter filter);
+static void drawReflection(CompWindow *w, CompScreen *s, CompTexture *texture, const WindowPaintAttrib *attrib, int mask, CompTextureFilter filter);
+static void drawBlur(CompWindow *w, CompScreen *s, CompTexture *texture, const WindowPaintAttrib *attrib, int mask, CompTextureFilter filter);
+static Bool blurfxToggleMotionBlur (CompDisplay *d, CompAction *ac, CompActionState state, CompOption *option, int nOption);
+static Bool bindFbo(CompScreen *s, BlurTexture tex);
+static void unbindFbo(CompScreen *s);
+static void genGeometry (BlurfxVertArray *vA, CompMatrix matrix, int xextend,Region region);
+static Bool moreVertices (BlurfxVertArray *vA, int newSize);
+static void initBlurfxScreen(BlurfxScreen* bs,int Screenwidth,int Screenheight,CompScreen* s);
+static void genBlurTexture(BlurfxScreen *bs,BlurTexture *tex,int width,int height,int type);
+static void loadShader(GLenum type,CompScreen* s, GLuint * shader, const char * prog);
+static void loadPngToTexture2D(BlurfxScreen* bs,BlurTexture * tex, char* filename);
+static void enableBlurfxTexture(BlurTexture* tex, CompTextureFilter filter);
+static void switchBlurfxTexture(BlurTexture* from, BlurTexture* to, CompTextureFilter filter);
+static void disableBlurfxTexture(BlurTexture* tex);
+static Bool screenGrabExist(CompScreen *s,const char* name);
+
+CompPluginVTable blurfxVTable = {
+ "blurfx",
+ N_("Blur effects"),
+ N_("Blur and reflection effects"),
+ blurfxInit,
+ blurfxFini,
+ blurfxInitDisplay,
+ blurfxFiniDisplay,
+ blurfxInitScreen,
+ blurfxFiniScreen,
+ blurfxInitWindow,
+ blurfxFiniWindow,
+ blurfxGetDisplayOptions,
+ blurfxSetDisplayOption,
+ blurfxGetScreenOptions,
+ blurfxSetScreenOption,
+ 0,
+ 0,
+ BERYL_ABI_INFO
+};
+
+#endif