-
Notifications
You must be signed in to change notification settings - Fork 806
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
CoreText Performance: Call ID2D1RenderTarget::BeginDraw()/EndDraw() f… #1705
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,11 @@ | |
// An OSS request has been submitted. The link for the request is: | ||
// https://osstool.microsoft.com/palamida/RequestDetails.htm?rid=40072&projectId=1 | ||
void CGContextCairo::_cairoImageSurfaceBlur(cairo_surface_t* surface) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: as much as I hate them, this would make a nice macro #WontFix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
double blur = curState->shadowBlur; | ||
|
||
if (surface == NULL || blur <= 0) { | ||
|
@@ -171,6 +176,11 @@ | |
} | ||
|
||
void CGContextCairo::_cairoContextStrokePathShadow() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
int i; | ||
double width, height, deltaWidth, deltaHeight; | ||
|
||
|
@@ -283,6 +293,11 @@ | |
} | ||
|
||
void CGContextCairo::Clear(float r, float g, float b, float a) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
CGRect rct; | ||
|
@@ -303,6 +318,11 @@ | |
} | ||
|
||
void CGContextCairo::DrawImage(CGImageRef img, CGRect src, CGRect dest, bool tiled) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
if (dest.size.width == 0.0f || dest.size.height == 0.0f) | ||
|
@@ -854,6 +874,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextClearRect(CGRect rct) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -886,6 +911,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextFillRect(CGRect rct) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1102,6 +1132,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextStrokeEllipseInRect(CGRect rct) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1135,6 +1170,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextFillEllipseInRect(CGRect rct) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1174,6 +1214,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextStrokePath() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1197,6 +1242,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextStrokeRect(CGRect rct) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1230,6 +1280,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextStrokeRectWithWidth(CGRect rct, float width) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1260,6 +1315,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextFillPath() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1288,6 +1348,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextEOFillPath() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1316,6 +1381,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextEOClip() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
TraceWarning(TAG, L"CGContextEOClip not supported"); | ||
|
@@ -1326,6 +1396,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextDrawPath(CGPathDrawingMode mode) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1426,6 +1501,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextDrawLinearGradient(CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint, DWORD options) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1467,6 +1547,11 @@ | |
|
||
void CGContextCairo::CGContextDrawRadialGradient( | ||
CGGradientRef gradient, CGPoint startCenter, float startRadius, CGPoint endCenter, float endRadius, DWORD options) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
_isDirty = true; | ||
|
@@ -1673,6 +1758,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextClip() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
|
||
LOCK_CAIRO(); | ||
|
@@ -1710,6 +1800,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextClipToRect(CGRect rect) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
LOCK_CAIRO(); | ||
cairo_path_t* oldPath = cairo_copy_path(_drawContext); | ||
|
@@ -1738,6 +1833,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextBeginTransparencyLayerWithRect(CGRect rect, id auxInfo) { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
LOCK_CAIRO(); | ||
cairo_save(_drawContext); | ||
|
@@ -1756,6 +1856,11 @@ | |
} | ||
|
||
void CGContextCairo::CGContextEndTransparencyLayer() { | ||
// TODO #1635: It's unsafe to edit the bitmap not through D2D1RenderTarget, during a BeginDraw() | ||
// Escape any Begin/EndDraw() pairs for the lifetime of this function (to be removed during the CGD2D merge) | ||
_CGContextEscapeBeginEndDrawStack(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextUnescapeBeginEndDrawStack(this->_rootContext); }); | ||
|
||
ObtainLock(); | ||
LOCK_CAIRO(); | ||
// Retrieve the group as a pattern | ||
|
@@ -1863,7 +1968,7 @@ | |
CGContextStrokePath(); | ||
|
||
ID2D1RenderTarget* imgRenderTarget = _imgDest->Backing()->GetRenderTarget(); | ||
THROW_NS_IF_NULL(E_UNEXPECTED, imgRenderTarget); | ||
THROW_HR_IF_NULL(E_UNEXPECTED, imgRenderTarget); | ||
|
||
// Apply the required transformations as set in the context. | ||
// We need some special handling in transform as CoreText in iOS renders from bottom left but DWrite on Windows does top left. | ||
|
@@ -1898,7 +2003,9 @@ | |
D2D1::ColorF brushColor = | ||
D2D1::ColorF(curState->curFillColor.r, curState->curFillColor.g, curState->curFillColor.b, curState->curFillColor.a); | ||
|
||
imgRenderTarget->BeginDraw(); | ||
_CGContextPushBeginDraw(_rootContext); | ||
auto popEnd = wil::ScopeExit([this]() { _CGContextPopEndDraw(this->_rootContext); }); | ||
|
||
// Draw the glyph using ID2D1RenderTarget | ||
ComPtr<ID2D1SolidColorBrush> brush; | ||
THROW_IF_FAILED(imgRenderTarget->CreateSolidColorBrush(brushColor, &brush)); | ||
|
@@ -1931,8 +2038,6 @@ | |
userTransform = CGAffineTransformTranslate(userTransform, glyphRun->glyphAdvances[i], 0); | ||
} | ||
} | ||
|
||
THROW_IF_FAILED(imgRenderTarget->EndDraw()); | ||
} | ||
|
||
// TODO 1077:: Remove once D2D render target is implemented | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are a fairly significant hit to performance for the non-text CGContextCairo drawing functions, eating up >50% of time in CGContextFillRect, for instance. This may be unavoidable until the CGD2D merge, and is a tradeoff - text-drawing is still a much bigger bottleneck (CGContextFillRect, while slower, still does not take up much time). Please comment if you have any objections.