From b8aa2b1e6d81296fe8a4a4e2cd644eb81bf5d062 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Feb 29 2020 12:17:07 +0000 Subject: remove old rendering from core layers --- diff --git a/synfig-core/src/synfig/layers/layer_bitmap.cpp b/synfig-core/src/synfig/layers/layer_bitmap.cpp index ad6cf25..c8f4795 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.cpp +++ b/synfig-core/src/synfig/layers/layer_bitmap.cpp @@ -351,273 +351,6 @@ synfig::Layer_Bitmap::get_color(Context context, const Point &pos)const } -CairoColor -synfig::Layer_Bitmap::get_cairocolor(Context context, const Point &pos)const -{ - // no cairo implementation - return context.get_cairocolor(pos); -} - - -bool -Layer_Bitmap::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb) const -{ - RENDER_TRANSFORMED_IF_NEED(__FILE__, __LINE__) - - std::lock_guard lock(mutex); - - Point tl(param_tl.get(Point())); - Point br(param_br.get(Point())); - int c(param_c.get(int())); - Real gamma_adjust(param_gamma_adjust.get(Real())); - - rendering::SurfaceResource::LockRead lsurf(rendering_surface); - if (!lsurf) - return false; - Surface &layer_surface = lsurf.cast()->get_surface(); // const cast - - int interp=c; - if(quality>=10) - interp=0; - else if(quality>=5 && interp>1) - interp=1; - - // We can only handle NN and Linear at the moment - //if(interp>1) - // return Layer_Composite::accelerated_render(context,surface,quality,renddesc,cb); - - //if we don't actually have a valid surface just skip us - if(!layer_surface.is_valid()) - { - // Render what is behind us - return context.accelerated_render(surface,quality,renddesc,cb); - } - - SuperCallback subcb(cb,1,10000,10001+renddesc.get_h()); - - if( get_amount()==1 && - get_blend_method()==Color::BLEND_STRAIGHT && - !trimmed && - renddesc.get_tl()==tl && - renddesc.get_br()==br) - { - // Check for the trivial case - if(layer_surface.get_w()==renddesc.get_w() && layer_surface.get_h()==renddesc.get_h() && gamma_adjust==1.0f) - { - if(cb && !cb->amount_complete(0,100)) return false; - *surface=layer_surface; - if(cb && !cb->amount_complete(100,100)) return false; - return true; - } - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - } - else - { - // Render what is behind us - if(!context.accelerated_render(surface,quality,renddesc,&subcb)) - return false; - } - - if(cb && !cb->amount_complete(10000,10001+renddesc.get_h())) return false; - - Point obr = renddesc.get_br(), - otl = renddesc.get_tl(); - - //Vector::value_type pw=renddesc.get_w()/(renddesc.get_br()[0]-renddesc.get_tl()[0]); - //Vector::value_type ph=renddesc.get_h()/(renddesc.get_br()[1]-renddesc.get_tl()[1]); - - //A = representation of input (just tl,br) //just a scaling right now - //B = representation of output (just tl,br) //just a scaling right now - //sa = scaling for input (0,1) -> (0,w/h) - //sb = scaling for output (0,1) -> (0,w/h) - - float outwf = obr[0] - otl[0]; - float outhf = obr[1] - otl[1]; - - int inw = layer_surface.get_w(); - int inh = layer_surface.get_h(); - - int outw = renddesc.get_w(); - int outh = renddesc.get_h(); - - float inwf, inhf; - Point itl, ibr; - - if (trimmed) - { - inwf = (br[0] - tl[0])*layer_surface.get_w()/width; - inhf = (br[1] - tl[1])*layer_surface.get_h()/height; - itl = Point(tl[0] + (br[0]-tl[0])*left/width, - tl[1] + (br[1]-tl[1])*top/height); - ibr = Point(tl[0] + (br[0]-tl[0])*(left+inw)/width, - tl[1] + (br[1]-tl[1])*(top+inh)/height); - } - else - { - inwf = br[0] - tl[0]; - inhf = br[1] - tl[1]; - itl = tl; - ibr = br; - } - - //need to get the input coords in output space, so we can clip - - //get the desired corners of the bitmap (in increasing order) in integers - //floating point corners - float x1f = (itl[0] - otl[0])*outw/outwf; - float x2f = (ibr[0] - otl[0])*outw/outwf; - float y1f = (itl[1] - otl[1])*outh/outhf; - float y2f = (ibr[1] - otl[1])*outh/outhf; - - if(x1f > x2f) swap(x1f,x2f); - if(y1f > y2f) swap(y1f,y2f); - - int x_start = max(0,(int)floor(x1f)); //probably floor - int x_end = min(outw,(int)ceil(x2f)); //probably ceil - int y_start = max(0,(int)floor(y1f)); //probably floor - int y_end = min(outh,(int)ceil(y2f)); //probably ceil - - //need to get the x,y,dx,dy values from output space to input, so we can do fast interpolation - - //get the starting position in input space... for interpolating - - // in int -> out float: - // Sb(B^-1)A(Sa^-1) x - float inx_start = (((x_start/*+0.5f*/)*outwf/outw + otl[0]) - itl[0])*inw/inwf; //may want to bias this (center of pixel)??? - float iny_start = (((y_start/*+0.5f*/)*outhf/outh + otl[1]) - itl[1])*inh/inhf; //may want to bias this (center of pixel)??? - - //calculate the delta values in input space for one pixel movement in output space - //same matrix but with a vector instead of a point... - float indx = outwf*(inw)/((outw)*inwf); //translations died - float indy = outhf*(inh)/((outh)*inhf); //translations died - - //perhaps use a DDA algorithm... if faster... - // will still want pixel fractions to be floating point since colors are - - //synfig::info("xstart:%d ystart:%d xend:%d yend:%d",x_start,y_start,x_end,y_end); - - //start drawing at the start of the bitmap (either origin or corner of input...) - //and get other info - Surface::alpha_pen pen(surface->get_pen(x_start,y_start)); - pen.set_alpha(get_amount()); - pen.set_blend_method(get_blend_method()); - - //perform normal interpolation - if(interp==0) - { - //synfig::info("Decided to do nearest neighbor"); - float iny, inx; - int x,y; - - //Point sample - truncate - iny = iny_start;//+0.5f; - for(y = y_start; y < y_end; y++, pen.inc_y(), iny += indy) - { - inx = inx_start;//+0.5f; - int yclamp = min(inh-1, max(0, round_to_int(iny))); - for(x = x_start; x < x_end; x++, pen.inc_x(), inx += indx) - { - int xclamp = min(inw-1, max(0, round_to_int(inx))); - Color c = filter(layer_surface[yclamp][xclamp]); - pen.put_value(c); //must get rid of the clip - } - pen.dec_x(x_end-x_start); - } - } - else - if(interp==1) - { - //bilinear filtering - - //float xmf,xpf,ymf,ypf; - //int xm,xp,ym,yp; - float inx,iny; - int x,y; - - //can probably buffer for x values... - - //loop and based on inx,iny sample input image - iny = iny_start; - for(y = y_start; y < y_end; y++, pen.inc_y(), iny += indy) - { - inx = inx_start; - for(x = x_start; x < x_end; x++, pen.inc_x(), inx += indx) - { - Color col(layer_surface.linear_sample(inx,iny)); - pen.put_value(filter(col)); - } - pen.dec_x(x_end-x_start); - - } - } - else - if(interp==2) - { - //cosine filtering - - //float xmf,xpf,ymf,ypf; - //int xm,xp,ym,yp; - float inx,iny; - int x,y; - - //can probably buffer for x values... - - //loop and based on inx,iny sample input image - iny = iny_start; - for(y = y_start; y < y_end; y++, pen.inc_y(), iny += indy) - { - inx = inx_start; - for(x = x_start; x < x_end; x++, pen.inc_x(), inx += indx) - { - Color col(layer_surface.cosine_sample(inx,iny)); - pen.put_value(filter(col)); - } - pen.dec_x(x_end-x_start); - - } - } - else - { - //cubic filtering - - //float xmf,xpf,ymf,ypf; - //int xm,xp,ym,yp; - float inx,iny; - int x,y; - - //can probably buffer for x values... - - //loop and based on inx,iny sample input image - iny = iny_start; - for(y = y_start; y < y_end; y++, pen.inc_y(), iny += indy) - { - inx = inx_start; - for(x = x_start; x < x_end; x++, pen.inc_x(), inx += indx) - { - Color col(layer_surface.cubic_sample(inx,iny)); - pen.put_value(filter(col)); - } - pen.dec_x(x_end-x_start); - - } - } - - return true; -} - -///// -///// - -bool -Layer_Bitmap::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb) const -{ - // no cairo implementation - return context.accelerated_cairorender(cr,quality,renddesc,cb); -} - -///// - - Rect Layer_Bitmap::get_bounding_rect()const { diff --git a/synfig-core/src/synfig/layers/layer_bitmap.h b/synfig-core/src/synfig/layers/layer_bitmap.h index 3071206..e73bf6a 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.h +++ b/synfig-core/src/synfig/layers/layer_bitmap.h @@ -83,15 +83,11 @@ public: virtual ValueBase get_param(const String & param)const; virtual Color get_color(Context context, const Point &pos)const; - virtual CairoColor get_cairocolor(Context context, const Point &pos)const; virtual Vocab get_param_vocab()const; virtual Rect get_bounding_rect()const; - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; protected: diff --git a/synfig-core/src/synfig/layers/layer_composite.cpp b/synfig-core/src/synfig/layers/layer_composite.cpp index 61b2fd5..ff63035 100644 --- a/synfig-core/src/synfig/layers/layer_composite.cpp +++ b/synfig-core/src/synfig/layers/layer_composite.cpp @@ -76,92 +76,6 @@ Layer_Composite::Layer_Composite(Real a, Color::BlendMethod bm): SET_STATIC_DEFAULTS(); } -bool -Layer_Composite::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb) const -{ - RENDER_TRANSFORMED_IF_NEED(__FILE__, __LINE__) - - Real amount(param_amount.get(Real())); - if(!amount) - return context.accelerated_render(surface,quality,renddesc,cb); - - CanvasBase image; - - SuperCallback stageone(cb,0,50000,100000); - SuperCallback stagetwo(cb,50000,100000,100000); - - Context iter; - - Layer_Bitmap::Handle surfacelayer(new class Layer_Bitmap()); - for(iter=context;*iter;iter++) - image.push_back(*iter); - image.push_front(surfacelayer.get()); - - // We want to go ahead and schedule any other - // layers... -// while(dynamic_cast(context->get())) -// while(context->get() && -// &context->get()->AcceleratedRender== -// &Layer_Composite::AcceleratedRender) -// image.push_back(*(context++)); - - image.push_back(0); // Alpha black - - // sub_surface will destroyed with sub_surface_sw - Surface *sub_surface = new Surface(); - - // Render the backdrop on the surface layer's surface. - if(!context.accelerated_render(sub_surface,quality,renddesc,&stageone)) - return false; - - if (!sub_surface->is_valid()) - return false; - - surfacelayer->rendering_surface = new rendering::SurfaceResource( - new rendering::SurfaceSW(*sub_surface, true) ); - - // Sets up the interpolation of the context (now the surface layer is the first one) - // depending on the quality - if(quality<=4)surfacelayer->set_param("c", 3);else - if(quality<=5)surfacelayer->set_param("c", 2); - else if(quality<=6)surfacelayer->set_param("c", 1); - else surfacelayer->set_param("c",0); - surfacelayer->set_param("tl",renddesc.get_tl()); - surfacelayer->set_param("br",renddesc.get_br()); - // Sets the blend method to straight. See below - surfacelayer->set_blend_method(Color::BLEND_STRAIGHT); - // Push this layer on the image. The blending result is only this layer - // and the surface layer. The rest of the context is ignored by the straight - // blend method of surface layer - image.push_front(const_cast(this)); - - // Set up a surface target - Target_Scanline::Handle target(surface_target_scanline(surface)); - - if(!target) - { - if(cb)cb->error(_("Unable to create surface target")); - return false; - } - - RendDesc desc(renddesc); - - target->set_rend_desc(&desc); - - // Render the scene - return render(Context(image.begin(),context),target,desc,&stagetwo); -} - - -///// -bool -Layer_Composite::accelerated_cairorender(Context context,cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb) const -{ - // no cairo implementation - return context.accelerated_cairorender(cr,quality,renddesc,cb); -} - - Rect Layer_Composite::get_full_bounding_rect(Context context)const { diff --git a/synfig-core/src/synfig/layers/layer_composite.h b/synfig-core/src/synfig/layers/layer_composite.h index 45f3594..f5f5ec2 100644 --- a/synfig-core/src/synfig/layers/layer_composite.h +++ b/synfig-core/src/synfig/layers/layer_composite.h @@ -88,9 +88,6 @@ public: //!Returns the rectangle that includes the context of the layer and //! the intersection of the layer in case it is active and not onto virtual Rect get_full_bounding_rect(Context context)const; - //! Renders the layer composited on the context and puts it on the target surface. - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; protected: virtual rendering::Task::Handle build_composite_task_vfunc(ContextParams context_params)const; diff --git a/synfig-core/src/synfig/layers/layer_duplicate.cpp b/synfig-core/src/synfig/layers/layer_duplicate.cpp index edd58ce..f566070 100644 --- a/synfig-core/src/synfig/layers/layer_duplicate.cpp +++ b/synfig-core/src/synfig/layers/layer_duplicate.cpp @@ -158,103 +158,6 @@ Layer_Duplicate::get_duplicate_param()const return ValueNode_Duplicate::Handle::cast_dynamic(param); } -bool -Layer_Duplicate::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - RENDER_TRANSFORMED_IF_NEED(__FILE__, __LINE__) - - if(quality == 10) - return context.accelerated_render(surface,quality,renddesc,cb); - - if(context->empty()) - { - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->clear(); - return true; - } - - SuperCallback subimagecb; - Surface tmp; - int i = 0; - - handle duplicate_param = get_duplicate_param(); - if (!duplicate_param) return context.accelerated_render(surface,quality,renddesc,cb); - - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->clear(); - - Color::BlendMethod blend_method(get_blend_method()); - Time time_cur = get_time_mark(); - int steps = duplicate_param->count_steps(time_cur); - - std::lock_guard lock(mutex); - duplicate_param->reset_index(time_cur); - do - { - subimagecb=SuperCallback(cb,i*(5000/steps),(i+1)*(5000/steps),5000); - context.set_time(time_cur, true); - if(!context.accelerated_render(&tmp,quality,renddesc,&subimagecb)) return false; - - Surface::alpha_pen apen(surface->begin()); - apen.set_alpha(get_amount()); - // \todo have a checkbox allowing use of 'behind' to reverse the order? - apen.set_blend_method(i ? blend_method : Color::BLEND_COMPOSITE); - tmp.blit_to(apen); - i++; - } while (duplicate_param->step(time_cur)); - - return true; -} - -///// -bool -Layer_Duplicate::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - if(quality == 10) - return context.accelerated_cairorender(cr,quality,renddesc,cb); - - if(context->empty()) - { - cairo_save(cr); - cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); - cairo_paint(cr); - cairo_restore(cr); - return true; - } - - SuperCallback subimagecb; - - int i = 0; - - handle duplicate_param = get_duplicate_param(); - if (!duplicate_param) return context.accelerated_cairorender(cr,quality,renddesc,cb); - - Color::BlendMethod blend_method(get_blend_method()); - Time time_cur = get_time_mark(); - int steps = duplicate_param->count_steps(time_cur); - - std::lock_guard lock(mutex); - duplicate_param->reset_index(time_cur); - cairo_save(cr); - do - { - subimagecb=SuperCallback(cb,i*(5000/steps),(i+1)*(5000/steps),5000); - context.set_time(time_cur, true); - cairo_push_group(cr); - if(!context.accelerated_cairorender(cr,quality,renddesc,&subimagecb)) - { - cairo_pop_group(cr); - return false; - } - cairo_pop_group_to_source(cr); - // \todo have a checkbox allowing use of 'behind' to reverse the order? - cairo_paint_with_alpha_operator(cr, get_amount(), i ? blend_method : Color::BLEND_COMPOSITE); - i++; - } while (duplicate_param->step(time_cur)); - cairo_restore(cr); - return true; -} - rendering::Task::Handle Layer_Duplicate::build_rendering_task_vfunc(Context context) const { diff --git a/synfig-core/src/synfig/layers/layer_duplicate.h b/synfig-core/src/synfig/layers/layer_duplicate.h index 6701574..04e1557 100644 --- a/synfig-core/src/synfig/layers/layer_duplicate.h +++ b/synfig-core/src/synfig/layers/layer_duplicate.h @@ -54,8 +54,6 @@ public: virtual ValueBase get_param(const String & param)const; virtual Color get_color(Context context, const Point &pos)const; virtual ValueNode_Duplicate::Handle get_duplicate_param()const; - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; virtual Vocab get_param_vocab()const; virtual bool reads_context()const { return true; } diff --git a/synfig-core/src/synfig/layers/layer_invisible.cpp b/synfig-core/src/synfig/layers/layer_invisible.cpp index 1ca6ff0..16647bf 100644 --- a/synfig-core/src/synfig/layers/layer_invisible.cpp +++ b/synfig-core/src/synfig/layers/layer_invisible.cpp @@ -53,15 +53,6 @@ using namespace synfig; Layer_Invisible::Layer_Invisible() { } -bool -Layer_Invisible::accelerated_render(Context context, Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const - { return context.accelerated_render(surface,quality,renddesc,cb); } - - -bool -Layer_Invisible::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const - { return context.accelerated_cairorender(cr,quality,renddesc,cb); } - rendering::Task::Handle Layer_Invisible::build_rendering_task_vfunc(Context context)const { return context.build_rendering_task(); } diff --git a/synfig-core/src/synfig/layers/layer_invisible.h b/synfig-core/src/synfig/layers/layer_invisible.h index 82ef5fd..3dbec83 100644 --- a/synfig-core/src/synfig/layers/layer_invisible.h +++ b/synfig-core/src/synfig/layers/layer_invisible.h @@ -46,11 +46,6 @@ protected: //! Default constructor. Not used directly. Layer_Invisible(); -public: - //! Renders the layer composited on the context and puts it on the target surface. - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - protected: virtual rendering::Task::Handle build_rendering_task_vfunc(Context context)const; }; // END of class Layer_Invisible diff --git a/synfig-core/src/synfig/layers/layer_motionblur.cpp b/synfig-core/src/synfig/layers/layer_motionblur.cpp index 5367041..b7b54ef 100644 --- a/synfig-core/src/synfig/layers/layer_motionblur.cpp +++ b/synfig-core/src/synfig/layers/layer_motionblur.cpp @@ -155,254 +155,6 @@ Layer_MotionBlur::get_param_vocab()const return ret; } -bool -Layer_MotionBlur::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - RENDER_TRANSFORMED_IF_NEED(__FILE__, __LINE__) - - Time aperture=param_aperture.get(Time()); - Real subsamples_factor=param_subsamples_factor.get(Real()); - SubsamplingType subsampling_type=(SubsamplingType)param_subsampling_type.get(int()); - Real subsample_start=param_subsample_start.get(Real()); - Real subsample_end=param_subsample_end.get(Real()); - - if(aperture && quality<=10) - { - //int x, y; - SuperCallback subimagecb; - int samples=1; - switch(quality) - { - case 1: // Production Quality - samples=32; - break; - case 2: // Excellent Quality - samples=24; - break; - case 3: // Good Quality - samples=16; - break; - case 4: // Moderate Quality - samples=12; - break; - case 5: // Draft Quality - samples=7; - break; - case 6: - samples=6; - break; - case 7: - samples=5; - break; - case 8: - samples=3; - break; - case 9: - samples=2; - break; - case 10: // Rough Quality - default: - samples=1; - break; - - } - - samples *= subsamples_factor; - - if (samples <= 1) return context.accelerated_render(surface,quality,renddesc,cb); - - // Only in modes where subsample_start/end matters... - if(subsampling_type == SUBSAMPLING_LINEAR) - { - // We won't render when the scale==0, so we'll use those samples elsewhere - if(subsample_start == 0) samples++; - if(subsample_end == 0) samples++; - } - - Surface tmp; - int i; - float scale, divisor = 0; - - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->clear(); - - // Render subsamples from time_cur-aperture to time_cur - for(i=0;iamount_complete(0,10000)) return false; - - if(depth==MAX_DEPTH) - // if we are at the extent of our depth, - // then we should just return whatever is under us. - return context.accelerated_render(surface,quality,renddesc,cb); - - depth_counter counter(depth); - - if(!sub_canvas || !get_amount()) - return context.accelerated_render(surface,quality,renddesc,cb); - - SuperCallback stageone(cb,0,4500,10000); - SuperCallback stagetwo(cb,4500,9000,10000); - SuperCallback stagethree(cb,9000,9999,10000); - - CanvasBase queue; - Context canvasContext = build_context_queue(context, queue); - - if (is_solid_color()) - { - RendDesc intermediate_desc(renddesc); - intermediate_desc.clear_flags(); - intermediate_desc.set_transformation_matrix(transformation.get_matrix()); - return canvasContext.accelerated_render(surface,quality,intermediate_desc,&stagetwo); - } - else - if (!context.accelerated_render(surface,quality,renddesc,&stageone)) - return false; - - Color::BlendMethod blend_method(get_blend_method()); - const Rect full_bounding_rect(canvasContext.get_full_bounding_rect()); - - Rect inner_bounds( - full_bounding_rect.get_min(), - full_bounding_rect.get_max() - ); - inner_bounds &= transformation.back_transform_bounds(renddesc.get_rect()); - Rect outer_bounds(transformation.transform_bounds(inner_bounds)); - outer_bounds &= renddesc.get_rect(); - if (!outer_bounds.is_valid()) - return true; - - Rect next_bounds( Transformation::transform_bounds(renddesc.get_transformation_matrix(), context.get_full_bounding_rect()) ); - - // sometimes the user changes the parameters while we're - // rendering, causing our pasted canvas' bounding box to shrink - // and no longer overlap with our tile. if that has happened, - // let's just stop now - we'll be refreshing soon anyway - //! \todo shouldn't a mutex ensure this isn't needed? - // http://synfig.org/images/d/d2/Bbox-change.sifz is an example - // that shows this happening - open the encapsulation, select the - // 'shade', and toggle the 'invert' parameter quickly. - // Occasionally you'll see: - // error: Context::accelerated_render(): Layer "shade" threw a bad_alloc exception! - // where the shade layer tries to allocate itself a canvas of - // negative proportions, due to changing bounding boxes. - if (!inner_bounds.is_valid()) - { - warning("%s:%d bounding box shrank while rendering?", __FILE__, __LINE__); - return true; - } - - bool blend_using_straight = false; // use 'straight' just for the central blit - - if (!etl::intersect(next_bounds,outer_bounds)) - { - // if there's no intersection between the context and our - // surface, and we're rendering 'onto', then we're done - if (Color::is_onto(blend_method) && !Color::is_straight(blend_method)) - return true; - - /* 'straight' is faster than 'composite' and has the same - * effect if the affected area of the lower layer is - * transparent; however, if we're not clipping the blit to - * just the bounding rectangle, the affected area is the whole - * tile, so we can't use this optimisation. if we are - * clipping, then we can use 'straight' to blit the clipped - * rectangle, but we shouldn't set blend_method to 'straight', - * or the surrounding areas will be blanked, which we don't - * want. - */ -#ifdef SYNFIG_CLIP_PASTECANVAS - if (blend_method==Color::BLEND_COMPOSITE) blend_using_straight = true; -#endif // SYNFIG_CLIP_PASTECANVAS - } - - int w = renddesc.get_w(); - int h = renddesc.get_h(); - Vector tl = renddesc.get_tl(); - Vector br = renddesc.get_br(); - Vector size = br - tl; - Real rx0 = (outer_bounds.minx - tl[0])/size[0]*w; - Real rx1 = (outer_bounds.maxx - tl[0])/size[0]*w; - Real ry0 = (outer_bounds.miny - tl[1])/size[1]*h; - Real ry1 = (outer_bounds.maxy - tl[1])/size[1]*h; - if (rx1 < rx0) { Real rx = rx0; rx0 = rx1; rx1 = rx; } - if (ry1 < ry0) { Real ry = ry0; ry0 = ry1; ry1 = ry; } - int x0((floor(rx0))); - int x1((ceil(rx1))); - int y0((floor(ry0))); - int y1((ceil(ry1))); - - if (x0 < 0) x0 = 0; else if (x0 > w) x0 = w; - if (x1 < 0) x1 = 0; else if (x1 > w) x1 = w; - if (y0 < 0) y0 = 0; else if (y0 > h) y0 = h; - if (y1 < 0) y1 = 0; else if (y1 > h) y1 = h; - int intermediate_w = x1 - x0; - int intermediate_h = y1 - y0; - Vector pixel_aligned_tl( - (Real)x0/(Real)w*size[0] + tl[0], - (Real)y0/(Real)h*size[1] + tl[1] ); - Vector pixel_aligned_br( - (Real)x1/(Real)w*size[0] + tl[0], - (Real)y1/(Real)h*size[1] + tl[1] ); - - if (intermediate_w > 0 && intermediate_h > 0) { - RendDesc intermediate_desc(renddesc); - intermediate_desc.clear_flags(); - intermediate_desc.set_transformation_matrix(transformation.get_matrix()); - intermediate_desc.set_wh(intermediate_w, intermediate_h); - intermediate_desc.set_tl(pixel_aligned_tl); - intermediate_desc.set_br(pixel_aligned_br); - Surface intermediate_surface; - - //{ // TODO: remove - // std::ofstream of("/tmp/contours.txt", std::ios_base::app); - // of << "g " << x0 << " " << y0 << endl; - //} - - if(!canvasContext.accelerated_render(&intermediate_surface,quality,intermediate_desc,&stagetwo)) - return false; - - //{ // TODO: remove - // std::ofstream of("/tmp/contours.txt", std::ios_base::app); - // of << "end" << endl; - //} - - Surface::alpha_pen apen(surface->get_pen(x0, y0)); - apen.set_alpha(get_amount()); - apen.set_blend_method(blend_using_straight ? Color::BLEND_STRAIGHT : blend_method); - intermediate_surface.blit_to(apen); - } - - if(cb && !cb->amount_complete(10000,10000)) return false; - return true; -} - -/////// - -bool -Layer_PasteCanvas::accelerated_cairorender(Context context,cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - Transformation transformation(get_summary_transformation()); - - if(cb && !cb->amount_complete(0,10000)) return false; - - if(depth==MAX_DEPTH) - // if we are at the extent of our depth, - // then we should just return whatever is under us. - return context.accelerated_cairorender(cr,quality,renddesc,cb); - - depth_counter counter(depth); - - if(!sub_canvas || !get_amount()) - return context.accelerated_cairorender(cr,quality,renddesc,cb); - - SuperCallback stageone(cb,0,4500,10000); - SuperCallback stagetwo(cb,4500,9000,10000); - SuperCallback stagethree(cb,9000,9999,10000); - - - bool ret; - RendDesc workdesc(renddesc); - - // Render the background - ret=context.accelerated_cairorender(cr, quality, renddesc, &stagethree); - if(!ret) - return false; - - // render the canvas to be pasted onto pastesurface - cairo_surface_t* pastesurface=cairo_surface_create_similar_image(cairo_get_target(cr), CAIRO_FORMAT_ARGB32, workdesc.get_w(), workdesc.get_h()); - cairo_t* subcr=cairo_create(pastesurface); - // apply the transformations form the current context - cairo_matrix_t matrix; - cairo_get_matrix(cr, &matrix); - - // apply the transformations form the (paste canvas) group layer - cairo_set_matrix(subcr, &matrix); - - cairo_matrix_t cairo_transformation_matrix; - Matrix transformation_matrix(transformation.get_matrix()); - cairo_matrix_init( - &cairo_transformation_matrix, - transformation_matrix.m00, - transformation_matrix.m01, - transformation_matrix.m10, - transformation_matrix.m11, - transformation_matrix.m20, - transformation_matrix.m21 ); - - cairo_transform(subcr, &cairo_transformation_matrix); - - // Effectively render the canvas content - CanvasBase queue; - ret=build_context_queue(context, queue).accelerated_cairorender(subcr, quality, workdesc, &stagetwo); - // we are done apply the result to the source - cairo_destroy(subcr); - - if(!ret) - return false; - // Let's paint the result with its alpha - cairo_save(cr); - - cairo_status_t status; - status=cairo_matrix_invert(&matrix); - if(status) // doh! the matrix can't be inverted! - { - synfig::error("Can't invert current Cairo matrix!"); - return false; - } - // apply the inverse of the transformation of the current context to - // compensate the pending transformations form cr to be applied. - cairo_transform(cr, &matrix); - cairo_set_source_surface(cr, pastesurface, 0, 0); - cairo_paint_with_alpha_operator(cr, get_amount(), get_blend_method()); - - cairo_restore(cr); - cairo_surface_destroy(pastesurface); - - if(cb && !cb->amount_complete(10000,10000)) return false; - - return true; -} -/////// - - -void Layer_PasteCanvas::get_times_vfunc(Node::time_set &set) const +void +Layer_PasteCanvas::get_times_vfunc(Node::time_set &set) const { Real time_dilation=param_time_dilation.get(Real()); Time time_offset=param_time_offset.get(Time()); diff --git a/synfig-core/src/synfig/layers/layer_pastecanvas.h b/synfig-core/src/synfig/layers/layer_pastecanvas.h index 1a5c4f2..07a3f7e 100644 --- a/synfig-core/src/synfig/layers/layer_pastecanvas.h +++ b/synfig-core/src/synfig/layers/layer_pastecanvas.h @@ -172,10 +172,6 @@ public: //! Gets the blend color of the Layer in the context at \a pos virtual Color get_color(Context context, const Point &pos)const; - //! Renders the Canvas to the given Surface in an accelerated manner - //! See Layer::accelerated_render - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; //! Bounding rect for this layer depends from context_params Rect get_bounding_rect_context_dependent(const ContextParams &context_params)const; //!Returns the rectangle that includes the context of the layer and diff --git a/synfig-core/src/synfig/layers/layer_shape.cpp b/synfig-core/src/synfig/layers/layer_shape.cpp index 4de8457..e44e23d 100644 --- a/synfig-core/src/synfig/layers/layer_shape.cpp +++ b/synfig-core/src/synfig/layers/layer_shape.cpp @@ -320,176 +320,6 @@ Layer_Shape::sync_vfunc() { } bool -Layer_Shape::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - sync(); - Color color=param_color.get(Color()); - Point origin=param_origin.get(Point()); - bool invert =param_invert.get(bool(true)); - int blurtype=param_blurtype.get(int()); - Real feather=param_feather.get(Real()); - - const unsigned int w = renddesc.get_w(); - const unsigned int h = renddesc.get_h(); - - const Real pw = abs(renddesc.get_pw()); - const Real ph = abs(renddesc.get_ph()); - - SuperCallback stageone(cb,1,10000,15001+renddesc.get_h()); - SuperCallback stagetwo(cb,10000,10001+renddesc.get_h(),15001+renddesc.get_h()); - SuperCallback stagethree(cb,10001+renddesc.get_h(),15001+renddesc.get_h(),15001+renddesc.get_h()); - - // Render what is behind us - - //clip if it satisfies the invert solid thing - if(is_solid_color() && invert) - { - Rect aabb = contour->get_bounds(); - Point tl = renddesc.get_tl() - origin; - - Real pw = renddesc.get_pw(), - ph = renddesc.get_ph(); - - Rect nrect; - - Real pixelfeatherx = quality == 10 ? 0 : abs(feather/pw), - pixelfeathery = quality == 10 ? 0 : abs(feather/ph); - - nrect.set_point((aabb.minx - tl[0])/pw,(aabb.miny - tl[1])/ph); - nrect.expand((aabb.maxx - tl[0])/pw,(aabb.maxy - tl[1])/ph); - - RendDesc optdesc(renddesc); - - //make sure to expand so we gain subpixels rather than lose them - nrect.minx = floor(nrect.minx-pixelfeatherx); nrect.miny = floor(nrect.miny-pixelfeathery); - nrect.maxx = ceil(nrect.maxx+pixelfeatherx); nrect.maxy = ceil(nrect.maxy+pixelfeathery); - - //make sure the subwindow is clipped with our tile window (minimize useless drawing) - set_intersect(nrect,nrect,Rect(0,0,renddesc.get_w(),renddesc.get_h())); - - //must resize the surface first - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->clear(); - - //only render anything if it's visible from our current tile - if(nrect.valid()) - { - //set the subwindow to the viewable pixels and render it to the subsurface - optdesc.set_subwindow((int)nrect.minx, (int)nrect.miny, - (int)(nrect.maxx - nrect.minx), (int)(nrect.maxy - nrect.miny)); - - Surface optimizedbacksurf; - if(!context.accelerated_render(&optimizedbacksurf,quality,optdesc,&stageone)) - return false; - - //blit that onto the original surface so we can pretend that nothing ever happened - Surface::pen p = surface->get_pen((int)nrect.minx,(int)nrect.miny); - optimizedbacksurf.blit_to(p); - } - }else - { - if(!context.accelerated_render(surface,quality,renddesc,&stageone)) - return false; - } - - if(cb && !cb->amount_complete(10000,10001+renddesc.get_h())) return false; - - if(feather && quality != 10) - { - //we have to blur rather than be crappy - - //so make a separate surface - RendDesc workdesc(renddesc); - - Surface shapesurface; - - //the expanded size = 1/2 the size in each direction rounded up - int halfsizex = (int) (abs(feather*.5/pw) + 3), - halfsizey = (int) (abs(feather*.5/ph) + 3); - - //expand by 1/2 size in each direction on either side - switch(blurtype) - { - case Blur::DISC: - case Blur::BOX: - case Blur::CROSS: - { - workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),w+2*max(1,halfsizex),h+2*max(1,halfsizey)); - break; - } - case Blur::FASTGAUSSIAN: - { - if(quality < 4) - { - halfsizex*=2; - halfsizey*=2; - } - workdesc.set_subwindow(-max(1,halfsizex),-max(1,halfsizey),w+2*max(1,halfsizex),h+2*max(1,halfsizey)); - break; - } - case Blur::GAUSSIAN: - { - #define GAUSSIAN_ADJUSTMENT (0.05) - Real pw = (Real)workdesc.get_w()/(workdesc.get_br()[0]-workdesc.get_tl()[0]); - Real ph = (Real)workdesc.get_h()/(workdesc.get_br()[1]-workdesc.get_tl()[1]); - - pw=pw*pw; - ph=ph*ph; - - halfsizex = (int)(abs(pw)*feather*GAUSSIAN_ADJUSTMENT+0.5); - halfsizey = (int)(abs(ph)*feather*GAUSSIAN_ADJUSTMENT+0.5); - - halfsizex = (halfsizex + 1)/2; - halfsizey = (halfsizey + 1)/2; - workdesc.set_subwindow( -halfsizex, -halfsizey, w+2*halfsizex, h+2*halfsizey ); - - break; - } - } - - shapesurface.set_wh(workdesc.get_w(),workdesc.get_h()); - shapesurface.clear(); - - //render the shape - if(!render_shape(&shapesurface,false,workdesc))return false; - - //blur the image - Blur(feather,feather,blurtype,&stagethree)(shapesurface,workdesc.get_br()-workdesc.get_tl(),shapesurface); - - //blend with stuff below it... - unsigned int v = halfsizey, x = 0, y = 0; - for(y = 0; y < h; y++,v++) - { - unsigned int u = halfsizex; - for(x = 0; x < w; x++,u++) - { - Color::value_type a = shapesurface[v][u].get_a(); - if(a) - { - //a = floor(a*255+0.5f)/255; - (*surface)[y][x]=Color::blend(color,(*surface)[y][x],a*get_amount(),get_blend_method()); - } - //else (*surface)[y][x] = worksurface[v][u]; - } - } - - //we are done - if(cb && !cb->amount_complete(100,100)) - { - synfig::warning("Layer_Shape: could not set amount complete"); - return false; - } - - return true; - }else - { - //might take out to reduce code size - return render_shape(surface,true,renddesc); - } - -} - -bool Layer_Shape::render_shape(Surface *surface, bool useblend, const RendDesc &renddesc) const { Point origin=param_origin.get(Point()); diff --git a/synfig-core/src/synfig/layers/layer_shape.h b/synfig-core/src/synfig/layers/layer_shape.h index c7e89c8..f3f0b42 100644 --- a/synfig-core/src/synfig/layers/layer_shape.h +++ b/synfig-core/src/synfig/layers/layer_shape.h @@ -123,7 +123,6 @@ public: virtual Vocab get_param_vocab()const; virtual Color get_color(Context context, const Point &pos)const; - virtual bool accelerated_render(Context context, Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const; virtual Rect get_bounding_rect()const; diff --git a/synfig-core/src/synfig/layers/layer_solidcolor.cpp b/synfig-core/src/synfig/layers/layer_solidcolor.cpp index a8fe4b7..fb9efae 100644 --- a/synfig-core/src/synfig/layers/layer_solidcolor.cpp +++ b/synfig-core/src/synfig/layers/layer_solidcolor.cpp @@ -149,100 +149,6 @@ Layer_SolidColor::get_color(Context context, const Point &pos)const return Color::blend(color,context.get_color(pos),get_amount(),get_blend_method()); } -bool -Layer_SolidColor::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - Color color=param_color.get(Color()); - if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT) - { - // Mark our progress as starting - if(cb && !cb->amount_complete(0,1000)) - return false; - - surface->set_wh(renddesc.get_w(),renddesc.get_h()); - surface->fill(color); - - // Mark our progress as finished - if(cb && !cb->amount_complete(1000,1000)) - return false; - - return true; - } - - SuperCallback supercb(cb,0,9500,10000); - - if(!context.accelerated_render(surface,quality,renddesc,&supercb)) - return false; - - int x,y; - - Surface::alpha_pen apen(surface->begin()); - - apen.set_value(color); - apen.set_alpha(get_amount()); - apen.set_blend_method(get_blend_method()); - - for(y=0;yamount_complete(10000,10000)) - return false; - - return true; -} - -////// - -bool -Layer_SolidColor::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const -{ - Color color=param_color.get(Color()); - float r(color.get_r()), - g(color.get_g()), - b(color.get_b()), - a(color.get_a()); - - if((get_amount()==1.f && get_blend_method()==Color::BLEND_STRAIGHT) - || - (get_amount()==1.f && color.get_a()==1.f && get_blend_method()==Color::BLEND_COMPOSITE) - ) - { - // Mark our progress as starting - if(cb && !cb->amount_complete(0,1000)) - return false; - cairo_save(cr); - cairo_set_source_rgba(cr, r, g, b, a); - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_paint(cr); - cairo_restore(cr); - // Mark our progress as finished - if(cb && !cb->amount_complete(1000,1000)) - return false; - return true; - } - - SuperCallback supercb(cb,0,9500,10000); - - if(!context.accelerated_cairorender(cr,quality,renddesc,&supercb)) - return false; - - cairo_save(cr); - cairo_reset_clip(cr); - cairo_set_source_rgba(cr, r, g, b, a); - cairo_paint_with_alpha_operator(cr, get_amount(), get_blend_method()); - cairo_restore(cr); - - // Mark our progress as finished - if(cb && !cb->amount_complete(10000,10000)) - return false; - - return true; -} - -////// - rendering::Task::Handle Layer_SolidColor::build_composite_task_vfunc(ContextParams /*context_params*/)const { diff --git a/synfig-core/src/synfig/layers/layer_solidcolor.h b/synfig-core/src/synfig/layers/layer_solidcolor.h index c8a4cea..74bfd24 100644 --- a/synfig-core/src/synfig/layers/layer_solidcolor.h +++ b/synfig-core/src/synfig/layers/layer_solidcolor.h @@ -56,8 +56,6 @@ public: virtual Color get_color(Context context, const Point &pos)const; - virtual bool accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const; - virtual bool accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const; virtual Vocab get_param_vocab()const; virtual synfig::Layer::Handle hit_check(synfig::Context context, const synfig::Point &point)const;