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

[CGD2D] Draw primitives with Porter-Duff blend modes #1389

Closed
DHowett-MSFT opened this issue Nov 15, 2016 · 1 comment · Fixed by #2222
Closed

[CGD2D] Draw primitives with Porter-Duff blend modes #1389

DHowett-MSFT opened this issue Nov 15, 2016 · 1 comment · Fixed by #2222

Comments

@DHowett-MSFT
Copy link

DHowett-MSFT commented Nov 15, 2016

Direct2D supports a subset of CG's blend modes as direct composition modes, and a subset of CG's porter-duff blend modes with its blend effect.

The blend effect, however, requires a full target readback and recompose.

The scope of this issue is to support only the basic non-blend-effect composition modes for 1611.

kCGBlendModeNormal = kCGBlendModeSourceOver
kCGBlendModeSourceOver
kCGBlendModeDestinationOver
kCGBlendModeSourceIn
kCGBlendModeDestinationIn
kCGBlendModeSourceOut
kCGBlendModeDestinationOut
kCGBlendModeSourceAtop
kCGBlendModeDestinationAtop
kCGBlendModeXOR
kCGBlendModePlusLighter
kCGBlendModeCopy
kCGBlendModePlusDarker // Not supported
@DHowett-MSFT DHowett-MSFT added this to the 1611 milestone Nov 15, 2016
@DHowett-MSFT DHowett-MSFT self-assigned this Nov 15, 2016
@rajsesh rajsesh modified the milestones: 1612, 1611 Nov 18, 2016
@rajsesh rajsesh changed the title [CGD2D] Draw primitives with blend modes (composite only). [CGD2D] Draw primitives with blend modes (composite only, porter-def and clear). Nov 18, 2016
@rajsesh rajsesh modified the milestones: 1701, 1612 Dec 16, 2016
@rajsesh
Copy link
Contributor

rajsesh commented Dec 16, 2016

Still have some open issues here that need to be sorted out. May not be required for merge back to develop.

@rajsesh rajsesh modified the milestones: 1702, 1701 Jan 6, 2017
@rajsesh rajsesh modified the milestones: 1703, 1702, 1704 Jan 27, 2017
@rajsesh rajsesh modified the milestones: 1703, 1704 Feb 23, 2017
@DHowett-MSFT DHowett-MSFT changed the title [CGD2D] Draw primitives with blend modes (composite only, porter-def and clear). [CGD2D] Draw primitives with Porter-Duff blend modes Mar 2, 2017
DHowett-MSFT pushed a commit that referenced this issue Mar 15, 2017
This pull request adds support for blending to CGContext. There are a number of
caveats.

* `kCGBlendModeClear` is not supported.
* The *Source In*, *Destination In*, *Source Out*, *Destination Atop*, and
  *Source Copy* blend modes cannot be used properly without transparency layers.
  Their use per-primitive will result in unusual artifacts.
* `kCGBlendModePlusDarker` is not supported (and was not supported in the
original Cairo implementation).

Some blend modes (the ones without Source/Destination) in the name require a
full buffer read-back and compose operation. This is unavoidable.

This change unfortunately _does_ include a rewrite of the CGD2D rendering
stack. Instead of adding yet another nesting level of command lists and layers,
I switched it to a scaffold/commit stack. Depending on various conditions,
operations will be queued up, started in order, and committed in reverse order.
A great many of those operations involve creating command lists and layers and
blending them or otherwise composing them.

There is a not-insignificant performance penalty in certain cases:

|                                    before             after   delta
| CoreText__CTLineDrawComplete       742.51            716.11   -3.5546% faster |
| CoreText__CTLineDrawGroup         292,909           307,828    5.0934% slower |
| CoreText__CTLineDrawSingle         233.43            280.05   19.9746% slower |

times in μs.

While 19% seems like a lot, it's only 47μs/operation; an application running at
60fps requires its rendering operations complete in ~16000μs. It's not
_significant_, but it is a cost taken per operation.

I believe there is opportunity for improvement; specifically, I had to
compromise on allocations to achieve the desired effects of polymorphism in the
new render operation stack.

Fixes #1389.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants