Skip to content

Commit 929b91c

Browse files
committed
try our own tile snapping
1 parent 887070f commit 929b91c

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/imagedisplay.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,16 @@ imagedisplay_snapshot(GtkWidget *widget, GtkSnapshot *snapshot)
666666
paint.size.width = imagedisplay->paint_rect.width;
667667
paint.size.height = imagedisplay->paint_rect.height;
668668

669+
/* Used for tile snapping if there's no gtk snapshot system.
670+
*/
671+
GtkNative *native = gtk_widget_get_native(widget);
672+
GdkSurface *surface = gtk_native_get_surface(native);
673+
double scale_factor = gdk_surface_get_scale_factor(surface);
674+
669675
if (imagedisplay->tilecache &&
670676
imagedisplay->tilecache->n_levels > 0)
671677
tilecache_snapshot(imagedisplay->tilecache, snapshot,
678+
scale_factor,
672679
imagedisplay->scale, imagedisplay->x, imagedisplay->y,
673680
&paint, imagedisplay->debug);
674681

src/tilecache.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,15 +835,41 @@ tilecache_draw_bounds(GtkSnapshot *snapshot,
835835
}
836836
}
837837

838+
#ifndef HAVE_GTK_SNAPSHOT_SET_SNAP
839+
/* Snap a graphene rect to a hardware pixel boundary on the output surface. We
840+
* need to do this if the gtk snap mechachanism is missing or we'll get thin
841+
* white lines on tile edges.
842+
*/
843+
static void
844+
tilecache_snap_rect_to_boundary(graphene_rect_t *bounds, double scale)
845+
{
846+
double left = rint(bounds->origin.x * scale) / scale;
847+
double top = rint(bounds->origin.y * scale) / scale;
848+
double right =
849+
rint((bounds->origin.x + bounds->size.width) * scale) / scale;
850+
double bottom =
851+
rint((bounds->origin.y + bounds->size.height) * scale) / scale;
852+
853+
bounds->origin.x = left;
854+
bounds->origin.y = top;
855+
bounds->size.width = right - left;
856+
bounds->size.height = bottom - top;
857+
}
858+
#endif /*!HAVE_GTK_SNAPSHOT_SET_SNAP*/
859+
838860
/* Scale is how much the level0 image has been scaled, x/y is the position of
839-
* the top-left corner of the paint_rect area in the scaled image.
861+
* the top-left corner of @paint in the scaled image.
862+
*
863+
* @pixel_scale is gdk_surface_get_scale() for the surface this snapshot will
864+
* be rendered to.
840865
*
841-
* paint_rect is the pixel area in gtk coordinates that we paint in the widget.
866+
* @paint is the pixel area in gtk coordinates that we paint in the widget.
842867
*
843868
* Set debug to draw tile boundaries for debugging.
844869
*/
845870
void
846871
tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
872+
double scale_factor,
847873
double scale, double x, double y, graphene_rect_t *paint, gboolean debug)
848874
{
849875
/* In debug mode, scale and offset so we can see tile clipping.
@@ -947,11 +973,9 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
947973
bounds.size.height = tile->bounds0.height * scale;
948974

949975
#ifndef HAVE_GTK_SNAPSHOT_SET_SNAP
950-
/* Without set snap, we have to hide tile edges by expanding the
951-
* tile.
976+
/* Without gtk snap, we have to snap tiles edges ourselves.
952977
*/
953-
bounds.size.width += 1;
954-
bounds.size.height += 1;
978+
tilecache_snap_rect_to_boundary(&bounds, scale_factor);
955979
#endif /*!HAVE_GTK_SNAPSHOT_SET_SNAP*/
956980

957981
gtk_snapshot_append_scaled_texture(snapshot,

src/tilecache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Tilecache *tilecache_new();
110110
/* Render the tiles to a snapshot.
111111
*/
112112
void tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
113+
double scale_factor,
113114
double scale, double x, double y, graphene_rect_t *paint, gboolean debug);
114115

115116
#endif /*__TILECACHE_H*/

0 commit comments

Comments
 (0)