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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
diff -Narup a/src/shell-blur-effect.c b/src/shell-blur-effect.c
--- a/src/shell-blur-effect.c 2021-11-06 14:09:18.864228559 +0800
+++ b/src/shell-blur-effect.c 2021-11-06 14:09:18.864228559 +0800
@@ -22,6 +22,9 @@
#include "shell-enum-types.h"
+#include "meta/prefs.h"
+#include "shader.h"
+
/**
* SECTION:shell-blur-effect
* @short_description: Blur effect for actors
@@ -40,12 +43,6 @@
* of using this blur mode.
*/
-static const gchar *brightness_glsl_declarations =
-"uniform float brightness; \n";
-
-static const gchar *brightness_glsl =
-" cogl_color_out.rgb *= brightness; \n";
-
#define MIN_DOWNSCALE_SIZE 256.f
#define MAX_SIGMA 6.f
@@ -62,7 +59,7 @@ typedef struct
CoglTexture *texture;
} FramebufferData;
-struct _ShellBlurEffect
+struct _MetaShellBlurEffect
{
ClutterEffect parent_instance;
@@ -78,6 +75,12 @@ struct _ShellBlurEffect
FramebufferData background_fb;
FramebufferData brightness_fb;
int brightness_uniform;
+ int bounds_uniform;
+ int corner_centers_1_uniform;
+ int corner_centers_2_uniform;
+ int pixel_step_uniform;
+ int skip_uniform;
+ gboolean skip;
ShellBlurMode mode;
float downscale_factor;
@@ -85,7 +88,7 @@ struct _ShellBlurEffect
int sigma;
};
-G_DEFINE_TYPE (ShellBlurEffect, shell_blur_effect, CLUTTER_TYPE_EFFECT)
+G_DEFINE_TYPE (MetaShellBlurEffect, meta_shell_blur_effect, CLUTTER_TYPE_EFFECT)
enum {
PROP_0,
@@ -133,8 +136,8 @@ create_brightness_pipeline (void)
brightness_pipeline = create_base_pipeline ();
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
- brightness_glsl_declarations,
- brightness_glsl);
+ ROUNDED_CLIP_FRAGMENT_SHADER_DECLARATIONS_BLUR,
+ ROUNDED_CLIP_FRAGMENT_SHADER_CODE_BLUR);
cogl_pipeline_add_snippet (brightness_pipeline, snippet);
cogl_object_unref (snippet);
}
@@ -144,7 +147,7 @@ create_brightness_pipeline (void)
static void
-update_brightness (ShellBlurEffect *self,
+update_brightness (MetaShellBlurEffect *self,
uint8_t paint_opacity)
{
cogl_pipeline_set_color4ub (self->brightness_fb.pipeline,
@@ -155,9 +158,44 @@ update_brightness (ShellBlurEffect *self
if (self->brightness_uniform > -1)
{
+ cogl_pipeline_set_uniform_1i (self->brightness_fb.pipeline,
+ self->skip_uniform, self->skip);
cogl_pipeline_set_uniform_1f (self->brightness_fb.pipeline,
self->brightness_uniform,
self->brightness);
+ if (self->skip)
+ return;
+
+ float width = self->tex_width;
+ float height = self->tex_height;
+ float radius = meta_prefs_get_round_corner_radius();
+ float bounds[] = { 0.0, 0.0, width, height };
+ float corner_centers_1[] = {
+ radius,
+ radius,
+ width - radius,
+ radius
+ };
+ float corner_centers_2[] = {
+ width - radius,
+ height - radius,
+ radius,
+ height - radius
+ };
+ float pixel_step[] = { 1.0 / width, 1.0 / height };
+
+ cogl_pipeline_set_uniform_float (self->brightness_fb.pipeline,
+ self->bounds_uniform,
+ 4, 1, bounds);
+ cogl_pipeline_set_uniform_float (self->brightness_fb.pipeline,
+ self->corner_centers_1_uniform,
+ 4, 1, corner_centers_1);
+ cogl_pipeline_set_uniform_float (self->brightness_fb.pipeline,
+ self->corner_centers_2_uniform,
+ 4, 1, corner_centers_2);
+ cogl_pipeline_set_uniform_float (self->brightness_fb.pipeline,
+ self->pixel_step_uniform,
+ 2, 1, pixel_step);
}
}
@@ -212,7 +250,7 @@ update_fbo (FramebufferData *data,
}
static gboolean
-update_actor_fbo (ShellBlurEffect *self,
+update_actor_fbo (MetaShellBlurEffect *self,
unsigned int width,
unsigned int height,
float downscale_factor)
@@ -231,7 +269,7 @@ update_actor_fbo (ShellBlurEffect *self,
}
static gboolean
-update_brightness_fbo (ShellBlurEffect *self,
+update_brightness_fbo (MetaShellBlurEffect *self,
unsigned int width,
unsigned int height,
float downscale_factor)
@@ -250,7 +288,7 @@ update_brightness_fbo (ShellBlurEffect *
}
static gboolean
-update_background_fbo (ShellBlurEffect *self,
+update_background_fbo (MetaShellBlurEffect *self,
unsigned int width,
unsigned int height)
{
@@ -303,10 +341,10 @@ static void
shell_blur_effect_set_actor (ClutterActorMeta *meta,
ClutterActor *actor)
{
- ShellBlurEffect *self = SHELL_BLUR_EFFECT (meta);
+ MetaShellBlurEffect *self = META_SHELL_BLUR_EFFECT (meta);
ClutterActorMetaClass *meta_class;
- meta_class = CLUTTER_ACTOR_META_CLASS (shell_blur_effect_parent_class);
+ meta_class = CLUTTER_ACTOR_META_CLASS (meta_shell_blur_effect_parent_class);
meta_class->set_actor (meta, actor);
/* clear out the previous state */
@@ -319,7 +357,7 @@ shell_blur_effect_set_actor (ClutterActo
}
static void
-update_actor_box (ShellBlurEffect *self,
+update_actor_box (MetaShellBlurEffect *self,
ClutterPaintContext *paint_context,
ClutterActorBox *source_actor_box)
{
@@ -368,7 +406,7 @@ update_actor_box (ShellBlurEffect *s
}
static void
-add_blurred_pipeline (ShellBlurEffect *self,
+add_blurred_pipeline (MetaShellBlurEffect *self,
ClutterPaintNode *node,
uint8_t paint_opacity)
{
@@ -395,7 +433,7 @@ add_blurred_pipeline (ShellBlurEffect *
}
static ClutterPaintNode *
-create_blur_nodes (ShellBlurEffect *self,
+create_blur_nodes (MetaShellBlurEffect *self,
ClutterPaintNode *node,
uint8_t paint_opacity)
{
@@ -435,7 +473,7 @@ create_blur_nodes (ShellBlurEffect *sel
}
static void
-paint_background (ShellBlurEffect *self,
+paint_background (MetaShellBlurEffect *self,
ClutterPaintNode *node,
ClutterPaintContext *paint_context,
ClutterActorBox *source_actor_box)
@@ -482,7 +520,7 @@ paint_background (ShellBlurEffect *s
}
static gboolean
-update_framebuffers (ShellBlurEffect *self,
+update_framebuffers (MetaShellBlurEffect *self,
ClutterPaintContext *paint_context,
ClutterActorBox *source_actor_box)
{
@@ -509,7 +547,7 @@ update_framebuffers (ShellBlurEffect
}
static void
-add_actor_node (ShellBlurEffect *self,
+add_actor_node (MetaShellBlurEffect *self,
ClutterPaintNode *node,
int opacity)
{
@@ -520,7 +558,7 @@ add_actor_node (ShellBlurEffect *self,
}
static void
-paint_actor_offscreen (ShellBlurEffect *self,
+paint_actor_offscreen (MetaShellBlurEffect *self,
ClutterPaintNode *node,
ClutterEffectPaintFlags flags)
{
@@ -579,7 +617,7 @@ paint_actor_offscreen (ShellBlurEffect
}
static gboolean
-needs_repaint (ShellBlurEffect *self,
+needs_repaint (MetaShellBlurEffect *self,
ClutterEffectPaintFlags flags)
{
gboolean actor_cached;
@@ -608,7 +646,7 @@ shell_blur_effect_paint_node (ClutterEff
ClutterPaintContext *paint_context,
ClutterEffectPaintFlags flags)
{
- ShellBlurEffect *self = SHELL_BLUR_EFFECT (effect);
+ MetaShellBlurEffect *self = META_SHELL_BLUR_EFFECT (effect);
uint8_t paint_opacity;
g_assert (self->actor != NULL);
@@ -689,7 +727,7 @@ fail:
static void
shell_blur_effect_finalize (GObject *object)
{
- ShellBlurEffect *self = (ShellBlurEffect *)object;
+ MetaShellBlurEffect *self = (MetaShellBlurEffect *)object;
clear_framebuffer_data (&self->actor_fb);
clear_framebuffer_data (&self->background_fb);
@@ -699,7 +737,7 @@ shell_blur_effect_finalize (GObject *obj
g_clear_pointer (&self->background_fb.pipeline, cogl_object_unref);
g_clear_pointer (&self->brightness_fb.pipeline, cogl_object_unref);
- G_OBJECT_CLASS (shell_blur_effect_parent_class)->finalize (object);
+ G_OBJECT_CLASS (meta_shell_blur_effect_parent_class)->finalize (object);
}
static void
@@ -708,7 +746,7 @@ shell_blur_effect_get_property (GObject
GValue *value,
GParamSpec *pspec)
{
- ShellBlurEffect *self = SHELL_BLUR_EFFECT (object);
+ MetaShellBlurEffect *self = META_SHELL_BLUR_EFFECT (object);
switch (prop_id)
{
@@ -735,20 +773,20 @@ shell_blur_effect_set_property (GObject
const GValue *value,
GParamSpec *pspec)
{
- ShellBlurEffect *self = SHELL_BLUR_EFFECT (object);
+ MetaShellBlurEffect *self = META_SHELL_BLUR_EFFECT (object);
switch (prop_id)
{
case PROP_SIGMA:
- shell_blur_effect_set_sigma (self, g_value_get_int (value));
+ meta_shell_blur_effect_set_sigma (self, g_value_get_int (value));
break;
case PROP_BRIGHTNESS:
- shell_blur_effect_set_brightness (self, g_value_get_float (value));
+ meta_shell_blur_effect_set_brightness (self, g_value_get_float (value));
break;
case PROP_MODE:
- shell_blur_effect_set_mode (self, g_value_get_enum (value));
+ meta_shell_blur_effect_set_mode (self, g_value_get_enum (value));
break;
default:
@@ -757,7 +795,7 @@ shell_blur_effect_set_property (GObject
}
static void
-shell_blur_effect_class_init (ShellBlurEffectClass *klass)
+meta_shell_blur_effect_class_init (MetaShellBlurEffectClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ClutterActorMetaClass *meta_class = CLUTTER_ACTOR_META_CLASS (klass);
@@ -797,38 +835,50 @@ shell_blur_effect_class_init (ShellBlurE
}
static void
-shell_blur_effect_init (ShellBlurEffect *self)
+meta_shell_blur_effect_init (MetaShellBlurEffect *self)
{
self->mode = SHELL_BLUR_MODE_ACTOR;
self->sigma = 0;
self->brightness = 1.f;
+ self->skip = false;
self->actor_fb.pipeline = create_base_pipeline ();
self->background_fb.pipeline = create_base_pipeline ();
self->brightness_fb.pipeline = create_brightness_pipeline ();
self->brightness_uniform =
cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "brightness");
+ self->bounds_uniform =
+ cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "bounds");
+ self->corner_centers_1_uniform =
+ cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "corner_centers_1");
+ self->corner_centers_2_uniform =
+ cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "corner_centers_2");
+ self->pixel_step_uniform =
+ cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "pixel_step");
+ self->skip_uniform =
+ cogl_pipeline_get_uniform_location (self->brightness_fb.pipeline, "skip");
+
}
-ShellBlurEffect *
-shell_blur_effect_new (void)
+MetaShellBlurEffect *
+meta_shell_blur_effect_new (void)
{
- return g_object_new (SHELL_TYPE_BLUR_EFFECT, NULL);
+ return g_object_new (META_SHELL_TYPE_BLUR_EFFECT, NULL);
}
int
-shell_blur_effect_get_sigma (ShellBlurEffect *self)
+meta_shell_blur_effect_get_sigma (MetaShellBlurEffect *self)
{
- g_return_val_if_fail (SHELL_IS_BLUR_EFFECT (self), -1);
+ g_return_val_if_fail (META_IS_SHELL_BLUR_EFFECT (self), -1);
return self->sigma;
}
void
-shell_blur_effect_set_sigma (ShellBlurEffect *self,
+meta_shell_blur_effect_set_sigma (MetaShellBlurEffect *self,
int sigma)
{
- g_return_if_fail (SHELL_IS_BLUR_EFFECT (self));
+ g_return_if_fail (META_IS_SHELL_BLUR_EFFECT (self));
if (self->sigma == sigma)
return;
@@ -843,18 +893,18 @@ shell_blur_effect_set_sigma (ShellBlurEf
}
float
-shell_blur_effect_get_brightness (ShellBlurEffect *self)
+meta_shell_blur_effect_get_brightness (MetaShellBlurEffect *self)
{
- g_return_val_if_fail (SHELL_IS_BLUR_EFFECT (self), FALSE);
+ g_return_val_if_fail (META_IS_SHELL_BLUR_EFFECT (self), FALSE);
return self->brightness;
}
void
-shell_blur_effect_set_brightness (ShellBlurEffect *self,
+meta_shell_blur_effect_set_brightness (MetaShellBlurEffect *self,
float brightness)
{
- g_return_if_fail (SHELL_IS_BLUR_EFFECT (self));
+ g_return_if_fail (META_IS_SHELL_BLUR_EFFECT (self));
if (self->brightness == brightness)
return;
@@ -869,18 +919,18 @@ shell_blur_effect_set_brightness (ShellB
}
ShellBlurMode
-shell_blur_effect_get_mode (ShellBlurEffect *self)
+meta_shell_blur_effect_get_mode (MetaShellBlurEffect *self)
{
- g_return_val_if_fail (SHELL_IS_BLUR_EFFECT (self), -1);
+ g_return_val_if_fail (META_IS_SHELL_BLUR_EFFECT (self), -1);
return self->mode;
}
void
-shell_blur_effect_set_mode (ShellBlurEffect *self,
+meta_shell_blur_effect_set_mode (MetaShellBlurEffect *self,
ShellBlurMode mode)
{
- g_return_if_fail (SHELL_IS_BLUR_EFFECT (self));
+ g_return_if_fail (META_IS_SHELL_BLUR_EFFECT (self));
if (self->mode == mode)
return;
@@ -905,3 +955,17 @@ shell_blur_effect_set_mode (ShellBlurEff
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODE]);
}
+
+void meta_shell_blur_effect_set_skip (MetaShellBlurEffect *self,
+ gboolean skip)
+{
+ g_return_if_fail (META_IS_SHELL_BLUR_EFFECT (self));
+
+ if (self->skip == skip)
+ return;
+
+ self->skip = skip;
+
+ if (self->actor)
+ clutter_effect_queue_repaint (CLUTTER_EFFECT (self));
+}
diff -Narup a/src/shell-blur-effect.h b/src/shell-blur-effect.h
--- a/src/shell-blur-effect.h 2021-11-06 14:09:18.864228559 +0800
+++ b/src/shell-blur-effect.h 2021-11-06 14:09:18.864228559 +0800
@@ -20,6 +20,10 @@
#pragma once
+/*
+ * have to rename the type, to avoide conflicts with gnome shell
+ */
+
#include <clutter/clutter.h>
G_BEGIN_DECLS
@@ -37,21 +41,24 @@ typedef enum
SHELL_BLUR_MODE_BACKGROUND,
} ShellBlurMode;
-#define SHELL_TYPE_BLUR_EFFECT (shell_blur_effect_get_type())
-G_DECLARE_FINAL_TYPE (ShellBlurEffect, shell_blur_effect, SHELL, BLUR_EFFECT, ClutterEffect)
+#define META_SHELL_TYPE_BLUR_EFFECT (meta_shell_blur_effect_get_type())
+G_DECLARE_FINAL_TYPE (MetaShellBlurEffect, meta_shell_blur_effect, META, SHELL_BLUR_EFFECT, ClutterEffect)
+
+MetaShellBlurEffect *meta_shell_blur_effect_new (void);
+
+int meta_shell_blur_effect_get_sigma (MetaShellBlurEffect *self);
+void meta_shell_blur_effect_set_sigma (MetaShellBlurEffect *self,
+ int sigma);
+
+float meta_shell_blur_effect_get_brightness (MetaShellBlurEffect *self);
+void meta_shell_blur_effect_set_brightness (MetaShellBlurEffect *self,
+ float brightness);
-ShellBlurEffect *shell_blur_effect_new (void);
+ShellBlurMode meta_shell_blur_effect_get_mode (MetaShellBlurEffect *self);
+void meta_shell_blur_effect_set_mode (MetaShellBlurEffect *self,
+ ShellBlurMode mode);
-int shell_blur_effect_get_sigma (ShellBlurEffect *self);
-void shell_blur_effect_set_sigma (ShellBlurEffect *self,
- int sigma);
-
-float shell_blur_effect_get_brightness (ShellBlurEffect *self);
-void shell_blur_effect_set_brightness (ShellBlurEffect *self,
- float brightness);
-
-ShellBlurMode shell_blur_effect_get_mode (ShellBlurEffect *self);
-void shell_blur_effect_set_mode (ShellBlurEffect *self,
- ShellBlurMode mode);
+void meta_shell_blur_effect_set_skip (MetaShellBlurEffect *self,
+ gboolean skip);
G_END_DECLS
|