/*
7 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
9 * Copyright (C) 2011 Authors
10 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
46 , _device_scale(device_scale)
61 , _origin(logbox.min())
64 , _device_scale(device_scale)
79 cairo_surface_reference(
surface);
83 cairo_surface_get_device_scale(
surface, &x_scale, &y_scale);
84 if (x_scale != y_scale) {
85 std::cerr <<
"DrawingSurface::DrawingSurface: non-uniform device scale!" << std::endl;
117 _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
139 , _clean_region(cairo_region_create())
140 , _pending_area(area)
178 bool is_integer_translation = is_identity;
182 is_integer_translation =
true;
204 if (is_integer_translation) {
210 cairo_set_source_surface(ct, old_surface, old_origin.
x(), old_origin.
y());
211 cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE);
212 cairo_pattern_set_filter(cairo_get_source(ct), CAIRO_FILTER_NEAREST);
225 cairo_surface_destroy(old_surface);
243 cairo_region_t *dirty_region = cairo_region_create_rectangle(&area_c);
247 if (is_filter && !cairo_region_is_empty(dirty_region)) {
248 cairo_region_destroy(cache_region);
249 cairo_region_destroy(dirty_region);
255 if (cairo_region_is_empty(dirty_region)) {
258 cairo_rectangle_int_t to_repaint;
259 cairo_region_get_extents(dirty_region, &to_repaint);
261 cairo_region_subtract_rectangle(cache_region, &to_repaint);
263 cairo_region_destroy(dirty_region);
265 if (!cairo_region_is_empty(cache_region)) {
266 int nr = cairo_region_num_rectangles(cache_region);
267 for (
int i = 0; i < nr; ++i) {
268 cairo_rectangle_int_t tmp;
269 cairo_region_get_rectangle(cache_region, i, &tmp);
275 cairo_region_destroy(cache_region);
281 static int dumpnr = 0;
287 cairo_rectangle_int_t tmp;
288 for (
int i = 0; i < nr; ++i) {
298 char *fn = g_strdup_printf(
"dump%d.png", dumpnr++);
299 cairo_surface_write_to_png(
surface, fn);
300 cairo_surface_destroy(
surface);
void ink_cairo_transform(cairo_t *ct, Geom::Affine const &m)
cairo_surface_t * ink_cairo_surface_copy(cairo_surface_t *s)
Create an exact copy of a surface.
Cairo integration helpers.
Cairo::RefPtr< Cairo::ImageSurface > surface
Cairo::RefPtr< Cairo::Region > clean
3x3 matrix representing an affine transformation.
Point translation() const
Gets the translation imparted by the Affine.
bool isIdentity(Coord eps=EPSILON) const
Check whether this matrix is an identity matrix.
void setIdentity()
Sets this matrix to be the Identity Affine.
bool isTranslation(Coord eps=EPSILON) const
Check whether this matrix represents a pure translation.
Axis-aligned generic rectangle that can be empty.
Axis aligned, non-empty, generic rectangle.
static CRect from_xywh(C x, C y, C w, C h)
Create rectangle from origin and dimensions.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint dimensions() const
Get rectangle's width and height as a point.
Two-dimensional point with integer coordinates.
constexpr IntCoord x() const noexcept
constexpr IntCoord y() const noexcept
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
IntPoint round() const
Round to nearest integer coordinates.
Axis aligned, non-empty rectangle.
DrawingCache(Geom::IntRect const &area, int device_scale=1)
void markDirty(Geom::IntRect const &area=Geom::IntRect::infinite())
void prepare()
Transforms the cache according to the transform specified during the update phase.
void paintFromCache(DrawingContext &dc, Geom::OptIntRect &area, bool is_filter)
Paints the clean area from cache and modifies the area parameter to the bounds of the region that mus...
void scheduleTransform(Geom::IntRect const &new_area, Geom::Affine const &trans)
Call this during the update phase to schedule a transformation of the cache.
Geom::Affine _pending_transform
void _dumpCache(Geom::OptIntRect const &area)
void markClean(Geom::IntRect const &area=Geom::IntRect::infinite())
cairo_region_t * _clean_region
Geom::IntRect _pending_area
RAII idiom for saving the state of DrawingContext.
Minimal wrapper over Cairo.
void setSource(cairo_pattern_t *source)
void rectangle(Geom::Rect const &r)
Drawing surface that remembers its origin.
virtual ~DrawingSurface()
void dropContents()
Drop contents of the surface and release the underlying Cairo object.
Geom::IntRect pixelArea() const
cairo_t * createRawContext()
Create a drawing context for this surface.
DrawingSurface(Geom::IntRect const &area, int device_scale=1)
Creates a surface with the given physical extents.
Geom::Rect area() const
Get the logical extents of the surface.
cairo_surface_t * _surface
Cairo drawing context with Inkscape extensions.
Cairo surface that remembers its origin.
struct _cairo_surface cairo_surface_t
struct _cairo_region cairo_region_t
GenericOptRect< IntCoord > OptIntRect
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Helper class to stream background task notifications as a series of messages.
Cairo::RectangleInt geom_to_cairo(const Geom::IntRect &rect)
Geom::IntRect cairo_to_geom(const Cairo::RectangleInt &rect)
Geom::IntPoint dimensions(const Cairo::RefPtr< Cairo::ImageSurface > &surface)