|
|
ff210d |
From 0e4e268844ea38075535eb5b233dda325da4481d Mon Sep 17 00:00:00 2001
|
|
|
ff210d |
From: Hans de Goede <hdegoede@redhat.com>
|
|
|
ff210d |
Date: Wed, 6 Dec 2017 17:37:12 +0100
|
|
|
ff210d |
Subject: [PATCH 3/6] pixel-buffer: Add the concept of device rotation
|
|
|
ff210d |
|
|
|
ff210d |
On some devices the LCD panel is mounted in the casing in such a way
|
|
|
ff210d |
that the up/top side of the panel does not match with the top side of
|
|
|
ff210d |
the device (e.g. it is mounted upside-down).
|
|
|
ff210d |
|
|
|
ff210d |
This commit adds support to the ply-pixel-buffer code to create
|
|
|
ff210d |
buffers which take device rotation into account and which will rotate
|
|
|
ff210d |
the picture to compensate.
|
|
|
ff210d |
|
|
|
ff210d |
https://bugs.freedesktop.org/show_bug.cgi?id=104714
|
|
|
ff210d |
---
|
|
|
ff210d |
src/libply-splash-core/ply-pixel-buffer.c | 109 ++++++++++++++++++++--
|
|
|
ff210d |
src/libply-splash-core/ply-pixel-buffer.h | 9 ++
|
|
|
ff210d |
2 files changed, 110 insertions(+), 8 deletions(-)
|
|
|
ff210d |
|
|
|
ff210d |
diff --git a/src/libply-splash-core/ply-pixel-buffer.c b/src/libply-splash-core/ply-pixel-buffer.c
|
|
|
ff210d |
index 52a3f86..a337407 100644
|
|
|
ff210d |
--- a/src/libply-splash-core/ply-pixel-buffer.c
|
|
|
ff210d |
+++ b/src/libply-splash-core/ply-pixel-buffer.c
|
|
|
ff210d |
@@ -50,6 +50,7 @@ struct _ply_pixel_buffer
|
|
|
ff210d |
ply_region_t *updated_areas; /* in device pixels */
|
|
|
ff210d |
uint32_t is_opaque : 1;
|
|
|
ff210d |
int device_scale;
|
|
|
ff210d |
+ int device_rotation;
|
|
|
ff210d |
};
|
|
|
ff210d |
|
|
|
ff210d |
static inline void ply_pixel_buffer_blend_value_at_pixel (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
@@ -153,6 +154,52 @@ make_pixel_value_translucent (uint32_t pixel_value,
|
|
|
ff210d |
return (alpha << 24) | (red << 16) | (green << 8) | blue;
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
+static inline void ply_pixel_buffer_set_pixel (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
+ int x,
|
|
|
ff210d |
+ int y,
|
|
|
ff210d |
+ uint32_t pixel_value)
|
|
|
ff210d |
+{
|
|
|
ff210d |
+ switch (buffer->device_rotation) {
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPRIGHT:
|
|
|
ff210d |
+ buffer->bytes[y * buffer->area.width + x] = pixel_value;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN:
|
|
|
ff210d |
+ x = (buffer->area.width - 1) - x;
|
|
|
ff210d |
+ y = (buffer->area.height - 1) - y;
|
|
|
ff210d |
+ buffer->bytes[y * buffer->area.width + x] = pixel_value;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE:
|
|
|
ff210d |
+ y = (buffer->area.height - 1) - y;
|
|
|
ff210d |
+ buffer->bytes[x * buffer->area.height + y] = pixel_value;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE:
|
|
|
ff210d |
+ x = (buffer->area.width - 1) - x;
|
|
|
ff210d |
+ buffer->bytes[x * buffer->area.height + y] = pixel_value;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ }
|
|
|
ff210d |
+}
|
|
|
ff210d |
+
|
|
|
ff210d |
+static inline uint32_t ply_pixel_buffer_get_pixel (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
+ int x,
|
|
|
ff210d |
+ int y)
|
|
|
ff210d |
+{
|
|
|
ff210d |
+ switch (buffer->device_rotation) {
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPRIGHT:
|
|
|
ff210d |
+ return buffer->bytes[y * buffer->area.width + x];
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN:
|
|
|
ff210d |
+ x = (buffer->area.width - 1) - x;
|
|
|
ff210d |
+ y = (buffer->area.height - 1) - y;
|
|
|
ff210d |
+ return buffer->bytes[y * buffer->area.width + x];
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE:
|
|
|
ff210d |
+ y = (buffer->area.height - 1) - y;
|
|
|
ff210d |
+ return buffer->bytes[x * buffer->area.height + y];
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE:
|
|
|
ff210d |
+ x = (buffer->area.width - 1) - x;
|
|
|
ff210d |
+ return buffer->bytes[x * buffer->area.height + y];
|
|
|
ff210d |
+ }
|
|
|
ff210d |
+ return 0;
|
|
|
ff210d |
+}
|
|
|
ff210d |
+
|
|
|
ff210d |
static inline void
|
|
|
ff210d |
ply_pixel_buffer_blend_value_at_pixel (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
int x,
|
|
|
ff210d |
@@ -162,12 +209,12 @@ ply_pixel_buffer_blend_value_at_pixel (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
uint32_t old_pixel_value;
|
|
|
ff210d |
|
|
|
ff210d |
if ((pixel_value >> 24) != 0xff) {
|
|
|
ff210d |
- old_pixel_value = buffer->bytes[y * buffer->area.width + x];
|
|
|
ff210d |
+ old_pixel_value = ply_pixel_buffer_get_pixel (buffer, x, y);
|
|
|
ff210d |
|
|
|
ff210d |
pixel_value = blend_two_pixel_values (pixel_value, old_pixel_value);
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
- buffer->bytes[y * buffer->area.width + x] = pixel_value;
|
|
|
ff210d |
+ ply_pixel_buffer_set_pixel (buffer, x, y, pixel_value);
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
static void
|
|
|
ff210d |
@@ -222,6 +269,35 @@ ply_pixel_buffer_crop_area_to_clip_area (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
}
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
+static void ply_pixel_buffer_add_updated_area (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
+ ply_rectangle_t *area)
|
|
|
ff210d |
+{
|
|
|
ff210d |
+ ply_rectangle_t updated_area = *area;
|
|
|
ff210d |
+
|
|
|
ff210d |
+ switch (buffer->device_rotation) {
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPRIGHT:
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN:
|
|
|
ff210d |
+ updated_area.x = buffer->area.width - area->width - area->x;
|
|
|
ff210d |
+ updated_area.y = buffer->area.height - area->height - area->y;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE:
|
|
|
ff210d |
+ updated_area.x = buffer->area.height - area->height - area->y;
|
|
|
ff210d |
+ updated_area.y = area->x;
|
|
|
ff210d |
+ updated_area.height = area->width;
|
|
|
ff210d |
+ updated_area.width = area->height;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ case PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE:
|
|
|
ff210d |
+ updated_area.x = area->y;
|
|
|
ff210d |
+ updated_area.y = buffer->area.width - area->width - area->x;
|
|
|
ff210d |
+ updated_area.height = area->width;
|
|
|
ff210d |
+ updated_area.width = area->height;
|
|
|
ff210d |
+ break;
|
|
|
ff210d |
+ }
|
|
|
ff210d |
+
|
|
|
ff210d |
+ ply_region_add_rectangle (buffer->updated_areas, &updated_area);
|
|
|
ff210d |
+}
|
|
|
ff210d |
+
|
|
|
ff210d |
static void
|
|
|
ff210d |
ply_pixel_buffer_fill_area_with_pixel_value (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
ply_rectangle_t *fill_area,
|
|
|
ff210d |
@@ -251,7 +327,7 @@ ply_pixel_buffer_fill_area_with_pixel_value (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
}
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
- ply_region_add_rectangle (buffer->updated_areas, &cropped_area);
|
|
|
ff210d |
+ ply_pixel_buffer_add_updated_area (buffer, &cropped_area);
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
void
|
|
|
ff210d |
@@ -281,9 +357,24 @@ ply_pixel_buffer_pop_clip_area (ply_pixel_buffer_t *buffer)
|
|
|
ff210d |
ply_pixel_buffer_t *
|
|
|
ff210d |
ply_pixel_buffer_new (unsigned long width,
|
|
|
ff210d |
unsigned long height)
|
|
|
ff210d |
+{
|
|
|
ff210d |
+ return ply_pixel_buffer_new_with_device_rotation (
|
|
|
ff210d |
+ width, height, PLY_PIXEL_BUFFER_ROTATE_UPRIGHT);
|
|
|
ff210d |
+}
|
|
|
ff210d |
+
|
|
|
ff210d |
+ply_pixel_buffer_t *
|
|
|
ff210d |
+ply_pixel_buffer_new_with_device_rotation (unsigned long width,
|
|
|
ff210d |
+ unsigned long height,
|
|
|
ff210d |
+ int device_rotation)
|
|
|
ff210d |
{
|
|
|
ff210d |
ply_pixel_buffer_t *buffer;
|
|
|
ff210d |
|
|
|
ff210d |
+ if (device_rotation >= PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE) {
|
|
|
ff210d |
+ unsigned long tmp = width;
|
|
|
ff210d |
+ width = height;
|
|
|
ff210d |
+ height = tmp;
|
|
|
ff210d |
+ }
|
|
|
ff210d |
+
|
|
|
ff210d |
buffer = calloc (1, sizeof(ply_pixel_buffer_t));
|
|
|
ff210d |
|
|
|
ff210d |
buffer->updated_areas = ply_region_new ();
|
|
|
ff210d |
@@ -292,6 +383,7 @@ ply_pixel_buffer_new (unsigned long width,
|
|
|
ff210d |
buffer->area.height = height;
|
|
|
ff210d |
buffer->logical_area = buffer->area;
|
|
|
ff210d |
buffer->device_scale = 1;
|
|
|
ff210d |
+ buffer->device_rotation = device_rotation;
|
|
|
ff210d |
|
|
|
ff210d |
buffer->clip_areas = ply_list_new ();
|
|
|
ff210d |
ply_pixel_buffer_push_clip_area (buffer, &buffer->area);
|
|
|
ff210d |
@@ -447,7 +539,7 @@ ply_pixel_buffer_fill_with_gradient (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
|
|
|
ff210d |
for (y = buffer->area.y; y < buffer->area.y + buffer->area.height; y++) {
|
|
|
ff210d |
if (cropped_area.y <= y && y < cropped_area.y + cropped_area.height) {
|
|
|
ff210d |
- if (cropped_area.width < UNROLLED_PIXEL_COUNT) {
|
|
|
ff210d |
+ if (cropped_area.width < UNROLLED_PIXEL_COUNT || buffer->device_rotation) {
|
|
|
ff210d |
for (x = cropped_area.x; x < cropped_area.x + cropped_area.width; x++) {
|
|
|
ff210d |
pixel = 0xff000000;
|
|
|
ff210d |
RANDOMIZE (noise);
|
|
|
ff210d |
@@ -457,7 +549,7 @@ ply_pixel_buffer_fill_with_gradient (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
RANDOMIZE (noise);
|
|
|
ff210d |
pixel |= (((blue + noise) & COLOR_MASK) >> BLUE_SHIFT);
|
|
|
ff210d |
|
|
|
ff210d |
- buffer->bytes[y * buffer->area.width + x] = pixel;
|
|
|
ff210d |
+ ply_pixel_buffer_set_pixel (buffer, x, y, pixel);
|
|
|
ff210d |
}
|
|
|
ff210d |
} else {
|
|
|
ff210d |
uint32_t shaded_set[UNROLLED_PIXEL_COUNT];
|
|
|
ff210d |
@@ -485,7 +577,7 @@ ply_pixel_buffer_fill_with_gradient (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
blue += blue_step;
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
- ply_region_add_rectangle (buffer->updated_areas, &cropped_area);
|
|
|
ff210d |
+ ply_pixel_buffer_add_updated_area (buffer, &cropped_area);
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
void
|
|
|
ff210d |
@@ -671,7 +763,7 @@ ply_pixel_buffer_fill_with_argb32_data_at_opacity_with_clip_and_scale (ply_pixel
|
|
|
ff210d |
}
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
- ply_region_add_rectangle (buffer->updated_areas, &cropped_area);
|
|
|
ff210d |
+ ply_pixel_buffer_add_updated_area (buffer, &cropped_area);
|
|
|
ff210d |
}
|
|
|
ff210d |
|
|
|
ff210d |
void
|
|
|
ff210d |
@@ -756,7 +848,8 @@ ply_pixel_buffer_fill_with_buffer_at_opacity_with_clip (ply_pixel_buffer_t *canv
|
|
|
ff210d |
|
|
|
ff210d |
/* Fast path to memcpy if we need no blending or scaling */
|
|
|
ff210d |
if (opacity == 1.0 && ply_pixel_buffer_is_opaque (source) &&
|
|
|
ff210d |
- canvas->device_scale == source->device_scale) {
|
|
|
ff210d |
+ canvas->device_scale == source->device_scale &&
|
|
|
ff210d |
+ canvas->device_rotation == PLY_PIXEL_BUFFER_ROTATE_UPRIGHT) {
|
|
|
ff210d |
ply_rectangle_t cropped_area;
|
|
|
ff210d |
|
|
|
ff210d |
cropped_area.x = x_offset;
|
|
|
ff210d |
diff --git a/src/libply-splash-core/ply-pixel-buffer.h b/src/libply-splash-core/ply-pixel-buffer.h
|
|
|
ff210d |
index 595e9bd..7736dd3 100644
|
|
|
ff210d |
--- a/src/libply-splash-core/ply-pixel-buffer.h
|
|
|
ff210d |
+++ b/src/libply-splash-core/ply-pixel-buffer.h
|
|
|
ff210d |
@@ -37,9 +37,18 @@ typedef struct _ply_pixel_buffer ply_pixel_buffer_t;
|
|
|
ff210d |
| ((uint8_t) (CLAMP (g * 255.0, 0.0, 255.0)) << 8) \
|
|
|
ff210d |
| ((uint8_t) (CLAMP (b * 255.0, 0.0, 255.0))))
|
|
|
ff210d |
|
|
|
ff210d |
+#define PLY_PIXEL_BUFFER_ROTATE_UPRIGHT 0
|
|
|
ff210d |
+#define PLY_PIXEL_BUFFER_ROTATE_UPSIDE_DOWN 1
|
|
|
ff210d |
+#define PLY_PIXEL_BUFFER_ROTATE_CLOCKWISE 2
|
|
|
ff210d |
+#define PLY_PIXEL_BUFFER_ROTATE_COUNTER_CLOCKWISE 3
|
|
|
ff210d |
+
|
|
|
ff210d |
#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
|
|
|
ff210d |
ply_pixel_buffer_t *ply_pixel_buffer_new (unsigned long width,
|
|
|
ff210d |
unsigned long height);
|
|
|
ff210d |
+ply_pixel_buffer_t *
|
|
|
ff210d |
+ply_pixel_buffer_new_with_device_rotation (unsigned long width,
|
|
|
ff210d |
+ unsigned long height,
|
|
|
ff210d |
+ int device_rotation);
|
|
|
ff210d |
void ply_pixel_buffer_free (ply_pixel_buffer_t *buffer);
|
|
|
ff210d |
void ply_pixel_buffer_get_size (ply_pixel_buffer_t *buffer,
|
|
|
ff210d |
ply_rectangle_t *size);
|
|
|
ff210d |
--
|
|
|
ff210d |
2.17.0
|
|
|
ff210d |
|