X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fcanvas.cpp;h=8cf1f20bdcd777b08cb5a549766d78b94f28b9b4;hb=78e15db42e8bd6cfce82576d3c1d1659200b2074;hp=e7a54f979a19e57801912e7891d524d2b8e17d5d;hpb=3fe10abdf88b103b84825cd2bbac1e25090ecd9a;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/canvas.cpp b/synfig-core/trunk/src/synfig/canvas.cpp index e7a54f9..8cf1f20 100644 --- a/synfig-core/trunk/src/synfig/canvas.cpp +++ b/synfig-core/trunk/src/synfig/canvas.cpp @@ -90,6 +90,34 @@ Canvas::on_changed() Canvas::~Canvas() { + bool keep_going = true; + + // we were having a crash where pastecanvas layers were still + // refering to a canvas after it had been destroyed; this code + // will stop the pastecanvas layers from refering to the canvas + // before the canvas is destroyed + + // the set_sub_canvas(0) ends up deleting the parent-child link, + // which modifies the set we're iterating through, invalidating + // the set iterator. the outer while loop makes sure that we + // recreate the set iterator each time the set itself is modified + while (keep_going) + { + keep_going = false; // only keep going if we find a pastecanvas parent to clear + for (std::set::iterator iter = parent_set.begin(); iter != parent_set.end(); iter++) + { + Layer_PasteCanvas* paste_canvas = dynamic_cast(*iter); + if(paste_canvas) + { + paste_canvas->set_sub_canvas(0); + keep_going = true; + break; // out of the for loop to the while loop + } + else + warning("destroyed canvas has a parent that is not a pastecanvas - please report if repeatable"); + } + } + //if(is_inline() && parent_) assert(0); _CanvasCounter::counter--; clear(); @@ -1016,7 +1044,7 @@ Canvas::get_meta_data_keys()const refer to "motion blur", they mean either of these two layers. */ void -synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_motion_blur_in_parent) +synfig::optimize_layers(Time time, Context context, Canvas::Handle op_canvas, bool seen_motion_blur_in_parent) { Context iter; @@ -1082,12 +1110,12 @@ synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_mot if(value.get_type()==ValueBase::TYPE_REAL && value.get(Real())==0) continue; - Layer_PasteCanvas* paste_canvas(static_cast(layer.get())); - // note: this used to include "&& paste_canvas->get_time_offset()==0", but then // time-shifted layers weren't being sorted by z-depth (bug #1806852) if(layer->get_name()=="PasteCanvas") { + Layer_PasteCanvas* paste_canvas(static_cast(layer.get())); + // we need to blur the sub canvas if: // our parent is blurred, // or the child is lower than a local blur, @@ -1112,7 +1140,7 @@ synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_mot Canvas::Handle sub_canvas(Canvas::create_inline(op_canvas)); Canvas::Handle paste_sub_canvas = paste_canvas->get_sub_canvas(); if(paste_sub_canvas) - optimize_layers(paste_sub_canvas->get_context(),sub_canvas,motion_blurred); + optimize_layers(time, paste_sub_canvas->get_context(),sub_canvas,motion_blurred); // \todo: uncommenting the following breaks the rendering of at least examples/backdrop.sifz quite severely // #define SYNFIG_OPTIMIZE_PASTE_CANVAS @@ -1170,6 +1198,45 @@ synfig::optimize_layers(Context context, Canvas::Handle op_canvas, bool seen_mot dynamic_cast(new_layer.get())->set_muck_with_time(true); layer=new_layer; } + else // not a PasteCanvas - does it use blend method 'Straight'? + { + /* when we use the 'straight' blend method, every pixel on the layer affects the layers underneath, + * not just the non-transparent pixels; the following workarea wraps non-pastecanvas layers in a + * new pastecanvas to ensure that the straight blend affects the full plane, not just the area + * within the layer's bounding box + */ + + // \todo: this code probably needs modification to work properly with motionblur and duplicate + etl::handle composite = etl::handle::cast_dynamic(layer); + + /* some layers (such as circle) don't touch pixels that aren't + * part of the circle, so they don't get blended correctly when + * using a straight blend. so we encapsulate the circle, and the + * encapsulation layer takes care of the transparent pixels + * for us. if we do that for all layers, however, then the + * distortion layers no longer work, since they have no + * context to work on. the Layer::reads_context() method + * returns true for layers which need to be able to see + * their context. we can't encapsulate those. + */ + if (composite && + Color::is_straight(composite->get_blend_method()) && + !composite->reads_context()) + { + Canvas::Handle sub_canvas(Canvas::create_inline(op_canvas)); + sub_canvas->push_back(composite = composite->clone()); + layer = Layer::create("PasteCanvas"); + composite->set_description(strprintf("Wrapped clone of '%s'", composite->get_non_empty_description().c_str())); + layer->set_description(strprintf("PasteCanvas wrapper for '%s'", composite->get_non_empty_description().c_str())); + Layer_PasteCanvas* paste_canvas(static_cast(layer.get())); + paste_canvas->set_blend_method(composite->get_blend_method()); + paste_canvas->set_amount(composite->get_amount()); + sub_canvas->set_time(time); // region and outline don't calculate their bounding rects until their time is set + composite->set_blend_method(Color::BLEND_STRAIGHT); // do this before calling set_sub_canvas(), but after set_time() + composite->set_amount(1.0f); // after set_time() + paste_canvas->set_sub_canvas(sub_canvas); + } + } sort_list.push_back(std::pair(z_depth,layer)); //op_canvas->push_back_simple(layer);