Merge lp:~larsu/notify-osd/crisper-on-hidpi into lp:notify-osd

Proposed by Lars Karlitski
Status: Merged
Approved by: Mirco Müller
Approved revision: 491
Merged at revision: 489
Proposed branch: lp:~larsu/notify-osd/crisper-on-hidpi
Merge into: lp:notify-osd
Diff against target: 625 lines (+143/-132)
8 files modified
src/bubble.c (+99/-72)
src/raico-blur.c (+13/-3)
src/tile.c (+7/-11)
src/tile.h (+3/-1)
src/util.c (+15/-36)
src/util.h (+0/-3)
tests/test-grow-bubble.c (+1/-1)
tests/test-scroll-text.c (+5/-5)
To merge this branch: bzr merge lp:~larsu/notify-osd/crisper-on-hidpi
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+269930@code.launchpad.net

Commit message

Render in native resolution on hidpi displays

Description of the change

Render in native resolution on hidpi displays

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Reviewed and tested it. Looking good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bubble.c'
--- src/bubble.c 2014-12-20 21:35:15 +0000
+++ src/bubble.c 2015-09-02 14:41:24 +0000
@@ -177,6 +177,23 @@
177static guint g_bubble_signals[LAST_SIGNAL] = { 0 };177static guint g_bubble_signals[LAST_SIGNAL] = { 0 };
178gint g_pointer[2];178gint g_pointer[2];
179179
180static cairo_surface_t *
181bubble_create_image_surface (Bubble* self,
182 cairo_format_t format,
183 gint width,
184 gint height)
185{
186 cairo_surface_t *surface;
187 gint scale;
188
189 scale = gtk_widget_get_scale_factor (self->priv->widget);
190
191 surface = cairo_image_surface_create (format, scale * width, scale * height);
192 cairo_surface_set_device_scale (surface, scale, scale);
193
194 return surface;
195}
196
180static void197static void
181draw_round_rect (cairo_t* cr,198draw_round_rect (cairo_t* cr,
182 gdouble aspect, // aspect-ratio199 gdouble aspect, // aspect-ratio
@@ -372,7 +389,8 @@
372}389}
373390
374void391void
375_draw_shadow (cairo_t* cr,392_draw_shadow (Bubble* self,
393 cairo_t* cr,
376 gdouble width,394 gdouble width,
377 gdouble height,395 gdouble height,
378 gint shadow_radius,396 gint shadow_radius,
@@ -384,10 +402,13 @@
384 cairo_t* cr_surf = NULL;402 cairo_t* cr_surf = NULL;
385 cairo_matrix_t matrix;403 cairo_matrix_t matrix;
386 raico_blur_t* blur = NULL;404 raico_blur_t* blur = NULL;
405 double x_scale;
406 double y_scale;
387407
388 tmp_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,408 tmp_surface = bubble_create_image_surface (self,
389 4 * shadow_radius,409 CAIRO_FORMAT_ARGB32,
390 4 * shadow_radius);410 4 * shadow_radius,
411 4 * shadow_radius);
391 if (cairo_surface_status (tmp_surface) != CAIRO_STATUS_SUCCESS) {412 if (cairo_surface_status (tmp_surface) != CAIRO_STATUS_SUCCESS) {
392 if (tmp_surface)413 if (tmp_surface)
393 cairo_surface_destroy (tmp_surface);414 cairo_surface_destroy (tmp_surface);
@@ -433,6 +454,9 @@
433 cairo_image_surface_get_width (tmp_surface) / 2,454 cairo_image_surface_get_width (tmp_surface) / 2,
434 cairo_image_surface_get_height (tmp_surface) / 2,455 cairo_image_surface_get_height (tmp_surface) / 2,
435 cairo_image_surface_get_stride (tmp_surface));456 cairo_image_surface_get_stride (tmp_surface));
457 cairo_surface_get_device_scale (tmp_surface, &x_scale, &y_scale);
458 cairo_surface_set_device_scale (new_surface, x_scale, y_scale);
459
436 pattern = cairo_pattern_create_for_surface (new_surface);460 pattern = cairo_pattern_create_for_surface (new_surface);
437 if (cairo_pattern_status (pattern) != CAIRO_STATUS_SUCCESS)461 if (cairo_pattern_status (pattern) != CAIRO_STATUS_SUCCESS)
438 {462 {
@@ -639,7 +663,6 @@
639 Defaults* d = self->defaults;663 Defaults* d = self->defaults;
640 cairo_t* cr = NULL;664 cairo_t* cr = NULL;
641 cairo_surface_t* scratch = NULL;665 cairo_surface_t* scratch = NULL;
642 cairo_surface_t* dummy = NULL;
643 cairo_surface_t* clone = NULL;666 cairo_surface_t* clone = NULL;
644 cairo_surface_t* normal = NULL;667 cairo_surface_t* normal = NULL;
645 cairo_surface_t* blurred = NULL;668 cairo_surface_t* blurred = NULL;
@@ -654,7 +677,8 @@
654 if (priv->composited)677 if (priv->composited)
655 {678 {
656 scratch_shadow_size = EM2PIXELS (get_shadow_size (self), d);679 scratch_shadow_size = EM2PIXELS (get_shadow_size (self), d);
657 scratch = cairo_image_surface_create (680 scratch = bubble_create_image_surface (
681 self,
658 CAIRO_FORMAT_ARGB32,682 CAIRO_FORMAT_ARGB32,
659 3 * scratch_shadow_size,683 3 * scratch_shadow_size,
660 3 * scratch_shadow_size);684 3 * scratch_shadow_size);
@@ -663,7 +687,8 @@
663 {687 {
664 // We must have at least some width to this scratch surface.688 // We must have at least some width to this scratch surface.
665 scratch_shadow_size = 1;689 scratch_shadow_size = 1;
666 scratch = cairo_image_surface_create (690 scratch = bubble_create_image_surface (
691 self,
667 CAIRO_FORMAT_RGB24,692 CAIRO_FORMAT_RGB24,
668 3 * scratch_shadow_size,693 3 * scratch_shadow_size,
669 3 * scratch_shadow_size);694 3 * scratch_shadow_size);
@@ -715,6 +740,7 @@
715 if (priv->composited)740 if (priv->composited)
716 {741 {
717 _draw_shadow (742 _draw_shadow (
743 self,
718 cr,744 cr,
719 width,745 width,
720 height,746 height,
@@ -757,24 +783,10 @@
757 cairo_destroy (cr);783 cairo_destroy (cr);
758784
759 // create temp. clone of scratch surface785 // create temp. clone of scratch surface
760 dummy = cairo_image_surface_create_for_data (786 clone = copy_surface (scratch);
761 cairo_image_surface_get_data (scratch),
762 cairo_image_surface_get_format (scratch),
763 3 * scratch_shadow_size,
764 3 * scratch_shadow_size,
765 cairo_image_surface_get_stride (scratch));
766 clone = copy_surface (dummy);
767 cairo_surface_destroy (dummy);
768787
769 // create normal surface from that surface-clone788 // create normal surface from that surface-clone
770 dummy = cairo_image_surface_create_for_data (789 normal = copy_surface (clone);
771 cairo_image_surface_get_data (clone),
772 cairo_image_surface_get_format (clone),
773 2 * scratch_shadow_size,
774 2 * scratch_shadow_size,
775 cairo_image_surface_get_stride (clone));
776 normal = copy_surface (dummy);
777 cairo_surface_destroy (dummy);
778790
779 // now blur the surface-clone791 // now blur the surface-clone
780 blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);792 blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW);
@@ -783,30 +795,26 @@
783 raico_blur_destroy (blur);795 raico_blur_destroy (blur);
784796
785 // create blurred version from that blurred surface-clone 797 // create blurred version from that blurred surface-clone
786 dummy = cairo_image_surface_create_for_data (798 blurred = copy_surface (clone);
787 cairo_image_surface_get_data (clone),799 cairo_surface_destroy (clone);
788 cairo_image_surface_get_format (clone),
789 2 * scratch_shadow_size,
790 2 * scratch_shadow_size,
791 cairo_image_surface_get_stride (clone));
792 blurred = copy_surface (dummy);
793 cairo_surface_destroy (dummy);
794 destroy_cloned_surface (clone);
795800
796 // finally create tile with top-left shadow/background part801 // finally create tile with top-left shadow/background part
797 if (priv->tile_background_part)802 if (priv->tile_background_part)
798 tile_destroy (priv->tile_background_part);803 tile_destroy (priv->tile_background_part);
799 priv->tile_background_part = tile_new_for_padding (normal, blurred);804 priv->tile_background_part = tile_new_for_padding (normal, blurred,
800 destroy_cloned_surface (normal);805 3 * scratch_shadow_size,
801 destroy_cloned_surface (blurred);806 3 * scratch_shadow_size);
807 cairo_surface_destroy (normal);
808 cairo_surface_destroy (blurred);
802809
803 // create surface(s) for full shadow/background tile810 // create surface(s) for full shadow/background tile
804 if (priv->composited)811 if (priv->composited)
805 {812 {
806 // we need two RGBA-surfaces813 // we need two RGBA-surfaces
807 normal = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,814 normal = bubble_create_image_surface (self,
808 width,815 CAIRO_FORMAT_ARGB32,
809 height);816 width,
817 height);
810 if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS)818 if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS)
811 {819 {
812 cairo_surface_destroy (scratch);820 cairo_surface_destroy (scratch);
@@ -817,9 +825,10 @@
817 return;825 return;
818 }826 }
819827
820 blurred = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,828 blurred = bubble_create_image_surface (self,
821 width,829 CAIRO_FORMAT_ARGB32,
822 height);830 width,
831 height);
823 if (cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS)832 if (cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS)
824 {833 {
825 cairo_surface_destroy (normal);834 cairo_surface_destroy (normal);
@@ -834,9 +843,10 @@
834 else843 else
835 {844 {
836 // we need only one RGB-surface845 // we need only one RGB-surface
837 normal = cairo_image_surface_create (CAIRO_FORMAT_RGB24,846 normal = bubble_create_image_surface (self,
838 width,847 CAIRO_FORMAT_RGB24,
839 height);848 width,
849 height);
840 if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS)850 if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS)
841 {851 {
842 cairo_surface_destroy (scratch);852 cairo_surface_destroy (scratch);
@@ -921,9 +931,9 @@
921 if (priv->tile_background)931 if (priv->tile_background)
922 tile_destroy (priv->tile_background);932 tile_destroy (priv->tile_background);
923 if (priv->composited)933 if (priv->composited)
924 priv->tile_background = tile_new_for_padding (normal, blurred);934 priv->tile_background = tile_new_for_padding (normal, blurred, width, height);
925 else935 else
926 priv->tile_background = tile_new_for_padding (normal, normal);936 priv->tile_background = tile_new_for_padding (normal, normal, width, height);
927937
928 // clean up938 // clean up
929 if (priv->composited)939 if (priv->composited)
@@ -936,16 +946,18 @@
936void946void
937_refresh_icon (Bubble* self)947_refresh_icon (Bubble* self)
938{948{
939 BubblePrivate* priv = self->priv;949 BubblePrivate* priv = self->priv;
940 Defaults* d = self->defaults;950 Defaults* d = self->defaults;
941 cairo_surface_t* normal = NULL;951 cairo_surface_t* normal = NULL;
942 cairo_t* cr = NULL;952 cairo_surface_t* icon_surface = NULL;
953 cairo_t* cr = NULL;
943954
944 if (!priv->icon_pixbuf)955 if (!priv->icon_pixbuf)
945 return;956 return;
946957
947 // create temp. scratch surface958 // create temp. scratch surface
948 normal = cairo_image_surface_create (959 normal = bubble_create_image_surface (
960 self,
949 CAIRO_FORMAT_ARGB32,961 CAIRO_FORMAT_ARGB32,
950 EM2PIXELS (defaults_get_icon_size (d), d) +962 EM2PIXELS (defaults_get_icon_size (d), d) +
951 2 * BUBBLE_CONTENT_BLUR_RADIUS,963 2 * BUBBLE_CONTENT_BLUR_RADIUS,
@@ -969,10 +981,12 @@
969 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);981 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
970982
971 // render icon into normal surface983 // render icon into normal surface
972 gdk_cairo_set_source_pixbuf (cr,984 icon_surface = gdk_cairo_surface_create_from_pixbuf (priv->icon_pixbuf, 0,
973 priv->icon_pixbuf,985 gtk_widget_get_window (priv->widget));
974 BUBBLE_CONTENT_BLUR_RADIUS,986 cairo_set_source_surface (cr,
975 BUBBLE_CONTENT_BLUR_RADIUS);987 icon_surface,
988 BUBBLE_CONTENT_BLUR_RADIUS,
989 BUBBLE_CONTENT_BLUR_RADIUS);
976 cairo_paint (cr);990 cairo_paint (cr);
977991
978 // create the surface/blur-cache from the normal surface992 // create the surface/blur-cache from the normal surface
@@ -982,6 +996,7 @@
982996
983 // clean up997 // clean up
984 cairo_destroy (cr);998 cairo_destroy (cr);
999 cairo_surface_destroy (icon_surface);
985 cairo_surface_destroy (normal);1000 cairo_surface_destroy (normal);
986}1001}
9871002
@@ -998,7 +1013,8 @@
998 gchar* text_font_face = NULL;1013 gchar* text_font_face = NULL;
9991014
1000 // create temp. scratch surface1015 // create temp. scratch surface
1001 normal = cairo_image_surface_create (1016 normal = bubble_create_image_surface (
1017 self,
1002 CAIRO_FORMAT_ARGB32,1018 CAIRO_FORMAT_ARGB32,
1003 priv->title_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS,1019 priv->title_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS,
1004 priv->title_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS);1020 priv->title_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS);
@@ -1106,7 +1122,8 @@
1106 gchar* text_font_face = NULL;1122 gchar* text_font_face = NULL;
11071123
1108 // create temp. scratch surface1124 // create temp. scratch surface
1109 normal = cairo_image_surface_create (1125 normal = bubble_create_image_surface (
1126 self,
1110 CAIRO_FORMAT_ARGB32,1127 CAIRO_FORMAT_ARGB32,
1111 priv->body_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS,1128 priv->body_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS,
1112 priv->body_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS);1129 priv->body_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS);
@@ -1212,7 +1229,8 @@
1212 cairo_t* cr = NULL;1229 cairo_t* cr = NULL;
12131230
1214 // create temp. scratch surface1231 // create temp. scratch surface
1215 normal = cairo_image_surface_create (1232 normal = bubble_create_image_surface (
1233 self,
1216 CAIRO_FORMAT_ARGB32,1234 CAIRO_FORMAT_ARGB32,
1217 EM2PIXELS (defaults_get_bubble_width (d), d) -1235 EM2PIXELS (defaults_get_bubble_width (d), d) -
1218 3 * EM2PIXELS (defaults_get_margin_size (d), d) -1236 3 * EM2PIXELS (defaults_get_margin_size (d), d) -
@@ -1810,13 +1828,15 @@
18101828
1811static1829static
1812GdkPixbuf*1830GdkPixbuf*
1813load_icon (const gchar* filename,1831load_icon (Bubble* self,
1832 const gchar* filename,
1814 gint icon_size)1833 gint icon_size)
1815{1834{
1816 GdkPixbuf* buffer = NULL;1835 GdkPixbuf* buffer = NULL;
1817 GdkPixbuf* pixbuf = NULL;1836 GdkPixbuf* pixbuf = NULL;
1818 GtkIconTheme* theme = NULL;1837 GtkIconTheme* theme = NULL;
1819 GError* error = NULL;1838 GError* error = NULL;
1839 gint scale;
18201840
1821 /* sanity check */1841 /* sanity check */
1822 g_return_val_if_fail (filename, NULL);1842 g_return_val_if_fail (filename, NULL);
@@ -1825,25 +1845,28 @@
1825 if (!strncmp (filename, "file://", 7))1845 if (!strncmp (filename, "file://", 7))
1826 filename += 7;1846 filename += 7;
18271847
1848 scale = gtk_widget_get_scale_factor (self->priv->widget);
1849
1828 if (filename[0] == '/')1850 if (filename[0] == '/')
1829 {1851 {
1830 /* load image into pixbuf */1852 /* load image into pixbuf */
1831 pixbuf = gdk_pixbuf_new_from_file_at_scale (filename,1853 pixbuf = gdk_pixbuf_new_from_file_at_scale (filename,
1832 icon_size,1854 scale * icon_size,
1833 icon_size,1855 scale * icon_size,
1834 TRUE,1856 TRUE,
1835 NULL);1857 NULL);
1836 } else {1858 } else {
1837 /* TODO: rewrite, check for SVG support, raise apport1859 /* TODO: rewrite, check for SVG support, raise apport
1838 ** notification for low-res icons */1860 ** notification for low-res icons */
1839 theme = gtk_icon_theme_get_default ();1861 theme = gtk_icon_theme_get_default ();
1840 buffer = gtk_icon_theme_load_icon (theme,1862 buffer = gtk_icon_theme_load_icon_for_scale (theme,
1841 filename,1863 filename,
1842 icon_size,1864 icon_size,
1843 GTK_ICON_LOOKUP_FORCE_SVG |1865 scale,
1844 GTK_ICON_LOOKUP_GENERIC_FALLBACK |1866 GTK_ICON_LOOKUP_FORCE_SVG |
1845 GTK_ICON_LOOKUP_FORCE_SIZE,1867 GTK_ICON_LOOKUP_GENERIC_FALLBACK |
1846 &error);1868 GTK_ICON_LOOKUP_FORCE_SIZE,
1869 &error);
1847 if (error)1870 if (error)
1848 {1871 {
1849 g_print ("loading icon '%s' caused error: '%s'",1872 g_print ("loading icon '%s' caused error: '%s'",
@@ -2431,7 +2454,8 @@
2431 }2454 }
24322455
2433 d = self->defaults;2456 d = self->defaults;
2434 priv->icon_pixbuf = load_icon (filepath,2457 priv->icon_pixbuf = load_icon (self,
2458 filepath,
2435 EM2PIXELS (defaults_get_icon_size (d), d));2459 EM2PIXELS (defaults_get_icon_size (d), d));
24362460
2437 _refresh_icon (self);2461 _refresh_icon (self);
@@ -2474,7 +2498,8 @@
2474#ifdef TEMPORARY_ICON_PREFIX_WORKAROUND2498#ifdef TEMPORARY_ICON_PREFIX_WORKAROUND
2475 notify_osd_iconname = g_strdup_printf (NOTIFY_OSD_ICON_PREFIX "-%s",2499 notify_osd_iconname = g_strdup_printf (NOTIFY_OSD_ICON_PREFIX "-%s",
2476 filename);2500 filename);
2477 priv->icon_pixbuf = load_icon (notify_osd_iconname,2501 priv->icon_pixbuf = load_icon (self,
2502 notify_osd_iconname,
2478 EM2PIXELS (defaults_get_icon_size (d),2503 EM2PIXELS (defaults_get_icon_size (d),
2479 d));2504 d));
2480 g_free (notify_osd_iconname);2505 g_free (notify_osd_iconname);
@@ -2482,7 +2507,8 @@
24822507
2483 // fallback to non-notify-osd name2508 // fallback to non-notify-osd name
2484 if (!priv->icon_pixbuf)2509 if (!priv->icon_pixbuf)
2485 priv->icon_pixbuf = load_icon (filename,2510 priv->icon_pixbuf = load_icon (self,
2511 filename,
2486 EM2PIXELS (defaults_get_icon_size (d), d));2512 EM2PIXELS (defaults_get_icon_size (d), d));
24872513
2488 _refresh_icon (self);2514 _refresh_icon (self);
@@ -3224,7 +3250,7 @@
3224 d = self->defaults;3250 d = self->defaults;
3225 priv = self->priv;3251 priv = self->priv;
32263252
3227 surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1);3253 surface = bubble_create_image_surface (self, CAIRO_FORMAT_A1, 1, 1);
3228 if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {3254 if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
3229 if (surface)3255 if (surface)
3230 cairo_surface_destroy (surface);3256 cairo_surface_destroy (surface);
@@ -3418,6 +3444,7 @@
3418 EM2PIXELS (defaults_get_icon_size (d), d),3444 EM2PIXELS (defaults_get_icon_size (d), d),
3419 EM2PIXELS (defaults_get_icon_size (d), d),3445 EM2PIXELS (defaults_get_icon_size (d), d),
3420 GDK_INTERP_BILINEAR);3446 GDK_INTERP_BILINEAR);
3447 g_message ("resizing pixbuf to %d", EM2PIXELS (defaults_get_icon_size (d), d) );
3421 g_object_unref (priv->icon_pixbuf);3448 g_object_unref (priv->icon_pixbuf);
3422 priv->icon_pixbuf = pixbuf;3449 priv->icon_pixbuf = pixbuf;
3423 }3450 }
34243451
=== modified file 'src/raico-blur.c'
--- src/raico-blur.c 2009-11-05 03:13:20 +0000
+++ src/raico-blur.c 2015-09-02 14:41:24 +0000
@@ -112,6 +112,9 @@
112 cairo_surface_t* surface)112 cairo_surface_t* surface)
113{113{
114 cairo_format_t format;114 cairo_format_t format;
115 double x_scale;
116 double y_scale;
117 guint radius;
115118
116 // sanity checks119 // sanity checks
117 if (!blur)120 if (!blur)
@@ -151,20 +154,27 @@
151 if (blur->priv->radius == 0)154 if (blur->priv->radius == 0)
152 return;155 return;
153156
157 /* adjust radius for device scale. We don't support blurring
158 * different amounts in x and y, so just use the mean value
159 * between cairo's respective device scales (in practice they
160 * should always be the same). */
161 cairo_surface_get_device_scale (surface, &x_scale, &y_scale);
162 radius = blur->priv->radius * 0.5 * (x_scale + y_scale);
163
154 // now do the real work164 // now do the real work
155 switch (blur->priv->quality)165 switch (blur->priv->quality)
156 {166 {
157 case RAICO_BLUR_QUALITY_LOW:167 case RAICO_BLUR_QUALITY_LOW:
158 surface_exponential_blur (surface, blur->priv->radius);168 surface_exponential_blur (surface, radius);
159 break;169 break;
160170
161 case RAICO_BLUR_QUALITY_MEDIUM:171 case RAICO_BLUR_QUALITY_MEDIUM:
162 //surface_stack_blur (surface, blur->priv->radius);172 //surface_stack_blur (surface, blur->priv->radius);
163 surface_gaussian_blur (surface, blur->priv->radius);173 surface_gaussian_blur (surface, radius);
164 break;174 break;
165175
166 case RAICO_BLUR_QUALITY_HIGH:176 case RAICO_BLUR_QUALITY_HIGH:
167 surface_gaussian_blur (surface, blur->priv->radius);177 surface_gaussian_blur (surface, radius);
168 break;178 break;
169 }179 }
170}180}
171181
=== modified file 'src/tile.c'
--- src/tile.c 2010-12-06 00:17:02 +0000
+++ src/tile.c 2015-09-02 14:41:24 +0000
@@ -76,7 +76,9 @@
7676
77tile_t*77tile_t*
78tile_new_for_padding (cairo_surface_t* normal,78tile_new_for_padding (cairo_surface_t* normal,
79 cairo_surface_t* blurred)79 cairo_surface_t* blurred,
80 gint width,
81 gint height)
80{82{
81 tile_private_t* priv = NULL;83 tile_private_t* priv = NULL;
82 tile_t* tile = NULL;84 tile_t* tile = NULL;
@@ -93,20 +95,14 @@
93 cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS)95 cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS)
94 return NULL;96 return NULL;
9597
96 if (cairo_image_surface_get_width (normal) !=
97 cairo_image_surface_get_width (blurred) &&
98 cairo_image_surface_get_height (normal) !=
99 cairo_image_surface_get_height (blurred))
100 return NULL;
101
102 tile->priv = priv;98 tile->priv = priv;
10399
104 tile->priv->normal = copy_surface (normal);100 tile->priv->normal = copy_surface (normal);
105 tile->priv->blurred = copy_surface (blurred);101 tile->priv->blurred = copy_surface (blurred);
106 tile->priv->blur_radius = 0;102 tile->priv->blur_radius = 0;
107 tile->priv->use_padding = TRUE;103 tile->priv->use_padding = TRUE;
108 tile->priv->pad_width = cairo_image_surface_get_width (normal);104 tile->priv->pad_width = width;
109 tile->priv->pad_height = cairo_image_surface_get_height (normal);105 tile->priv->pad_height = height;
110106
111 return tile;107 return tile;
112}108}
@@ -120,8 +116,8 @@
120 //cairo_surface_write_to_png (tile->priv->normal, "./tile-normal.png");116 //cairo_surface_write_to_png (tile->priv->normal, "./tile-normal.png");
121 //cairo_surface_write_to_png (tile->priv->blurred, "./tile-blurred.png");117 //cairo_surface_write_to_png (tile->priv->blurred, "./tile-blurred.png");
122118
123 destroy_cloned_surface (tile->priv->normal);119 cairo_surface_destroy (tile->priv->normal);
124 destroy_cloned_surface (tile->priv->blurred);120 cairo_surface_destroy (tile->priv->blurred);
125121
126 g_free ((gpointer) tile->priv);122 g_free ((gpointer) tile->priv);
127 g_free ((gpointer) tile);123 g_free ((gpointer) tile);
128124
=== modified file 'src/tile.h'
--- src/tile.h 2009-07-14 14:11:40 +0000
+++ src/tile.h 2015-09-02 14:41:24 +0000
@@ -44,7 +44,9 @@
4444
45tile_t*45tile_t*
46tile_new_for_padding (cairo_surface_t* normal,46tile_new_for_padding (cairo_surface_t* normal,
47 cairo_surface_t* blurred);47 cairo_surface_t* blurred,
48 gint width,
49 gint height);
4850
49void51void
50tile_destroy (tile_t* tile);52tile_destroy (tile_t* tile);
5153
=== modified file 'src/util.c'
--- src/util.c 2009-10-25 06:00:23 +0000
+++ src/util.c 2015-09-02 14:41:24 +0000
@@ -139,51 +139,30 @@
139 return text1;139 return text1;
140}140}
141141
142gboolean
143destroy_cloned_surface (cairo_surface_t* surface)
144{
145 gboolean finalref = FALSE;
146 g_return_val_if_fail (surface, FALSE);
147
148 if (cairo_surface_get_reference_count (surface) == 1) {
149 g_free (cairo_image_surface_get_data (surface));
150 finalref = TRUE;
151 }
152 cairo_surface_destroy (surface);
153 return finalref;
154}
155
156cairo_surface_t*142cairo_surface_t*
157copy_surface (cairo_surface_t* orig)143copy_surface (cairo_surface_t* orig)
158{144{
159 cairo_surface_t* copy = NULL;145 cairo_surface_t* copy = NULL;
160 guchar* pixels_src = NULL;
161 guchar* pixels_cpy = NULL;
162 cairo_format_t format;146 cairo_format_t format;
163 gint width;147 gint width;
164 gint height;148 gint height;
165 gint stride;149 cairo_t* cr;
166150 double x_scale;
167 pixels_src = cairo_image_surface_get_data (orig);151 double y_scale;
168 if (!pixels_src)152
169 return NULL;
170
171 format = cairo_image_surface_get_format (orig);
172 width = cairo_image_surface_get_width (orig);153 width = cairo_image_surface_get_width (orig);
173 height = cairo_image_surface_get_height (orig);154 height = cairo_image_surface_get_height (orig);
174 stride = cairo_image_surface_get_stride (orig);155 format = cairo_image_surface_get_format (orig);
175156 cairo_surface_get_device_scale (orig, &x_scale, &y_scale);
176 pixels_cpy = g_malloc0 (stride * height);157
177 if (!pixels_cpy)158 copy = cairo_surface_create_similar_image (orig, format, width, height);
178 return NULL;159 cairo_surface_set_device_scale (copy, x_scale, y_scale);
179160
180 memcpy ((void*) pixels_cpy, (void*) pixels_src, height * stride);161 cr = cairo_create (copy);
181162 cairo_set_source_surface (cr, orig, 0, 0);
182 copy = cairo_image_surface_create_for_data (pixels_cpy,163 cairo_paint (cr);
183 format,164
184 width,165 cairo_destroy (cr);
185 height,
186 stride);
187166
188 return copy;167 return copy;
189}168}
190169
=== modified file 'src/util.h'
--- src/util.h 2009-10-25 06:00:23 +0000
+++ src/util.h 2015-09-02 14:41:24 +0000
@@ -46,9 +46,6 @@
46cairo_surface_t*46cairo_surface_t*
47copy_surface (cairo_surface_t* orig);47copy_surface (cairo_surface_t* orig);
4848
49gboolean
50destroy_cloned_surface (cairo_surface_t* surface);
51
52gchar*49gchar*
53get_wm_name (Display* dpy);50get_wm_name (Display* dpy);
5451
5552
=== modified file 'tests/test-grow-bubble.c'
--- tests/test-grow-bubble.c 2014-12-20 18:39:52 +0000
+++ tests/test-grow-bubble.c 2015-09-02 14:41:24 +0000
@@ -651,7 +651,7 @@
651 cairo_surface_destroy (tmp);651 cairo_surface_destroy (tmp);
652 cairo_surface_destroy (dummy_surf);652 cairo_surface_destroy (dummy_surf);
653653
654 g_tile = tile_new_for_padding (norm_surf, blur_surf);654 g_tile = tile_new_for_padding (norm_surf, blur_surf, width, height);
655 cairo_surface_destroy (norm_surf);655 cairo_surface_destroy (norm_surf);
656 cairo_surface_destroy (blur_surf);656 cairo_surface_destroy (blur_surf);
657657
658658
=== modified file 'tests/test-scroll-text.c'
--- tests/test-scroll-text.c 2014-12-20 18:39:52 +0000
+++ tests/test-scroll-text.c 2015-09-02 14:41:24 +0000
@@ -826,10 +826,10 @@
826 cairo_surface_destroy (tmp);826 cairo_surface_destroy (tmp);
827827
828 // actually create the tile with padding in mind828 // actually create the tile with padding in mind
829 tile = tile_new_for_padding (norm_surf, blur_surf);829 tile = tile_new_for_padding (norm_surf, blur_surf, width, height);
830 destroy_cloned_surface (norm_surf);830 cairo_surface_destroy (norm_surf);
831 destroy_cloned_surface (blur_surf);831 cairo_surface_destroy (blur_surf);
832 destroy_cloned_surface (dummy_surf);832 cairo_surface_destroy (dummy_surf);
833833
834 cairo_destroy (cr);834 cairo_destroy (cr);
835 cairo_surface_destroy (cr_surf);835 cairo_surface_destroy (cr_surf);
@@ -852,7 +852,7 @@
852 tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 0.0f, 1.0f);852 tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 0.0f, 1.0f);
853 cairo_destroy (cr);853 cairo_destroy (cr);
854854
855 g_tile = tile_new_for_padding (norm_surf, blur_surf);855 g_tile = tile_new_for_padding (norm_surf, blur_surf, width, height);
856856
857 // clean up857 // clean up
858 tile_destroy (tile);858 tile_destroy (tile);

Subscribers

People subscribed via source and target branches