summaryrefslogtreecommitdiff
path: root/riscos/draw.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-05-06 20:40:09 +0000
commite71691bae890040b83cfd54a2d9a1097d5026866 (patch)
tree96b2680dc6559ca0ab88fa0b6a533c13b7c9487e /riscos/draw.c
parente77b1a29550e4753f771848705975295a6ebe99e (diff)
downloadnetsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.gz
netsurf-e71691bae890040b83cfd54a2d9a1097d5026866.tar.bz2
Merge branches/jmb/content-factory to trunk
svn path=/trunk/netsurf/; revision=12283
Diffstat (limited to 'riscos/draw.c')
-rw-r--r--riscos/draw.c156
1 files changed, 145 insertions, 11 deletions
diff --git a/riscos/draw.c b/riscos/draw.c
index 76bda452f..d2773439a 100644
--- a/riscos/draw.c
+++ b/riscos/draw.c
@@ -29,13 +29,123 @@
#include <stdlib.h>
#include "oslib/drawfile.h"
#include "utils/config.h"
-#include "desktop/plotters.h"
#include "content/content_protected.h"
+#include "desktop/plotters.h"
#include "riscos/draw.h"
#include "riscos/gui.h"
-#include "utils/utils.h"
-#include "utils/messages.h"
#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/talloc.h"
+#include "utils/utils.h"
+
+typedef struct draw_content {
+ struct content base;
+
+ int x0, y0;
+} draw_content;
+
+static nserror draw_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c);
+static bool draw_convert(struct content *c);
+static void draw_destroy(struct content *c);
+static bool draw_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour);
+static nserror draw_clone(const struct content *old, struct content **newc);
+static content_type draw_content_type(lwc_string *mime_type);
+
+static const content_handler draw_content_handler = {
+ draw_create,
+ NULL,
+ draw_convert,
+ NULL,
+ draw_destroy,
+ NULL,
+ NULL,
+ NULL,
+ draw_redraw,
+ NULL,
+ NULL,
+ NULL,
+ draw_clone,
+ NULL,
+ draw_content_type,
+ false
+};
+
+static const char *draw_types[] = {
+ "application/drawfile",
+ "application/x-drawfile",
+ "image/drawfile",
+ "image/x-drawfile"
+};
+
+static lwc_string *draw_mime_types[NOF_ELEMENTS(draw_types)];
+
+nserror draw_init(void)
+{
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
+
+ for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) {
+ lerror = lwc_intern_string(draw_types[i],
+ strlen(draw_types[i]),
+ &draw_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
+ error = content_factory_register_handler(draw_mime_types[i],
+ &draw_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ draw_fini();
+
+ return error;
+}
+
+void draw_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) {
+ if (draw_mime_types[i] != NULL)
+ lwc_string_unref(draw_mime_types[i]);
+ }
+}
+
+nserror draw_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache, const char *fallback_charset,
+ bool quirks, struct content **c)
+{
+ draw_content *draw;
+ nserror error;
+
+ draw = talloc_zero(0, draw_content);
+ if (draw == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&draw->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(draw);
+ return error;
+ }
+
+ *c = (struct content *) draw;
+
+ return NSERROR_OK;
+}
/**
* Convert a CONTENT_DRAW for display.
@@ -46,6 +156,7 @@
bool draw_convert(struct content *c)
{
+ draw_content *draw = (draw_content *) c;
union content_msg_data msg_data;
const char *source_data;
unsigned long source_size;
@@ -78,8 +189,8 @@ bool draw_convert(struct content *c)
/* invalid/undefined bounding box */
c->height = c->width = 0;
- c->data.draw.x0 = bbox.x0;
- c->data.draw.y0 = bbox.y0;
+ draw->x0 = bbox.x0;
+ draw->y0 = bbox.y0;
snprintf(title, sizeof(title), messages_get("DrawTitle"), c->width,
c->height, source_size);
content__set_title(c, title);
@@ -109,6 +220,7 @@ bool draw_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour)
{
+ draw_content *draw = (draw_content *) c;
os_trfm matrix;
const char *source_data;
unsigned long source_size;
@@ -131,9 +243,9 @@ bool draw_redraw(struct content *c, int x, int y,
matrix.entries[1][1] = height * 65536 / c->height;
/* Draw units. (x,y) = bottom left */
matrix.entries[2][0] = ro_plot_origin_x * 256 + x * 512 -
- c->data.draw.x0 * width / c->width;
+ draw->x0 * width / c->width;
matrix.entries[2][1] = ro_plot_origin_y * 256 - (y + height) * 512 -
- c->data.draw.y0 * height / c->height;
+ draw->y0 * height / c->height;
error = xdrawfile_render(0, (drawfile_diagram *) data,
(int) source_size, &matrix, 0, 0);
@@ -150,16 +262,38 @@ bool draw_redraw(struct content *c, int x, int y,
* Clone a CONTENT_DRAW
*/
-bool draw_clone(const struct content *old, struct content *new_content)
+nserror draw_clone(const struct content *old, struct content **newc)
{
+ draw_content *draw;
+ nserror error;
+
+ draw = talloc_zero(0, draw_content);
+ if (draw == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__clone(old, &draw->base);
+ if (error != NSERROR_OK) {
+ content_destroy(&draw->base);
+ return error;
+ }
+
/* Simply rerun convert */
if (old->status == CONTENT_STATUS_READY ||
old->status == CONTENT_STATUS_DONE) {
- if (draw_convert(new_content) == false)
- return false;
+ if (draw_convert(&draw->base) == false) {
+ content_destroy(&draw->base);
+ return NSERROR_CLONE_FAILED;
+ }
}
- return true;
+ *newc = (struct content *) draw;
+
+ return NSERROR_OK;
+}
+
+content_type draw_content_type(lwc_string *mime_type)
+{
+ return CONTENT_IMAGE;
}
#endif