Merge lp:~larsu/notify-osd/crisper-on-hidpi into lp:notify-osd
- crisper-on-hidpi
- Merge into trunk
Proposed by
Lars Karlitski
on 2015-09-02
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Mirco Müller on 2015-09-04 | ||||
| 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 | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Mirco Müller (community) | 2015-09-02 | Approve on 2015-09-04 | |
|
Review via email:
|
|||
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.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'src/bubble.c' |
| 2 | --- src/bubble.c 2014-12-20 21:35:15 +0000 |
| 3 | +++ src/bubble.c 2015-09-02 14:41:24 +0000 |
| 4 | @@ -177,6 +177,23 @@ |
| 5 | static guint g_bubble_signals[LAST_SIGNAL] = { 0 }; |
| 6 | gint g_pointer[2]; |
| 7 | |
| 8 | +static cairo_surface_t * |
| 9 | +bubble_create_image_surface (Bubble* self, |
| 10 | + cairo_format_t format, |
| 11 | + gint width, |
| 12 | + gint height) |
| 13 | +{ |
| 14 | + cairo_surface_t *surface; |
| 15 | + gint scale; |
| 16 | + |
| 17 | + scale = gtk_widget_get_scale_factor (self->priv->widget); |
| 18 | + |
| 19 | + surface = cairo_image_surface_create (format, scale * width, scale * height); |
| 20 | + cairo_surface_set_device_scale (surface, scale, scale); |
| 21 | + |
| 22 | + return surface; |
| 23 | +} |
| 24 | + |
| 25 | static void |
| 26 | draw_round_rect (cairo_t* cr, |
| 27 | gdouble aspect, // aspect-ratio |
| 28 | @@ -372,7 +389,8 @@ |
| 29 | } |
| 30 | |
| 31 | void |
| 32 | -_draw_shadow (cairo_t* cr, |
| 33 | +_draw_shadow (Bubble* self, |
| 34 | + cairo_t* cr, |
| 35 | gdouble width, |
| 36 | gdouble height, |
| 37 | gint shadow_radius, |
| 38 | @@ -384,10 +402,13 @@ |
| 39 | cairo_t* cr_surf = NULL; |
| 40 | cairo_matrix_t matrix; |
| 41 | raico_blur_t* blur = NULL; |
| 42 | + double x_scale; |
| 43 | + double y_scale; |
| 44 | |
| 45 | - tmp_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
| 46 | - 4 * shadow_radius, |
| 47 | - 4 * shadow_radius); |
| 48 | + tmp_surface = bubble_create_image_surface (self, |
| 49 | + CAIRO_FORMAT_ARGB32, |
| 50 | + 4 * shadow_radius, |
| 51 | + 4 * shadow_radius); |
| 52 | if (cairo_surface_status (tmp_surface) != CAIRO_STATUS_SUCCESS) { |
| 53 | if (tmp_surface) |
| 54 | cairo_surface_destroy (tmp_surface); |
| 55 | @@ -433,6 +454,9 @@ |
| 56 | cairo_image_surface_get_width (tmp_surface) / 2, |
| 57 | cairo_image_surface_get_height (tmp_surface) / 2, |
| 58 | cairo_image_surface_get_stride (tmp_surface)); |
| 59 | + cairo_surface_get_device_scale (tmp_surface, &x_scale, &y_scale); |
| 60 | + cairo_surface_set_device_scale (new_surface, x_scale, y_scale); |
| 61 | + |
| 62 | pattern = cairo_pattern_create_for_surface (new_surface); |
| 63 | if (cairo_pattern_status (pattern) != CAIRO_STATUS_SUCCESS) |
| 64 | { |
| 65 | @@ -639,7 +663,6 @@ |
| 66 | Defaults* d = self->defaults; |
| 67 | cairo_t* cr = NULL; |
| 68 | cairo_surface_t* scratch = NULL; |
| 69 | - cairo_surface_t* dummy = NULL; |
| 70 | cairo_surface_t* clone = NULL; |
| 71 | cairo_surface_t* normal = NULL; |
| 72 | cairo_surface_t* blurred = NULL; |
| 73 | @@ -654,7 +677,8 @@ |
| 74 | if (priv->composited) |
| 75 | { |
| 76 | scratch_shadow_size = EM2PIXELS (get_shadow_size (self), d); |
| 77 | - scratch = cairo_image_surface_create ( |
| 78 | + scratch = bubble_create_image_surface ( |
| 79 | + self, |
| 80 | CAIRO_FORMAT_ARGB32, |
| 81 | 3 * scratch_shadow_size, |
| 82 | 3 * scratch_shadow_size); |
| 83 | @@ -663,7 +687,8 @@ |
| 84 | { |
| 85 | // We must have at least some width to this scratch surface. |
| 86 | scratch_shadow_size = 1; |
| 87 | - scratch = cairo_image_surface_create ( |
| 88 | + scratch = bubble_create_image_surface ( |
| 89 | + self, |
| 90 | CAIRO_FORMAT_RGB24, |
| 91 | 3 * scratch_shadow_size, |
| 92 | 3 * scratch_shadow_size); |
| 93 | @@ -715,6 +740,7 @@ |
| 94 | if (priv->composited) |
| 95 | { |
| 96 | _draw_shadow ( |
| 97 | + self, |
| 98 | cr, |
| 99 | width, |
| 100 | height, |
| 101 | @@ -757,24 +783,10 @@ |
| 102 | cairo_destroy (cr); |
| 103 | |
| 104 | // create temp. clone of scratch surface |
| 105 | - dummy = cairo_image_surface_create_for_data ( |
| 106 | - cairo_image_surface_get_data (scratch), |
| 107 | - cairo_image_surface_get_format (scratch), |
| 108 | - 3 * scratch_shadow_size, |
| 109 | - 3 * scratch_shadow_size, |
| 110 | - cairo_image_surface_get_stride (scratch)); |
| 111 | - clone = copy_surface (dummy); |
| 112 | - cairo_surface_destroy (dummy); |
| 113 | + clone = copy_surface (scratch); |
| 114 | |
| 115 | // create normal surface from that surface-clone |
| 116 | - dummy = cairo_image_surface_create_for_data ( |
| 117 | - cairo_image_surface_get_data (clone), |
| 118 | - cairo_image_surface_get_format (clone), |
| 119 | - 2 * scratch_shadow_size, |
| 120 | - 2 * scratch_shadow_size, |
| 121 | - cairo_image_surface_get_stride (clone)); |
| 122 | - normal = copy_surface (dummy); |
| 123 | - cairo_surface_destroy (dummy); |
| 124 | + normal = copy_surface (clone); |
| 125 | |
| 126 | // now blur the surface-clone |
| 127 | blur = raico_blur_create (RAICO_BLUR_QUALITY_LOW); |
| 128 | @@ -783,30 +795,26 @@ |
| 129 | raico_blur_destroy (blur); |
| 130 | |
| 131 | // create blurred version from that blurred surface-clone |
| 132 | - dummy = cairo_image_surface_create_for_data ( |
| 133 | - cairo_image_surface_get_data (clone), |
| 134 | - cairo_image_surface_get_format (clone), |
| 135 | - 2 * scratch_shadow_size, |
| 136 | - 2 * scratch_shadow_size, |
| 137 | - cairo_image_surface_get_stride (clone)); |
| 138 | - blurred = copy_surface (dummy); |
| 139 | - cairo_surface_destroy (dummy); |
| 140 | - destroy_cloned_surface (clone); |
| 141 | + blurred = copy_surface (clone); |
| 142 | + cairo_surface_destroy (clone); |
| 143 | |
| 144 | // finally create tile with top-left shadow/background part |
| 145 | if (priv->tile_background_part) |
| 146 | tile_destroy (priv->tile_background_part); |
| 147 | - priv->tile_background_part = tile_new_for_padding (normal, blurred); |
| 148 | - destroy_cloned_surface (normal); |
| 149 | - destroy_cloned_surface (blurred); |
| 150 | + priv->tile_background_part = tile_new_for_padding (normal, blurred, |
| 151 | + 3 * scratch_shadow_size, |
| 152 | + 3 * scratch_shadow_size); |
| 153 | + cairo_surface_destroy (normal); |
| 154 | + cairo_surface_destroy (blurred); |
| 155 | |
| 156 | // create surface(s) for full shadow/background tile |
| 157 | if (priv->composited) |
| 158 | { |
| 159 | // we need two RGBA-surfaces |
| 160 | - normal = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
| 161 | - width, |
| 162 | - height); |
| 163 | + normal = bubble_create_image_surface (self, |
| 164 | + CAIRO_FORMAT_ARGB32, |
| 165 | + width, |
| 166 | + height); |
| 167 | if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS) |
| 168 | { |
| 169 | cairo_surface_destroy (scratch); |
| 170 | @@ -817,9 +825,10 @@ |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | - blurred = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
| 175 | - width, |
| 176 | - height); |
| 177 | + blurred = bubble_create_image_surface (self, |
| 178 | + CAIRO_FORMAT_ARGB32, |
| 179 | + width, |
| 180 | + height); |
| 181 | if (cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS) |
| 182 | { |
| 183 | cairo_surface_destroy (normal); |
| 184 | @@ -834,9 +843,10 @@ |
| 185 | else |
| 186 | { |
| 187 | // we need only one RGB-surface |
| 188 | - normal = cairo_image_surface_create (CAIRO_FORMAT_RGB24, |
| 189 | - width, |
| 190 | - height); |
| 191 | + normal = bubble_create_image_surface (self, |
| 192 | + CAIRO_FORMAT_RGB24, |
| 193 | + width, |
| 194 | + height); |
| 195 | if (cairo_surface_status (normal) != CAIRO_STATUS_SUCCESS) |
| 196 | { |
| 197 | cairo_surface_destroy (scratch); |
| 198 | @@ -921,9 +931,9 @@ |
| 199 | if (priv->tile_background) |
| 200 | tile_destroy (priv->tile_background); |
| 201 | if (priv->composited) |
| 202 | - priv->tile_background = tile_new_for_padding (normal, blurred); |
| 203 | + priv->tile_background = tile_new_for_padding (normal, blurred, width, height); |
| 204 | else |
| 205 | - priv->tile_background = tile_new_for_padding (normal, normal); |
| 206 | + priv->tile_background = tile_new_for_padding (normal, normal, width, height); |
| 207 | |
| 208 | // clean up |
| 209 | if (priv->composited) |
| 210 | @@ -936,16 +946,18 @@ |
| 211 | void |
| 212 | _refresh_icon (Bubble* self) |
| 213 | { |
| 214 | - BubblePrivate* priv = self->priv; |
| 215 | - Defaults* d = self->defaults; |
| 216 | - cairo_surface_t* normal = NULL; |
| 217 | - cairo_t* cr = NULL; |
| 218 | + BubblePrivate* priv = self->priv; |
| 219 | + Defaults* d = self->defaults; |
| 220 | + cairo_surface_t* normal = NULL; |
| 221 | + cairo_surface_t* icon_surface = NULL; |
| 222 | + cairo_t* cr = NULL; |
| 223 | |
| 224 | if (!priv->icon_pixbuf) |
| 225 | return; |
| 226 | |
| 227 | // create temp. scratch surface |
| 228 | - normal = cairo_image_surface_create ( |
| 229 | + normal = bubble_create_image_surface ( |
| 230 | + self, |
| 231 | CAIRO_FORMAT_ARGB32, |
| 232 | EM2PIXELS (defaults_get_icon_size (d), d) + |
| 233 | 2 * BUBBLE_CONTENT_BLUR_RADIUS, |
| 234 | @@ -969,10 +981,12 @@ |
| 235 | cairo_set_operator (cr, CAIRO_OPERATOR_OVER); |
| 236 | |
| 237 | // render icon into normal surface |
| 238 | - gdk_cairo_set_source_pixbuf (cr, |
| 239 | - priv->icon_pixbuf, |
| 240 | - BUBBLE_CONTENT_BLUR_RADIUS, |
| 241 | - BUBBLE_CONTENT_BLUR_RADIUS); |
| 242 | + icon_surface = gdk_cairo_surface_create_from_pixbuf (priv->icon_pixbuf, 0, |
| 243 | + gtk_widget_get_window (priv->widget)); |
| 244 | + cairo_set_source_surface (cr, |
| 245 | + icon_surface, |
| 246 | + BUBBLE_CONTENT_BLUR_RADIUS, |
| 247 | + BUBBLE_CONTENT_BLUR_RADIUS); |
| 248 | cairo_paint (cr); |
| 249 | |
| 250 | // create the surface/blur-cache from the normal surface |
| 251 | @@ -982,6 +996,7 @@ |
| 252 | |
| 253 | // clean up |
| 254 | cairo_destroy (cr); |
| 255 | + cairo_surface_destroy (icon_surface); |
| 256 | cairo_surface_destroy (normal); |
| 257 | } |
| 258 | |
| 259 | @@ -998,7 +1013,8 @@ |
| 260 | gchar* text_font_face = NULL; |
| 261 | |
| 262 | // create temp. scratch surface |
| 263 | - normal = cairo_image_surface_create ( |
| 264 | + normal = bubble_create_image_surface ( |
| 265 | + self, |
| 266 | CAIRO_FORMAT_ARGB32, |
| 267 | priv->title_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS, |
| 268 | priv->title_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS); |
| 269 | @@ -1106,7 +1122,8 @@ |
| 270 | gchar* text_font_face = NULL; |
| 271 | |
| 272 | // create temp. scratch surface |
| 273 | - normal = cairo_image_surface_create ( |
| 274 | + normal = bubble_create_image_surface ( |
| 275 | + self, |
| 276 | CAIRO_FORMAT_ARGB32, |
| 277 | priv->body_width + 2 * BUBBLE_CONTENT_BLUR_RADIUS, |
| 278 | priv->body_height + 2 * BUBBLE_CONTENT_BLUR_RADIUS); |
| 279 | @@ -1212,7 +1229,8 @@ |
| 280 | cairo_t* cr = NULL; |
| 281 | |
| 282 | // create temp. scratch surface |
| 283 | - normal = cairo_image_surface_create ( |
| 284 | + normal = bubble_create_image_surface ( |
| 285 | + self, |
| 286 | CAIRO_FORMAT_ARGB32, |
| 287 | EM2PIXELS (defaults_get_bubble_width (d), d) - |
| 288 | 3 * EM2PIXELS (defaults_get_margin_size (d), d) - |
| 289 | @@ -1810,13 +1828,15 @@ |
| 290 | |
| 291 | static |
| 292 | GdkPixbuf* |
| 293 | -load_icon (const gchar* filename, |
| 294 | +load_icon (Bubble* self, |
| 295 | + const gchar* filename, |
| 296 | gint icon_size) |
| 297 | { |
| 298 | GdkPixbuf* buffer = NULL; |
| 299 | GdkPixbuf* pixbuf = NULL; |
| 300 | GtkIconTheme* theme = NULL; |
| 301 | GError* error = NULL; |
| 302 | + gint scale; |
| 303 | |
| 304 | /* sanity check */ |
| 305 | g_return_val_if_fail (filename, NULL); |
| 306 | @@ -1825,25 +1845,28 @@ |
| 307 | if (!strncmp (filename, "file://", 7)) |
| 308 | filename += 7; |
| 309 | |
| 310 | + scale = gtk_widget_get_scale_factor (self->priv->widget); |
| 311 | + |
| 312 | if (filename[0] == '/') |
| 313 | { |
| 314 | /* load image into pixbuf */ |
| 315 | pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, |
| 316 | - icon_size, |
| 317 | - icon_size, |
| 318 | + scale * icon_size, |
| 319 | + scale * icon_size, |
| 320 | TRUE, |
| 321 | NULL); |
| 322 | } else { |
| 323 | /* TODO: rewrite, check for SVG support, raise apport |
| 324 | ** notification for low-res icons */ |
| 325 | theme = gtk_icon_theme_get_default (); |
| 326 | - buffer = gtk_icon_theme_load_icon (theme, |
| 327 | - filename, |
| 328 | - icon_size, |
| 329 | - GTK_ICON_LOOKUP_FORCE_SVG | |
| 330 | - GTK_ICON_LOOKUP_GENERIC_FALLBACK | |
| 331 | - GTK_ICON_LOOKUP_FORCE_SIZE, |
| 332 | - &error); |
| 333 | + buffer = gtk_icon_theme_load_icon_for_scale (theme, |
| 334 | + filename, |
| 335 | + icon_size, |
| 336 | + scale, |
| 337 | + GTK_ICON_LOOKUP_FORCE_SVG | |
| 338 | + GTK_ICON_LOOKUP_GENERIC_FALLBACK | |
| 339 | + GTK_ICON_LOOKUP_FORCE_SIZE, |
| 340 | + &error); |
| 341 | if (error) |
| 342 | { |
| 343 | g_print ("loading icon '%s' caused error: '%s'", |
| 344 | @@ -2431,7 +2454,8 @@ |
| 345 | } |
| 346 | |
| 347 | d = self->defaults; |
| 348 | - priv->icon_pixbuf = load_icon (filepath, |
| 349 | + priv->icon_pixbuf = load_icon (self, |
| 350 | + filepath, |
| 351 | EM2PIXELS (defaults_get_icon_size (d), d)); |
| 352 | |
| 353 | _refresh_icon (self); |
| 354 | @@ -2474,7 +2498,8 @@ |
| 355 | #ifdef TEMPORARY_ICON_PREFIX_WORKAROUND |
| 356 | notify_osd_iconname = g_strdup_printf (NOTIFY_OSD_ICON_PREFIX "-%s", |
| 357 | filename); |
| 358 | - priv->icon_pixbuf = load_icon (notify_osd_iconname, |
| 359 | + priv->icon_pixbuf = load_icon (self, |
| 360 | + notify_osd_iconname, |
| 361 | EM2PIXELS (defaults_get_icon_size (d), |
| 362 | d)); |
| 363 | g_free (notify_osd_iconname); |
| 364 | @@ -2482,7 +2507,8 @@ |
| 365 | |
| 366 | // fallback to non-notify-osd name |
| 367 | if (!priv->icon_pixbuf) |
| 368 | - priv->icon_pixbuf = load_icon (filename, |
| 369 | + priv->icon_pixbuf = load_icon (self, |
| 370 | + filename, |
| 371 | EM2PIXELS (defaults_get_icon_size (d), d)); |
| 372 | |
| 373 | _refresh_icon (self); |
| 374 | @@ -3224,7 +3250,7 @@ |
| 375 | d = self->defaults; |
| 376 | priv = self->priv; |
| 377 | |
| 378 | - surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1); |
| 379 | + surface = bubble_create_image_surface (self, CAIRO_FORMAT_A1, 1, 1); |
| 380 | if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { |
| 381 | if (surface) |
| 382 | cairo_surface_destroy (surface); |
| 383 | @@ -3418,6 +3444,7 @@ |
| 384 | EM2PIXELS (defaults_get_icon_size (d), d), |
| 385 | EM2PIXELS (defaults_get_icon_size (d), d), |
| 386 | GDK_INTERP_BILINEAR); |
| 387 | + g_message ("resizing pixbuf to %d", EM2PIXELS (defaults_get_icon_size (d), d) ); |
| 388 | g_object_unref (priv->icon_pixbuf); |
| 389 | priv->icon_pixbuf = pixbuf; |
| 390 | } |
| 391 | |
| 392 | === modified file 'src/raico-blur.c' |
| 393 | --- src/raico-blur.c 2009-11-05 03:13:20 +0000 |
| 394 | +++ src/raico-blur.c 2015-09-02 14:41:24 +0000 |
| 395 | @@ -112,6 +112,9 @@ |
| 396 | cairo_surface_t* surface) |
| 397 | { |
| 398 | cairo_format_t format; |
| 399 | + double x_scale; |
| 400 | + double y_scale; |
| 401 | + guint radius; |
| 402 | |
| 403 | // sanity checks |
| 404 | if (!blur) |
| 405 | @@ -151,20 +154,27 @@ |
| 406 | if (blur->priv->radius == 0) |
| 407 | return; |
| 408 | |
| 409 | + /* adjust radius for device scale. We don't support blurring |
| 410 | + * different amounts in x and y, so just use the mean value |
| 411 | + * between cairo's respective device scales (in practice they |
| 412 | + * should always be the same). */ |
| 413 | + cairo_surface_get_device_scale (surface, &x_scale, &y_scale); |
| 414 | + radius = blur->priv->radius * 0.5 * (x_scale + y_scale); |
| 415 | + |
| 416 | // now do the real work |
| 417 | switch (blur->priv->quality) |
| 418 | { |
| 419 | case RAICO_BLUR_QUALITY_LOW: |
| 420 | - surface_exponential_blur (surface, blur->priv->radius); |
| 421 | + surface_exponential_blur (surface, radius); |
| 422 | break; |
| 423 | |
| 424 | case RAICO_BLUR_QUALITY_MEDIUM: |
| 425 | //surface_stack_blur (surface, blur->priv->radius); |
| 426 | - surface_gaussian_blur (surface, blur->priv->radius); |
| 427 | + surface_gaussian_blur (surface, radius); |
| 428 | break; |
| 429 | |
| 430 | case RAICO_BLUR_QUALITY_HIGH: |
| 431 | - surface_gaussian_blur (surface, blur->priv->radius); |
| 432 | + surface_gaussian_blur (surface, radius); |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | === modified file 'src/tile.c' |
| 438 | --- src/tile.c 2010-12-06 00:17:02 +0000 |
| 439 | +++ src/tile.c 2015-09-02 14:41:24 +0000 |
| 440 | @@ -76,7 +76,9 @@ |
| 441 | |
| 442 | tile_t* |
| 443 | tile_new_for_padding (cairo_surface_t* normal, |
| 444 | - cairo_surface_t* blurred) |
| 445 | + cairo_surface_t* blurred, |
| 446 | + gint width, |
| 447 | + gint height) |
| 448 | { |
| 449 | tile_private_t* priv = NULL; |
| 450 | tile_t* tile = NULL; |
| 451 | @@ -93,20 +95,14 @@ |
| 452 | cairo_surface_status (blurred) != CAIRO_STATUS_SUCCESS) |
| 453 | return NULL; |
| 454 | |
| 455 | - if (cairo_image_surface_get_width (normal) != |
| 456 | - cairo_image_surface_get_width (blurred) && |
| 457 | - cairo_image_surface_get_height (normal) != |
| 458 | - cairo_image_surface_get_height (blurred)) |
| 459 | - return NULL; |
| 460 | - |
| 461 | tile->priv = priv; |
| 462 | |
| 463 | tile->priv->normal = copy_surface (normal); |
| 464 | tile->priv->blurred = copy_surface (blurred); |
| 465 | tile->priv->blur_radius = 0; |
| 466 | tile->priv->use_padding = TRUE; |
| 467 | - tile->priv->pad_width = cairo_image_surface_get_width (normal); |
| 468 | - tile->priv->pad_height = cairo_image_surface_get_height (normal); |
| 469 | + tile->priv->pad_width = width; |
| 470 | + tile->priv->pad_height = height; |
| 471 | |
| 472 | return tile; |
| 473 | } |
| 474 | @@ -120,8 +116,8 @@ |
| 475 | //cairo_surface_write_to_png (tile->priv->normal, "./tile-normal.png"); |
| 476 | //cairo_surface_write_to_png (tile->priv->blurred, "./tile-blurred.png"); |
| 477 | |
| 478 | - destroy_cloned_surface (tile->priv->normal); |
| 479 | - destroy_cloned_surface (tile->priv->blurred); |
| 480 | + cairo_surface_destroy (tile->priv->normal); |
| 481 | + cairo_surface_destroy (tile->priv->blurred); |
| 482 | |
| 483 | g_free ((gpointer) tile->priv); |
| 484 | g_free ((gpointer) tile); |
| 485 | |
| 486 | === modified file 'src/tile.h' |
| 487 | --- src/tile.h 2009-07-14 14:11:40 +0000 |
| 488 | +++ src/tile.h 2015-09-02 14:41:24 +0000 |
| 489 | @@ -44,7 +44,9 @@ |
| 490 | |
| 491 | tile_t* |
| 492 | tile_new_for_padding (cairo_surface_t* normal, |
| 493 | - cairo_surface_t* blurred); |
| 494 | + cairo_surface_t* blurred, |
| 495 | + gint width, |
| 496 | + gint height); |
| 497 | |
| 498 | void |
| 499 | tile_destroy (tile_t* tile); |
| 500 | |
| 501 | === modified file 'src/util.c' |
| 502 | --- src/util.c 2009-10-25 06:00:23 +0000 |
| 503 | +++ src/util.c 2015-09-02 14:41:24 +0000 |
| 504 | @@ -139,51 +139,30 @@ |
| 505 | return text1; |
| 506 | } |
| 507 | |
| 508 | -gboolean |
| 509 | -destroy_cloned_surface (cairo_surface_t* surface) |
| 510 | -{ |
| 511 | - gboolean finalref = FALSE; |
| 512 | - g_return_val_if_fail (surface, FALSE); |
| 513 | - |
| 514 | - if (cairo_surface_get_reference_count (surface) == 1) { |
| 515 | - g_free (cairo_image_surface_get_data (surface)); |
| 516 | - finalref = TRUE; |
| 517 | - } |
| 518 | - cairo_surface_destroy (surface); |
| 519 | - return finalref; |
| 520 | -} |
| 521 | - |
| 522 | cairo_surface_t* |
| 523 | copy_surface (cairo_surface_t* orig) |
| 524 | { |
| 525 | cairo_surface_t* copy = NULL; |
| 526 | - guchar* pixels_src = NULL; |
| 527 | - guchar* pixels_cpy = NULL; |
| 528 | cairo_format_t format; |
| 529 | gint width; |
| 530 | gint height; |
| 531 | - gint stride; |
| 532 | - |
| 533 | - pixels_src = cairo_image_surface_get_data (orig); |
| 534 | - if (!pixels_src) |
| 535 | - return NULL; |
| 536 | - |
| 537 | - format = cairo_image_surface_get_format (orig); |
| 538 | + cairo_t* cr; |
| 539 | + double x_scale; |
| 540 | + double y_scale; |
| 541 | + |
| 542 | width = cairo_image_surface_get_width (orig); |
| 543 | height = cairo_image_surface_get_height (orig); |
| 544 | - stride = cairo_image_surface_get_stride (orig); |
| 545 | - |
| 546 | - pixels_cpy = g_malloc0 (stride * height); |
| 547 | - if (!pixels_cpy) |
| 548 | - return NULL; |
| 549 | - |
| 550 | - memcpy ((void*) pixels_cpy, (void*) pixels_src, height * stride); |
| 551 | - |
| 552 | - copy = cairo_image_surface_create_for_data (pixels_cpy, |
| 553 | - format, |
| 554 | - width, |
| 555 | - height, |
| 556 | - stride); |
| 557 | + format = cairo_image_surface_get_format (orig); |
| 558 | + cairo_surface_get_device_scale (orig, &x_scale, &y_scale); |
| 559 | + |
| 560 | + copy = cairo_surface_create_similar_image (orig, format, width, height); |
| 561 | + cairo_surface_set_device_scale (copy, x_scale, y_scale); |
| 562 | + |
| 563 | + cr = cairo_create (copy); |
| 564 | + cairo_set_source_surface (cr, orig, 0, 0); |
| 565 | + cairo_paint (cr); |
| 566 | + |
| 567 | + cairo_destroy (cr); |
| 568 | |
| 569 | return copy; |
| 570 | } |
| 571 | |
| 572 | === modified file 'src/util.h' |
| 573 | --- src/util.h 2009-10-25 06:00:23 +0000 |
| 574 | +++ src/util.h 2015-09-02 14:41:24 +0000 |
| 575 | @@ -46,9 +46,6 @@ |
| 576 | cairo_surface_t* |
| 577 | copy_surface (cairo_surface_t* orig); |
| 578 | |
| 579 | -gboolean |
| 580 | -destroy_cloned_surface (cairo_surface_t* surface); |
| 581 | - |
| 582 | gchar* |
| 583 | get_wm_name (Display* dpy); |
| 584 | |
| 585 | |
| 586 | === modified file 'tests/test-grow-bubble.c' |
| 587 | --- tests/test-grow-bubble.c 2014-12-20 18:39:52 +0000 |
| 588 | +++ tests/test-grow-bubble.c 2015-09-02 14:41:24 +0000 |
| 589 | @@ -651,7 +651,7 @@ |
| 590 | cairo_surface_destroy (tmp); |
| 591 | cairo_surface_destroy (dummy_surf); |
| 592 | |
| 593 | - g_tile = tile_new_for_padding (norm_surf, blur_surf); |
| 594 | + g_tile = tile_new_for_padding (norm_surf, blur_surf, width, height); |
| 595 | cairo_surface_destroy (norm_surf); |
| 596 | cairo_surface_destroy (blur_surf); |
| 597 | |
| 598 | |
| 599 | === modified file 'tests/test-scroll-text.c' |
| 600 | --- tests/test-scroll-text.c 2014-12-20 18:39:52 +0000 |
| 601 | +++ tests/test-scroll-text.c 2015-09-02 14:41:24 +0000 |
| 602 | @@ -826,10 +826,10 @@ |
| 603 | cairo_surface_destroy (tmp); |
| 604 | |
| 605 | // actually create the tile with padding in mind |
| 606 | - tile = tile_new_for_padding (norm_surf, blur_surf); |
| 607 | - destroy_cloned_surface (norm_surf); |
| 608 | - destroy_cloned_surface (blur_surf); |
| 609 | - destroy_cloned_surface (dummy_surf); |
| 610 | + tile = tile_new_for_padding (norm_surf, blur_surf, width, height); |
| 611 | + cairo_surface_destroy (norm_surf); |
| 612 | + cairo_surface_destroy (blur_surf); |
| 613 | + cairo_surface_destroy (dummy_surf); |
| 614 | |
| 615 | cairo_destroy (cr); |
| 616 | cairo_surface_destroy (cr_surf); |
| 617 | @@ -852,7 +852,7 @@ |
| 618 | tile_paint_with_padding (tile, cr, 0.0f, 0.0f, w, h, 0.0f, 1.0f); |
| 619 | cairo_destroy (cr); |
| 620 | |
| 621 | - g_tile = tile_new_for_padding (norm_surf, blur_surf); |
| 622 | + g_tile = tile_new_for_padding (norm_surf, blur_surf, width, height); |
| 623 | |
| 624 | // clean up |
| 625 | tile_destroy (tile); |


Reviewed and tested it. Looking good.