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

Initial support for sweep gradients in Cairo and CoreGraphics backends #16

Merged
merged 5 commits into from
May 12, 2021

Conversation

horasio
Copy link
Contributor

@horasio horasio commented May 11, 2021

Common code in base.py
Cairo backend uses mesh gradient, so uses fewer curved triangles
CoreGraphics uses flat-shader triangles with acute angle less than half a degree

Edit: this partially addresses #5.

@justvanrossum
Copy link
Collaborator

Thanks! This is really cool.

I would love the _buildSweepGradientPatches method to become a function buildSweepGradientPatches in its own module "blackrenderer/backends/sweepGradient.py".

The idea of "blackrenderer/backends/base.py" is that it contains only two things: 1) abstract base classes that define the interfaces for Canvas and Surface and 2) derived functionality that applies to all backend (such as the drawRectXxxx API variants and the simpler transform methods.

Since the sweep gradient support code is not needed for Skia (and may generally depend on the individual backend), I don't think it belongs in base.py.

@@ -9,27 +9,50 @@ def buildSweepGradientPatches(
startAngle,
endAngle,
useGouraudShading,
maxAngle=-1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

A more Pythonic way to indicate a default would be None.

Suggested change
maxAngle=-1,
maxAngle=None,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes :-)

if useGouraudShading:
maxAngle = pi / 360.0
radius = 1.05 * radius # we will use straight-edged triangles
if maxAngle == -1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if maxAngle == -1:
if maxAngle is None:

Lib/blackrenderer/backends/sweepGradient.py Outdated Show resolved Hide resolved
@justvanrossum justvanrossum merged commit d2321ac into master May 12, 2021
@justvanrossum justvanrossum deleted the sweepGradient branch May 12, 2021 14:16
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