From 328fad57dbfb65e3bd31062021d5cc3081e68515 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Fri, 22 Jul 2011 04:09:27 +0200 Subject: Replace direct use of Cairo contexts and surfaces in the rendering tree with wrappers which keep some extra information about the surface, amd NRRect and NRRectL use with Geom::Rect and Geom::IntRect. Should simplify implementing filter primitive subregions. (bzr r10347.1.17) --- src/flood-context.cpp | 69 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'src/flood-context.cpp') diff --git a/src/flood-context.cpp b/src/flood-context.cpp index 90278ac95..d93e0284d 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -53,6 +53,7 @@ #include "display/nr-arena-image.h" #include "display/canvas-arena.h" #include "display/cairo-utils.h" +#include "display/drawing-context.h" #include <2geom/pathvector.h> #include "sp-item.h" #include "sp-root.h" @@ -805,8 +806,8 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even Geom::Point origin(screen.min()[Geom::X], document->getHeight() - screen.height() - screen.min()[Geom::Y]); - origin[Geom::X] = origin[Geom::X] + (screen.width() * ((1 - padding) / 2)); - origin[Geom::Y] = origin[Geom::Y] + (screen.height() * ((1 - padding) / 2)); + origin[Geom::X] += (screen.width() * ((1 - padding) / 2)); + origin[Geom::Y] += (screen.height() * ((1 - padding) / 2)); Geom::Scale scale(zoom_scale, zoom_scale); Geom::Affine affine = scale * Geom::Translate(-origin * scale); @@ -817,44 +818,42 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even NRGC gc(NULL); gc.transform.setIdentity(); + + Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - NRRectL final_bbox; - final_bbox.x0 = 0; - final_bbox.y0 = 0; //row; - final_bbox.x1 = width; - final_bbox.y1 = height; //row + num_rows; - - nr_arena_item_invoke_update(root, &final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); + nr_arena_item_invoke_update(root, final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); guchar *px = g_new(guchar, stride * height); - - cairo_surface_t *s = cairo_image_surface_create_for_data( - px, CAIRO_FORMAT_ARGB32, width, height, stride); - cairo_t *ct = cairo_create(s); - // cairo_translate not necessary here - surface origin is at 0,0 - - SPNamedView *nv = sp_desktop_namedview(desktop); - guint32 bgcolor = nv->pagecolor; - // bgcolor is 0xrrggbbaa, we need 0xaarrggbb - guint32 dtc = (bgcolor >> 8) | (bgcolor << 24); - - ink_cairo_set_source_rgba32(ct, bgcolor); - cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_paint(ct); - cairo_set_operator(ct, CAIRO_OPERATOR_OVER); - - nr_arena_item_invoke_render(ct, root, &final_bbox, NULL, NR_ARENA_ITEM_RENDER_NO_CACHE ); - - cairo_surface_flush(s); - cairo_destroy(ct); - cairo_surface_destroy(s); - - // Hide items - SP_ITEM(document->getRoot())->invoke_hide(dkey); + guint32 bgcolor, dtc; + + { // this block limits the lifetime of DrawingContext + cairo_surface_t *s = cairo_image_surface_create_for_data( + px, CAIRO_FORMAT_ARGB32, width, height, stride); + Inkscape::DrawingContext ct(s, Geom::Point(0,0)); + // cairo_translate not necessary here - surface origin is at 0,0 + + SPNamedView *nv = sp_desktop_namedview(desktop); + bgcolor = nv->pagecolor; + // bgcolor is 0xrrggbbaa, we need 0xaarrggbb + dtc = (bgcolor >> 8) | (bgcolor << 24); + + ct.setSource(bgcolor); + ct.setOperator(CAIRO_OPERATOR_SOURCE); + ct.paint(); + ct.setOperator(CAIRO_OPERATOR_OVER); + + nr_arena_item_invoke_render(ct, root, final_bbox, NR_ARENA_ITEM_RENDER_NO_CACHE ); + + cairo_surface_flush(s); + cairo_surface_destroy(s); + + // Hide items + SP_ITEM(document->getRoot())->invoke_hide(dkey); + + nr_object_unref((NRObject *) arena); + } - nr_object_unref((NRObject *) arena); - guchar *trace_px = g_new(guchar, width * height); memset(trace_px, 0x00, width * height); -- cgit v1.2.3 From 4dd33aa4d5c57706c7f64f63391174954160a308 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 6 Aug 2011 14:18:32 +0200 Subject: Rewrite NRArenaItem hierarchy into C++ (bzr r10347.1.21) --- src/flood-context.cpp | 76 ++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'src/flood-context.cpp') diff --git a/src/flood-context.cpp b/src/flood-context.cpp index 84c97b096..a71333a4f 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -20,54 +20,53 @@ #include "config.h" #endif +#include <2geom/pathvector.h> #include #include #include +#include -#include "macros.h" -#include "display/sp-canvas.h" -#include "document.h" -#include "sp-namedview.h" -#include "sp-object.h" -#include "sp-rect.h" -#include "selection.h" -#include "desktop-handles.h" +#include "color.h" +#include "context-fns.h" #include "desktop.h" +#include "desktop-handles.h" #include "desktop-style.h" -#include "message-stack.h" -#include "message-context.h" -#include "pixmaps/cursor-paintbucket.xpm" +#include "display/cairo-utils.h" +#include "display/canvas-arena.h" +#include "display/drawing-context.h" +#include "display/drawing-image.h" +#include "display/drawing-item.h" +#include "display/nr-arena.h" +#include "display/sp-canvas.h" +#include "document.h" #include "flood-context.h" -#include "sp-metrics.h" -#include +#include "livarot/Path.h" +#include "livarot/Shape.h" +#include "macros.h" +#include "message-context.h" +#include "message-stack.h" #include "object-edit.h" -#include "xml/repr.h" -#include "xml/node-event-vector.h" #include "preferences.h" -#include "context-fns.h" #include "rubberband.h" +#include "selection.h" #include "shape-editor.h" - -#include "display/nr-arena-item.h" -#include "display/nr-arena.h" -#include "display/nr-arena-image.h" -#include "display/canvas-arena.h" -#include "display/cairo-utils.h" -#include "display/drawing-context.h" -#include <2geom/pathvector.h> -#include "sp-item.h" -#include "sp-root.h" #include "sp-defs.h" -#include "sp-path.h" +#include "sp-item.h" #include "splivarot.h" -#include "livarot/Path.h" -#include "livarot/Shape.h" +#include "sp-metrics.h" +#include "sp-namedview.h" +#include "sp-object.h" +#include "sp-path.h" +#include "sp-rect.h" +#include "sp-root.h" #include "svg/svg.h" -#include "color.h" - -#include "trace/trace.h" #include "trace/imagemap.h" #include "trace/potrace/inkscape-potrace.h" +#include "trace/trace.h" +#include "xml/node-event-vector.h" +#include "xml/repr.h" + +#include "pixmaps/cursor-paintbucket.xpm" using Inkscape::DocumentUndo; @@ -812,15 +811,12 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even Geom::Affine affine = scale * Geom::Translate(-origin * scale); /* Create ArenaItems and set transform */ - NRArenaItem *root = document->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); - nr_arena_item_set_transform(NR_ARENA_ITEM(root), affine); - - NRGC gc(NULL); - gc.transform.setIdentity(); + Inkscape::DrawingItem *root = document->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); + root->setTransform(affine); + Inkscape::UpdateContext ctx; Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - - nr_arena_item_invoke_update(root, final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE); + root->update(final_bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); guchar *px = g_new(guchar, stride * height); @@ -842,7 +838,7 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even ct.paint(); ct.setOperator(CAIRO_OPERATOR_OVER); - nr_arena_item_invoke_render(ct, root, final_bbox, NR_ARENA_ITEM_RENDER_NO_CACHE ); + root->render(ct, final_bbox, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); cairo_surface_flush(s); cairo_surface_destroy(s); -- cgit v1.2.3 From 75976ea07dba9b97186667524d0a76603de416af Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 7 Aug 2011 12:53:12 +0200 Subject: Rewrite NRArena -> Inkscape::Drawing. Call render and update methods on the Drawing rather than on the root DrawingItem. (bzr r10347.1.25) --- src/flood-context.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/flood-context.cpp') diff --git a/src/flood-context.cpp b/src/flood-context.cpp index a71333a4f..8603f8b66 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -32,11 +32,10 @@ #include "desktop-handles.h" #include "desktop-style.h" #include "display/cairo-utils.h" -#include "display/canvas-arena.h" #include "display/drawing-context.h" #include "display/drawing-image.h" #include "display/drawing-item.h" -#include "display/nr-arena.h" +#include "display/drawing.h" #include "display/sp-canvas.h" #include "document.h" #include "flood-context.h" @@ -777,10 +776,6 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even SPDesktop *desktop = event_context->desktop; SPDocument *document = sp_desktop_document(desktop); - /* Create new arena */ - NRArena *arena = NRArena::create(); - unsigned dkey = SPItem::display_key_new(1); - document->ensureUpToDate(); Geom::OptRect bbox = document->getRoot()->getBounds(Geom::identity()); @@ -809,20 +804,22 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even Geom::Scale scale(zoom_scale, zoom_scale); Geom::Affine affine = scale * Geom::Translate(-origin * scale); - - /* Create ArenaItems and set transform */ - Inkscape::DrawingItem *root = document->getRoot()->invoke_show( arena, dkey, SP_ITEM_SHOW_DISPLAY); - root->setTransform(affine); - - Inkscape::UpdateContext ctx; - Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); - root->update(final_bbox, ctx, Inkscape::DrawingItem::STATE_ALL, 0); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); guchar *px = g_new(guchar, stride * height); guint32 bgcolor, dtc; - { // this block limits the lifetime of DrawingContext + { // this block limits the lifetime of Drawing and DrawingContext + /* Create DrawingItems and set transform */ + unsigned dkey = SPItem::display_key_new(1); + Inkscape::Drawing drawing; + Inkscape::DrawingItem *root = document->getRoot()->invoke_show( drawing, dkey, SP_ITEM_SHOW_DISPLAY); + root->setTransform(affine); + drawing.setRoot(root); + + Geom::IntRect final_bbox = Geom::IntRect::from_xywh(0, 0, width, height); + drawing.update(final_bbox); + cairo_surface_t *s = cairo_image_surface_create_for_data( px, CAIRO_FORMAT_ARGB32, width, height, stride); Inkscape::DrawingContext ct(s, Geom::Point(0,0)); @@ -838,15 +835,13 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even ct.paint(); ct.setOperator(CAIRO_OPERATOR_OVER); - root->render(ct, final_bbox, Inkscape::DrawingItem::RENDER_BYPASS_CACHE); + drawing.render(ct, final_bbox); cairo_surface_flush(s); cairo_surface_destroy(s); // Hide items document->getRoot()->invoke_hide(dkey); - - nr_object_unref((NRObject *) arena); } guchar *trace_px = g_new(guchar, width * height); -- cgit v1.2.3