summaryrefslogtreecommitdiffstats
path: root/src/display/drawing-surface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/display/drawing-surface.cpp')
-rw-r--r--src/display/drawing-surface.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/display/drawing-surface.cpp b/src/display/drawing-surface.cpp
index d2540de66..2752789e2 100644
--- a/src/display/drawing-surface.cpp
+++ b/src/display/drawing-surface.cpp
@@ -41,12 +41,15 @@ using Geom::Y;
* When a drawing context is created for this surface, its pixels
* will cover the area under the given rectangle.
*/
-DrawingSurface::DrawingSurface(Geom::IntRect const &area)
+DrawingSurface::DrawingSurface(Geom::IntRect const &area, int device_scale)
: _surface(NULL)
, _origin(area.min())
, _scale(1, 1)
, _pixels(area.dimensions())
-{}
+ , _device_scale(device_scale)
+{
+ assert(_device_scale > 0);
+}
/**
* Creates a surface with the given logical and physical extents.
@@ -56,12 +59,15 @@ DrawingSurface::DrawingSurface(Geom::IntRect const &area)
* @param logbox Logical extents of the surface
* @param pixdims Pixel dimensions of the surface.
*/
-DrawingSurface::DrawingSurface(Geom::Rect const &logbox, Geom::IntPoint const &pixdims)
+DrawingSurface::DrawingSurface(Geom::Rect const &logbox, Geom::IntPoint const &pixdims, int device_scale)
: _surface(NULL)
, _origin(logbox.min())
, _scale(pixdims[X] / logbox.width(), pixdims[Y] / logbox.height())
, _pixels(pixdims)
-{}
+ , _device_scale(device_scale)
+{
+ assert(_device_scale > 0);
+}
/**
* Wrap a cairo_surface_t.
@@ -74,8 +80,18 @@ DrawingSurface::DrawingSurface(cairo_surface_t *surface, Geom::Point const &orig
, _scale(1, 1)
{
cairo_surface_reference(surface);
- _pixels[X] = cairo_image_surface_get_width(surface);
- _pixels[Y] = cairo_image_surface_get_height(surface);
+
+ double x_scale = 0;
+ double y_scale = 0;
+ cairo_surface_get_device_scale( surface, &x_scale, &y_scale);
+ if (x_scale != y_scale) {
+ std::cerr << "DrawingSurface::DrawingSurface: non-uniform device scale!" << std::endl;
+ }
+ _device_scale = x_scale;
+ assert(_device_scale > 0);
+
+ _pixels[X] = cairo_image_surface_get_width(surface)/_device_scale;
+ _pixels[Y] = cairo_image_surface_get_height(surface)/_device_scale;
}
DrawingSurface::~DrawingSurface()
@@ -119,6 +135,13 @@ DrawingSurface::scale() const
return _scale;
}
+/// Device scale for HiDPI screens
+int
+DrawingSurface::device_scale() const
+{
+ return _device_scale;
+}
+
/// Get the transformation applied to the drawing context on construction.
Geom::Affine
DrawingSurface::drawingTransform() const
@@ -153,7 +176,10 @@ DrawingSurface::createRawContext()
{
// deferred allocation
if (!_surface) {
- _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, _pixels[X], _pixels[Y]);
+ _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ _pixels[X] * _device_scale,
+ _pixels[Y] * _device_scale);
+ cairo_surface_set_device_scale(_surface, _device_scale, _device_scale);
}
cairo_t *ct = cairo_create(_surface);
if (_scale != Geom::Scale::identity()) {
@@ -172,8 +198,8 @@ DrawingSurface::pixelArea() const
//////////////////////////////////////////////////////////////////////////////
-DrawingCache::DrawingCache(Geom::IntRect const &area)
- : DrawingSurface(area)
+DrawingCache::DrawingCache(Geom::IntRect const &area, int device_scale)
+ : DrawingSurface(area, device_scale)
, _clean_region(cairo_region_create())
, _pending_area(area)
{}