From 68a136703d96e42fba5a2464e2eb09eb3fee5815 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Sat, 17 Feb 2007 22:56:16 +0000 Subject: [PATCH] a bunch of cairo fixmes in anticipation of a more direct rendering with less intermediate buffers and unpacked 32bit RGBA throughout --- src/display/canvas-arena.cpp | 2 ++ src/display/sp-canvas-util.cpp | 2 +- src/display/sp-canvas.cpp | 22 +++++++++++++-- src/display/sp-ctrlline.cpp | 49 +++++++++++++++++++++++++++++++--- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index 7b3e5bc94..3212d0bd2 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -240,6 +240,7 @@ sp_canvas_arena_render (SPCanvasItem *item, SPCanvasBuf *buf) /* fixme: RGB transformed bitmap blit is not implemented (Lauris) */ /* And even if it would be, unless it uses MMX there is little reason to go RGB */ +// CAIRO FIXME: undefine this so that arena renders directly into SPCanvasBuf, without blitting and squishing (32bpp -> 24bpp packed) from a pixblock #define STRICT_RGBA for (y = buf->rect.y0; y < buf->rect.y1; y += sh) { @@ -261,6 +262,7 @@ sp_canvas_arena_render (SPCanvasItem *item, SPCanvasBuf *buf) pb.empty = FALSE; #endif +// CAIRO FIXME: switch this to R8G8B8A8P and 4 * ... nr_pixblock_setup_extern (&cb, NR_PIXBLOCK_MODE_R8G8B8, area.x0, area.y0, area.x1, area.y1, buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + 3 * (x - buf->rect.x0), buf->buf_rowstride, diff --git a/src/display/sp-canvas-util.cpp b/src/display/sp-canvas-util.cpp index e4f2c7b75..284328d7f 100644 --- a/src/display/sp-canvas-util.cpp +++ b/src/display/sp-canvas-util.cpp @@ -73,7 +73,7 @@ sp_canvas_clear_buffer (SPCanvasBuf *buf) } else { int y; for (y = buf->rect.y0; y < buf->rect.y1; y++) { - memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 3 * (buf->rect.x1 - buf->rect.x0)); + memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 3 * (buf->rect.x1 - buf->rect.x0)); // CAIRO FIXME: for cairo output we need 32bpp, so it will be 4 * ... } } } diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index c8de86884..39ebc17d1 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -1524,7 +1524,7 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1, buf.buf = nr_pixelstore_1M_new (FALSE, 0); } - buf.buf_rowstride = sw * 3; + buf.buf_rowstride = sw * 3; // CAIRO FIXME: for cairo output, the buffer must be RGB unpacked, i.e. sw * 4 buf.rect.x0 = x0; buf.rect.y0 = y0; buf.rect.x1 = x1; @@ -1551,6 +1551,23 @@ sp_canvas_paint_single_buffer (SPCanvas *canvas, int x0, int y0, int x1, int y1, x0 - canvas->x0, y0 - canvas->y0, x1 - x0, y1 - y0); } else { +/* + CAIRO FIXME: after SPCanvasBuf is made 32bpp throughout, this rgb_draw below can be replaced with: + cairo_surface_t* cst = cairo_image_surface_create_for_data ( + buf.buf, + CAIRO_FORMAT_RGB24, // unpacked, i.e. 32 bits! one byte is unused + x1 - x0, y1 - y0, + buf.buf_rowstride + ); + cairo_t *ct = gdk_cairo_create(SP_CANVAS_WINDOW (canvas)); + cairo_set_source_surface (ct, cst, x0 - canvas->x0, y0 - canvas->y0); + cairo_paint (ct); + + cairo_destroy (ct); + cairo_surface_finish (cst); + cairo_surface_destroy (cst); +*/ + gdk_draw_rgb_image_dithalign (SP_CANVAS_WINDOW (canvas), canvas->pixmap_gc, x0 - canvas->x0, y0 - canvas->y0, @@ -1588,7 +1605,8 @@ sp_canvas_paint_rect_internal (SPCanvas *canvas, NRRectL *rect, NR::ICoord *x_ab int bh = draw_y2 - draw_y1; if ((bw < 1) || (bh < 1)) return 0; - int sw, sh; + + int sw, sh; // CAIRO FIXME: the sw/sh calculations below all assume 24bpp, need fixing for 32bpp if (canvas->rendermode != RENDERMODE_OUTLINE) { // use 256K as a compromise to not slow down gradients /* 256K is the cached buffer and we need 3 channels */ if (bw * bh < 87381) { // 256K/3 diff --git a/src/display/sp-ctrlline.cpp b/src/display/sp-ctrlline.cpp index b32607a65..85f8fdc60 100644 --- a/src/display/sp-ctrlline.cpp +++ b/src/display/sp-ctrlline.cpp @@ -27,7 +27,7 @@ # include "config.h" #endif #include - +#include static void sp_ctrlline_class_init (SPCtrlLineClass *klass); @@ -108,6 +108,33 @@ sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf) area.y0=buf->rect.y0; area.y1=buf->rect.y1; +/* +// CAIRO FIXME: after SPCanvasBuf is switched to unpacked 32bit rgb, rendering can be done via cairo: + cairo_surface_t* cst = cairo_image_surface_create_for_data ( + buf->buf, + CAIRO_FORMAT_RGB24, + buf->rect.x1 - buf->rect.x0, + buf->rect.y1 - buf->rect.y0, + buf->buf_rowstride + ); + cairo_t *ct = cairo_create (cst); + + guint32 rgba = ctrlline->rgba; + cairo_set_source_rgba(ct, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba), SP_RGBA32_A_F(rgba)); + + cairo_set_line_width(ct, 0.5); + cairo_new_path(ct); + + cairo_move_to (ct, ctrlline->s.x - buf->rect.x0, ctrlline->s.y - buf->rect.y0); + cairo_line_to (ct, ctrlline->e.x - buf->rect.x0, ctrlline->e.y - buf->rect.y0); + + cairo_stroke(ct); + cairo_destroy (ct); + cairo_surface_finish (cst); + cairo_surface_destroy (cst); +*/ + +// CAIRO FIXME: instead of this: if (ctrlline->shp) { sp_canvas_prepare_buffer (buf); nr_pixblock_render_ctrl_rgba (ctrlline->shp,ctrlline->rgba,area,(char*)buf->buf, buf->buf_rowstride); @@ -117,8 +144,6 @@ sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf) static void sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags) { - NRRect dbox; - SPCtrlLine *cl = SP_CTRLLINE (item); sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); @@ -128,6 +153,24 @@ sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int f sp_canvas_item_reset_bounds (item); +/* +// CAIRO FIXME: all that is needed for update with cairo: + NR::Point s = NR::Point(cl->s.x, cl->s.y) * affine; + NR::Point e = NR::Point(cl->e.x, cl->e.y) * affine; + + cl->s.x = s[NR::X]; + cl->s.y = s[NR::Y]; + cl->e.x = e[NR::X]; + cl->e.y = e[NR::Y]; + + item->x1 = (int)(MIN(s[NR::X], e[NR::X]) - 1); + item->y1 = (int)(MIN(s[NR::Y], e[NR::Y]) - 1); + item->x2 = (int)(MAX(s[NR::X], e[NR::X]) + 1); + item->y2 = (int)(MAX(s[NR::Y], e[NR::Y]) + 1); +*/ + +// CAIRO FIXME: instead of: + NRRect dbox; dbox.x0=dbox.x1=dbox.y0=dbox.y1=0; if (cl->shp) { delete cl->shp; -- 2.30.2