drawing-surface.cpp revision 9194eb2e10d1cb7c67ed26b037755b4e09c90c1b
/**
* @file
* Cairo surface that remembers its origin.
*//*
* Authors:
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2011 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
//#include <iostream>
#include "display/drawing-surface.h"
#include "display/drawing-context.h"
#include "display/cairo-utils.h"
namespace Inkscape {
using Geom::X;
using Geom::Y;
/**
* @class DrawingSurface
* Drawing surface that remembers its origin.
*
* This is a very minimalistic wrapper over cairo_surface_t. The main
* extra functionality provided by this class is that it automates
* the mapping from "logical space" (coordinates in the rendering)
* and the "physical space" (surface pixels). For example, patterns
* have to be rendered on tiles which have possibly non-integer
* widths and heights.
*
* This class has delayed allocation functionality - it creates
* the Cairo surface it wraps on the first call to createRawContext()
* of when a DrawingContext is constructed.
*/
/**
* Creates a surface with the given physical extents.
* When a drawing context is created for this surface, its pixels
* will cover the area under the given rectangle.
*/
{}
/**
* Creates a surface with the given logical and physical extents.
* When a drawing context is created for this surface, its pixels
* will cover the area under the given rectangle. IT will contain
* the number of pixels specified by the second argument.
* @param logbox Logical extents of the surface
* @param pixdims Pixel dimensions of the surface.
*/
{}
/**
* Wrap a cairo_surface_t.
* This constructor will take an extra reference on @a surface, which will
* be released on destruction.
*/
{
}
{
if (_surface)
}
/// Get the logical extents of the surface.
DrawingSurface::area() const
{
return r;
}
/// Get the pixel dimensions of the surface
DrawingSurface::pixels() const
{
return _pixels;
}
/// Get the logical width and weight of the surface as a point.
DrawingSurface::dimensions() const
{
return logical_dims;
}
DrawingSurface::origin() const
{
return _origin;
}
DrawingSurface::scale() const
{
return _scale;
}
/// Get the transformation applied to the drawing context on construction.
DrawingSurface::drawingTransform() const
{
return ret;
}
DrawingSurface::type() const
{
// currently hardcoded
return CAIRO_SURFACE_TYPE_IMAGE;
}
/// Drop contents of the surface and release the underlying Cairo object.
void
{
if (_surface) {
}
}
/**
* Create a drawing context for this surface.
* It's better to use the surface constructor of DrawingContext.
*/
cairo_t *
{
// deferred allocation
if (!_surface) {
}
}
return ct;
}
DrawingSurface::pixelArea() const
{
return ret;
}
//////////////////////////////////////////////////////////////////////////////
{}
{
}
void
{
}
void
{
if (!r) return;
}
/// Call this during the update phase to schedule a transformation of the cache.
void
{
}
/// Transforms the cache according to the transform specified during the update phase.
/// Call this during render phase, before painting.
void
{
bool is_integer_translation = false;
is_integer_translation = true;
cairo_region_translate(_clean_region, t[X], t[Y]);
if (old_area + t == _pending_area) {
// if the areas match, the only thing to do
// is to ensure that the clean area is not too large
_origin += t;
return;
}
}
}
// otherwise, we need to transform the cache
if (!is_identity) {
}
if (!is_identity && !is_integer_translation) {
// dirty everything
} else {
}
//std::cout << _pending_transform << old_area << _pending_area << std::endl;
}
/**
* Paints the clean area from cache and modifies the @a area
* parameter to the bounds of the region that must be repainted.
*/
void
{
if (!area) return;
// We subtract the clean region from the area, then get the bounds
// of the resulting region. This is the area that needs to be repainted
// by the item.
// Then we subtract the area that needs to be repainted from the
// original area and paint the resulting region from cache.
if (cairo_region_is_empty(dirty_region)) {
} else {
}
if (!cairo_region_is_empty(cache_region)) {
for (int i = 0; i < nr; ++i) {
}
}
}
// debugging utility
void
{
static int dumpnr = 0;
if (!cairo_region_is_empty(_clean_region)) {
for (int i = 0; i < nr; ++i) {
}
}
}
{
return ret;
}
{
r.x, r.y,
return ret;
}
} // end namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :