summaryrefslogtreecommitdiff
path: root/content/handlers/image/rsvg.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/image/rsvg.c')
-rw-r--r--content/handlers/image/rsvg.c71
1 files changed, 26 insertions, 45 deletions
diff --git a/content/handlers/image/rsvg.c b/content/handlers/image/rsvg.c
index ee7373795..24fc1a4e0 100644
--- a/content/handlers/image/rsvg.c
+++ b/content/handlers/image/rsvg.c
@@ -49,7 +49,9 @@
#include "netsurf/content.h"
#include "content/llcache.h"
#include "content/content_protected.h"
+#include "content/content_factory.h"
#include "desktop/gui_internal.h"
+#include "desktop/bitmap.h"
#include "image/rsvg.h"
@@ -71,7 +73,7 @@ static nserror rsvg_create_svg_data(rsvg_content *c)
if ((c->rsvgh = rsvg_handle_new()) == NULL) {
NSLOG(netsurf, INFO, "rsvg_handle_new() returned NULL.");
- content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
+ content_broadcast_error(&c->base, NSERROR_NOMEM, NULL);
return NSERROR_NOMEM;
}
@@ -120,48 +122,13 @@ static bool rsvg_process_data(struct content *c, const char *data,
&err) == FALSE) {
NSLOG(netsurf, INFO,
"rsvg_handle_write returned an error: %s", err->message);
- content_broadcast_errorcode(c, NSERROR_SVG_ERROR);
+ content_broadcast_error(c, NSERROR_SVG_ERROR, NULL);
return false;
}
return true;
}
-/** Convert Cairo's ARGB output to NetSurf's favoured ABGR format. It converts
- * the data in-place.
- *
- * \param pixels Pixel data, in the form of ARGB. This will
- * be overwritten with new data in the form of ABGR.
- * \param width Width of the bitmap
- * \param height Height of the bitmap
- * \param rowstride Number of bytes to skip after each row (this
- * implementation requires this to be a multiple of 4.)
- */
-static inline void rsvg_argb_to_abgr(uint8_t *pixels,
- int width, int height, size_t rowstride)
-{
- uint8_t *p = pixels;
- int boff = 0, roff = 2;
-
- if (endian_host_is_le() == false) {
- boff = 1;
- roff = 3;
- }
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- /* Swap R and B */
- const uint8_t r = p[4*x+roff];
-
- p[4*x+roff] = p[4*x+boff];
-
- p[4*x+boff] = r;
- }
-
- p += rowstride;
- }
-}
-
static bool rsvg_convert(struct content *c)
{
rsvg_content *d = (rsvg_content *) c;
@@ -171,7 +138,7 @@ static bool rsvg_convert(struct content *c)
if (rsvg_handle_close(d->rsvgh, &err) == FALSE) {
NSLOG(netsurf, INFO,
"rsvg_handle_close returned an error: %s", err->message);
- content_broadcast_errorcode(c, NSERROR_SVG_ERROR);
+ content_broadcast_error(c, NSERROR_SVG_ERROR, NULL);
return false;
}
@@ -186,10 +153,10 @@ static bool rsvg_convert(struct content *c)
c->height = rsvgsize.height;
if ((d->bitmap = guit->bitmap->create(c->width, c->height,
- BITMAP_NEW)) == NULL) {
+ BITMAP_NONE)) == NULL) {
NSLOG(netsurf, INFO,
"Failed to create bitmap for rsvg render.");
- content_broadcast_errorcode(c, NSERROR_NOMEM);
+ content_broadcast_error(c, NSERROR_NOMEM, NULL);
return false;
}
@@ -200,22 +167,22 @@ static bool rsvg_convert(struct content *c)
guit->bitmap->get_rowstride(d->bitmap))) == NULL) {
NSLOG(netsurf, INFO,
"Failed to create Cairo image surface for rsvg render.");
- content_broadcast_errorcode(c, NSERROR_NOMEM);
+ content_broadcast_error(c, NSERROR_NOMEM, NULL);
return false;
}
if ((d->ct = cairo_create(d->cs)) == NULL) {
NSLOG(netsurf, INFO,
"Failed to create Cairo drawing context for rsvg render.");
- content_broadcast_errorcode(c, NSERROR_NOMEM);
+ content_broadcast_error(c, NSERROR_NOMEM, NULL);
return false;
}
rsvg_handle_render_cairo(d->rsvgh, d->ct);
- rsvg_argb_to_abgr(guit->bitmap->get_buffer(d->bitmap),
- c->width, c->height,
- guit->bitmap->get_rowstride(d->bitmap));
+ bitmap_format_to_client(d->bitmap, &(bitmap_fmt_t) {
+ .layout = BITMAP_LAYOUT_ARGB8888,
+ });
guit->bitmap->modified(d->bitmap);
content_set_ready(c);
content_set_done(c);
@@ -315,6 +282,19 @@ static content_type rsvg_content_type(void)
return CONTENT_IMAGE;
}
+
+static bool rsvg_content_is_opaque(struct content *c)
+{
+ rsvg_content *d = (rsvg_content *) c;
+
+ if (d->bitmap != NULL) {
+ return guit->bitmap->get_opaque(d->bitmap);
+ }
+
+ return false;
+}
+
+
static const content_handler rsvg_content_handler = {
.create = rsvg_create,
.process_data = rsvg_process_data,
@@ -324,6 +304,7 @@ static const content_handler rsvg_content_handler = {
.clone = rsvg_clone,
.get_internal = rsvg_get_internal,
.type = rsvg_content_type,
+ .is_opaque = rsvg_content_is_opaque,
.no_share = false,
};