Skip to content

refactor: simpler gradient render task declarations - #3301

Merged
ice0 merged 1 commit into
synfig:masterfrom
rodolforg:simpler-gradient
Oct 22, 2024
Merged

ice0 merged 1 commit into
synfig:masterfrom
rodolforg:simpler-gradient

Conversation

@rodolforg

Copy link
Copy Markdown
Contributor

No description provided.

adn add proper SYNFIG_EXPORT for MSVC builds
@ice0

ice0 commented Oct 20, 2024

Copy link
Copy Markdown
Collaborator

Could you provide more details?
I thought the transform information was needed for rendering.

@rodolforg

rodolforg commented Oct 20, 2024 •

Copy link
Copy Markdown
Contributor Author

Could you provide more details?

TaskContour (used for layers based on Layer_Shape class, for example) and TaskMesh (used for Skeleton Deformation layer) use this feature.
They both inherit from rendering::TaskInterfaceTransformation and implement the method rendering::TaskInterfaceTransformation::get_transformation().

class TaskInterfaceTransformation
{
public:
virtual ~TaskInterfaceTransformation() { }
virtual Transformation::Handle get_transformation() const
{ return Transformation::Handle(); }
};

These two layers implement it by creating a variable named transformation [1][2] to hold this info and both use this internal variable in their rendering code [3][4].

[1] get_transformation() fetches internal transformation variable (TaskContour)

class TaskContour: public Task, public TaskInterfaceTransformation
{
public:
typedef etl::handle<TaskContour> Handle;
SYNFIG_EXPORT static Token token;
virtual Token::Handle get_token() const { return token.handle(); }
public:
Contour::Handle contour;
Real detail;
bool allow_antialias;
Holder<TransformationAffine> transformation;
TaskContour(): detail(1.0), allow_antialias(true) { }
virtual Rect calc_bounds() const;
virtual Transformation::Handle get_transformation() const
{ return transformation.handle(); }
};

[2] get_transformation() fetches internal transformation variable (TaskMesh)

class TaskMesh: public Task, public TaskInterfaceTransformation
{
public:
typedef etl::handle<TaskMesh> Handle;
static Token token;
virtual Token::Handle get_token() const { return token.handle(); }
Mesh::Handle mesh;
Holder<TransformationAffine> transformation;
virtual int get_pass_subtask_index() const
{ return sub_task() ? PASSTO_THIS_TASK : PASSTO_NO_TASK; }
virtual Transformation::Handle get_transformation() const
{ return transformation.handle(); }

[3] Use of its own transformation variable (TaskContourSW) - line 96

virtual bool run(RunParams&) const {
if (!is_valid())
return true;
if (!contour)
return false;
Vector ppu = get_pixels_per_unit();
Matrix bounds_transformation;
bounds_transformation.m00 = ppu[0];
bounds_transformation.m11 = ppu[1];
bounds_transformation.m20 = target_rect.minx - ppu[0]*source_rect.minx;
bounds_transformation.m21 = target_rect.miny - ppu[1]*source_rect.miny;
Matrix matrix = bounds_transformation * transformation->matrix;

[4] Use of its own transformation variable (TaskMeshSW) - line 72

virtual bool run(RunParams&) const {
if (!is_valid() || !sub_task() || !sub_task()->is_valid())
return true;
if (!mesh)
return false;
Vector ppu = get_pixels_per_unit();
Matrix transformation_matrix;
transformation_matrix.m00 = ppu[0];
transformation_matrix.m11 = ppu[1];
transformation_matrix.m20 = target_rect.minx - source_rect.minx*ppu[0];
transformation_matrix.m21 = target_rect.miny - source_rect.miny*ppu[1];
transformation_matrix *= transformation->matrix;

As you can see in this PR, Linear, Conical, Spiral, and Radial gradients implement the get_transformation() method, declare their transformation variables used in the method. However, none of them use this data in their renderer code. So it's useless.

By the way, this interface is used in OptimizerTransformation, for example, to merge transformations and avoid multiple consecutive layer resizes/offsets/rotations: it multiply multiple affine transformation matrices before applying into a raster surface.

@ice0
ice0 merged commit 46013ff into synfig:master Oct 22, 2024
@ice0

ice0 commented Oct 22, 2024

Copy link
Copy Markdown
Collaborator

Merged. Thank you!

@rodolforg
rodolforg deleted the simpler-gradient branch October 22, 2024 10:37
rodolforg added a commit to rodolforg/synfig that referenced this pull request Apr 20, 2025
morevnaproject pushed a commit that referenced this pull request Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants