Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RenderScale #920

Merged
merged 3 commits into from
Sep 12, 2023
Merged

Conversation

acolwell
Copy link
Collaborator

Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. Additionally, make sure you've done all of these things:

PR Description

What type of PR is this? (Check one of the boxes below)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality nor fixes a bug but improves Natron in some way)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My change requires a change to the documentation
    • I have updated the documentation accordingly

What does this pull request do?

This change refactors RenderScale so that much of the code that uses it is much simpler. It also makes it much more explicit that Natron does not actually allow/support the x & y scale to be different from each other. Functionally this should be equivalent to the existing code and no new functionality was added.

  • Moved RenderScale declaration to its own file.
  • Removed inheritance from OfxPointD so implementation could be changed.
  • Made data members private to hide implementation and created helper methods to capture common use patterns.
  • Change TrackerNodeInteract::selectedMarkerScale to a double since it didn't really need to be a RenderScale.
  • Added named constant for RenderScale with x & y set to 1.
  • Changed the underlying implementation from a pair of doubles to an unsigned int that stores the mipmapLevel.

Have you tested your changes (if applicable)? If so, how?

Yes. I've tested this locally with a few project files. The unit tests all pass locally and in the GitHub Actions.

Futher details of this pull request

This came about mainly from me trying to understand why mipmapLevels and RenderScales were being passed around to different APIs and sometimes both were passed together. There also appeared to be more conversions to/from mipmapLevel then actual use of the doubles so it seemed to make sense to just convert the underlying representation to the mipmapLevel. I suspect further simplifications can be made in follow up changes and some usage of RenderScale can go away or be replaced with the equivalent mipmapLevel parameter. This change was just intended to leave the existing abstraction in place, but make the API more explicit and constrained.

- Moved declaration to its own file.
- Removed inheritance from OfxPointD so implementation could be changed.
- Made data members private to hide implementation and created
  helper methods to capture common use patterns.
- Change TrackerNodeInteract::selectedMarkerScale to a double since
  it didn't really need to be a RenderScale.
- Added named constant for RenderScale with x & y set to 1.
RenderScale
RenderScale::fromMipmapLevel(unsigned int mipmapLevel)
{
return RenderScale(mipmapLevel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

unsigned int
RenderScale::toMipmapLevel() const
{
return mipmapLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline?

OfxPointD
RenderScale::toOfxPointD() const
{
const double scale = Image::getScaleFromMipMapLevel(mipmapLevel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline and move function to RenderScale where it fits better than Image?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Also removed the function from Image since this change eliminates most of the callers.

// static
const RenderScale RenderScale::identity;

RenderScale::RenderScale(unsigned int mipmapLevel_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

constexpr RenderScale() = default;

// Named constant where x & y scale are both 1. (i.e the identity scale factor in both directions.)
static const RenderScale identity;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean that this constant will never be inlined? if this is the case, why not use the default constructor instead of this named constant? Or could this be constexpr instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since most RenderScale parameters are const RenderScale& the inlining doesn't really matter. This static var would always be a constant address that would get passed to the function whereas the default constructor would just use some stack space with a constant value. No real perf or code size difference here. I mainly added this constant to help with readability since it appeared that some code was trying to use names like scaleOne or explicitly specifying a scale of 1 to a constructor to signal identity. I'm fine with just using the default constructor everywhere if you'd like.

I tried making this constexpr but ran into problems. I believe I need to have C++17 semantics to get that to work. FWIW I'd love to upgrade to C++20 (but could settle for 17). I suspect that's a discussion for another pull request though.

Copy link
Member

@devernay devernay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@acolwell acolwell merged commit 3eded34 into NatronGitHub:RB-2.5 Sep 12, 2023
3 checks passed
@acolwell acolwell deleted the refactor_renderscale branch September 12, 2023 18:51
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