[cairo] [PATCH 37/71] drm: generalized *_map_to_image() functions
Enrico Weigelt, metux IT consult
enrico.weigelt at gr13.net
Mon Apr 17 16:57:16 UTC 2017
This function essentially creates an underlying image surface
(if not existing yet) and maps it to the underlying framebuffer.
The only device specific part here is actually mapping in the actual
BO (as long as we dont have an generic libdrm call / ioctl() for that).
As we already introduced the bo_map() vector in cairo_drm_device_t,
this function can be made generic, so all device specific backends
can just call it, instead of their own duplicated implementations.
In a later step, we can generalize thse surface ops, which just
proxy onto the image surface.
Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
src/drm/cairo-drm-i915-surface.c | 2 +-
src/drm/cairo-drm-intel-private.h | 2 --
src/drm/cairo-drm-intel-surface.c | 48 +++++---------------------------------
src/drm/cairo-drm-private.h | 3 +++
src/drm/cairo-drm-radeon-surface.c | 46 ++++--------------------------------
src/drm/cairo-drm-surface.c | 39 +++++++++++++++++++++++++++++++
6 files changed, 54 insertions(+), 86 deletions(-)
diff --git a/src/drm/cairo-drm-i915-surface.c b/src/drm/cairo-drm-i915-surface.c
index 3f8004b35..dd8ef012b 100644
--- a/src/drm/cairo-drm-i915-surface.c
+++ b/src/drm/cairo-drm-i915-surface.c
@@ -2928,7 +2928,7 @@ _cairo_drm_i915_device_create (int fd, dev_t dev_id, int vendor_id, int chip_id)
device->intel.base.surface.flink = _cairo_drm_surface_flink;
device->intel.base.surface.enable_scan_out = i915_surface_enable_scan_out;
- device->intel.base.surface.map_to_image = intel_surface_map_to_image;
+ device->intel.base.surface.map_to_image = _cairo_drm_surface_map_to_image;
device->intel.base.device.flush = i915_device_flush;
device->intel.base.device.throttle = i915_device_throttle;
diff --git a/src/drm/cairo-drm-intel-private.h b/src/drm/cairo-drm-intel-private.h
index 4d3b7c1c6..ace9742e8 100644
--- a/src/drm/cairo-drm-intel-private.h
+++ b/src/drm/cairo-drm-intel-private.h
@@ -438,8 +438,6 @@ cairo_private void
intel_surface_release_source_image (void *abstract_surface,
cairo_image_surface_t *image,
void *image_extra);
-cairo_private cairo_surface_t *
-intel_surface_map_to_image (void *abstract_surface);
cairo_private cairo_status_t
intel_surface_flush (void *abstract_surface,
diff --git a/src/drm/cairo-drm-intel-surface.c b/src/drm/cairo-drm-intel-surface.c
index 356dc4a4f..0c61ca0f2 100644
--- a/src/drm/cairo-drm-intel-surface.c
+++ b/src/drm/cairo-drm-intel-surface.c
@@ -124,42 +124,6 @@ intel_surface_release_source_image (void *abstract_surface,
cairo_surface_destroy (&image->base);
}
-cairo_surface_t *
-intel_surface_map_to_image (void *abstract_surface)
-{
- intel_surface_t *surface = cairo_abstract_surface_cast_intel(abstract_surface);
-
- if (surface->drm.fallback == NULL) {
- cairo_surface_t *image;
- cairo_status_t status;
- void *ptr;
-
- if (surface->drm.base.backend->flush != NULL) {
- status = surface->drm.base.backend->flush (surface, 0);
- if (unlikely (status))
- return _cairo_surface_create_in_error (status);
- }
-
- ptr = intel_bo_map (_cairo_intel_surface_get_device (surface),
- _cairo_intel_surface_get_bo (surface));
-
- if (unlikely (ptr == NULL))
- return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
-
- image = cairo_image_surface_create_for_data (ptr,
- surface->drm.format,
- surface->drm.width,
- surface->drm.height,
- surface->drm.stride);
- if (unlikely (image->status))
- return image;
-
- surface->drm.fallback = image;
- }
-
- return surface->drm.fallback;
-}
-
cairo_status_t
intel_surface_flush (void *abstract_surface, unsigned flags)
{
@@ -188,7 +152,7 @@ intel_surface_paint (void *abstract_surface,
const cairo_pattern_t *source,
const cairo_clip_t *clip)
{
- return _cairo_surface_paint (intel_surface_map_to_image (abstract_surface),
+ return _cairo_surface_paint (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, clip);
}
@@ -199,7 +163,7 @@ intel_surface_mask (void *abstract_surface,
const cairo_pattern_t *mask,
const cairo_clip_t *clip)
{
- return _cairo_surface_mask (intel_surface_map_to_image (abstract_surface),
+ return _cairo_surface_mask (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, mask, clip);
}
@@ -215,7 +179,7 @@ intel_surface_stroke (void *abstract_surface,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
- return _cairo_surface_stroke (intel_surface_map_to_image (abstract_surface),
+ return _cairo_surface_stroke (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, path, stroke_style, ctm, ctm_inverse,
tolerance, antialias, clip);
}
@@ -230,7 +194,7 @@ intel_surface_fill (void *abstract_surface,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
- return _cairo_surface_fill (intel_surface_map_to_image (abstract_surface),
+ return _cairo_surface_fill (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, path, fill_rule,
tolerance, antialias, clip);
}
@@ -244,7 +208,7 @@ intel_surface_glyphs (void *abstract_surface,
cairo_scaled_font_t *scaled_font,
const cairo_clip_t *clip)
{
- return _cairo_surface_show_text_glyphs (intel_surface_map_to_image (abstract_surface),
+ return _cairo_surface_show_text_glyphs (_cairo_drm_surface_map_to_image (abstract_surface),
op, source,
NULL, 0,
glyphs, num_glyphs,
@@ -426,7 +390,7 @@ _cairo_drm_intel_device_create (int fd, dev_t dev, int vendor_id, int chip_id)
device->base.surface.flink = _cairo_drm_surface_flink;
device->base.surface.enable_scan_out = intel_surface_enable_scan_out;
- device->base.surface.map_to_image = intel_surface_map_to_image;
+ device->base.surface.map_to_image = _cairo_drm_surface_map_to_image;
device->base.device.flush = NULL;
device->base.device.throttle = intel_device_throttle;
diff --git a/src/drm/cairo-drm-private.h b/src/drm/cairo-drm-private.h
index 90cd54c94..b7fd9bdf9 100644
--- a/src/drm/cairo-drm-private.h
+++ b/src/drm/cairo-drm-private.h
@@ -317,6 +317,9 @@ _cairo_drm_device_init (cairo_drm_device_t *device,
cairo_private void
_cairo_drm_device_fini (cairo_drm_device_t *device);
+cairo_private cairo_surface_t *
+_cairo_drm_surface_map_to_image (void *abstract_surface);
+
/* h/w specific backends */
cairo_private cairo_drm_device_t *
diff --git a/src/drm/cairo-drm-radeon-surface.c b/src/drm/cairo-drm-radeon-surface.c
index 0a1f27cba..c941e877b 100644
--- a/src/drm/cairo-drm-radeon-surface.c
+++ b/src/drm/cairo-drm-radeon-surface.c
@@ -112,42 +112,6 @@ radeon_surface_release_source_image (void *abstract_surface,
cairo_surface_destroy (&image->base);
}
-static cairo_surface_t *
-radeon_surface_map_to_image (radeon_surface_t *surface)
-{
- if (surface->base.fallback == NULL) {
- cairo_surface_t *image;
- cairo_status_t status;
- void *ptr;
-
- if (surface->base.base.backend->flush != NULL) {
- status = surface->base.base.backend->flush (surface, 0);
- if (unlikely (status))
- return _cairo_surface_create_in_error (status);
- }
-
- ptr = radeon_bo_map (_cairo_radeon_surface_get_device (surface),
- _cairo_radeon_surface_get_bo (surface));
-
- if (unlikely (ptr == NULL))
- return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
-
- image = cairo_image_surface_create_for_data (ptr,
- surface->base.format,
- surface->base.width,
- surface->base.height,
- surface->base.stride);
- if (unlikely (image->status)) {
- _cairo_drm_bo_unmap (surface->base.bo);
- return image;
- }
-
- surface->base.fallback = image;
- }
-
- return surface->base.fallback;
-}
-
static cairo_status_t
radeon_surface_flush (void *abstract_surface,
unsigned flags)
@@ -179,7 +143,7 @@ radeon_surface_paint (void *abstract_surface,
const cairo_pattern_t *source,
const cairo_clip_t *clip)
{
- return _cairo_surface_paint (radeon_surface_map_to_image (abstract_surface),
+ return _cairo_surface_paint (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, clip);
}
@@ -190,7 +154,7 @@ radeon_surface_mask (void *abstract_surface,
const cairo_pattern_t *mask,
const cairo_clip_t *clip)
{
- return _cairo_surface_mask (radeon_surface_map_to_image (abstract_surface),
+ return _cairo_surface_mask (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, mask, clip);
}
@@ -206,7 +170,7 @@ radeon_surface_stroke (void *abstract_surface,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
- return _cairo_surface_stroke (radeon_surface_map_to_image (abstract_surface),
+ return _cairo_surface_stroke (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, path, stroke_style, ctm, ctm_inverse,
tolerance, antialias, clip);
}
@@ -221,7 +185,7 @@ radeon_surface_fill (void *abstract_surface,
cairo_antialias_t antialias,
const cairo_clip_t *clip)
{
- return _cairo_surface_fill (radeon_surface_map_to_image (abstract_surface),
+ return _cairo_surface_fill (_cairo_drm_surface_map_to_image (abstract_surface),
op, source, path, fill_rule,
tolerance, antialias, clip);
}
@@ -235,7 +199,7 @@ radeon_surface_glyphs (void *abstract_surface,
cairo_scaled_font_t *scaled_font,
const cairo_clip_t *clip)
{
- return _cairo_surface_show_text_glyphs (radeon_surface_map_to_image (abstract_surface),
+ return _cairo_surface_show_text_glyphs (_cairo_drm_surface_map_to_image (abstract_surface),
op, source,
NULL, 0,
glyphs, num_glyphs,
diff --git a/src/drm/cairo-drm-surface.c b/src/drm/cairo-drm-surface.c
index ee514ddf1..c93fb94f9 100644
--- a/src/drm/cairo-drm-surface.c
+++ b/src/drm/cairo-drm-surface.c
@@ -367,3 +367,42 @@ cairo_drm_surface_unmap (cairo_surface_t *abstract_surface,
if (--surface->map_count == 0)
cairo_surface_flush (&surface->base);
}
+
+cairo_surface_t *
+_cairo_drm_surface_map_to_image (void *abstract_surface)
+{
+ cairo_drm_surface_t *surface = _cairo_surface_cast_drm (abstract_surface);
+ if (surface->fallback == NULL) {
+ cairo_surface_t *image;
+ cairo_status_t status;
+ void *ptr;
+
+ if (surface->base.backend->flush != NULL) {
+ status = surface->base.backend->flush (surface, 0);
+ if (unlikely (status))
+ return _cairo_surface_create_in_error (status);
+ }
+
+ cairo_drm_device_t * drm_dev = _cairo_device_cast_drm (surface->base.device);
+
+ ptr = drm_dev->bo.map (drm_dev, surface->bo);
+
+ if (unlikely (ptr == NULL))
+ return _cairo_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
+
+ image = cairo_image_surface_create_for_data (ptr,
+ surface->format,
+ surface->width,
+ surface->height,
+ surface->stride);
+
+ if (unlikely (image->status)) {
+ _cairo_drm_bo_unmap (surface->bo);
+ return image;
+ }
+
+ surface->fallback = image;
+ }
+
+ return surface->fallback;
+}
--
2.11.0.rc0.7.gbe5a750
More information about the cairo
mailing list