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

[CoreText] Remove the Foundation dependency from CTFrame #2427

Merged
merged 4 commits into from
Apr 12, 2017

Conversation

msft-Jeyaram
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram commented Apr 5, 2017

  • Implemented CTFrame via Runtimebase
  • Removed associated Foundation usage
  • Improvements to code
  • Performance gain

Fixes #2359

Develop:
image

With The Changes:
image

@msft-Jeyaram msft-Jeyaram changed the title Implementation of CTFrame via Runtimebase + Removal of Foundation usage + Some Perf [CoreText] Implementation of CTFrame via Runtimebase + Removal of Foundation usage + Some Perf Apr 5, 2017
@public
#pragma region CTFrame
struct __CTFrame : CoreFoundation::CppBase<__CTFrame> {
__CTFrame() : _lines(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)) {
Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 5, 2017

Choose a reason for hiding this comment

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

sadly due to the extensive usage of the internal vars outside the actual class, these had to go internal-public 😢 #ByDesign

@DHowett-MSFT
Copy link

DHowett-MSFT commented Apr 5, 2017

Please reword this title to be concise and imperative. 😄 #Resolved

@msft-Jeyaram msft-Jeyaram changed the title [CoreText] Implementation of CTFrame via Runtimebase + Removal of Foundation usage + Some Perf [CoreText] Implementation of CTFrame via Runtimebase + removal of associated Foundation usage Apr 5, 2017
@msft-Jeyaram msft-Jeyaram changed the title [CoreText] Implementation of CTFrame via Runtimebase + removal of associated Foundation usage [CoreText] Implementation of CTFrame via Runtimebase with removal of associated Foundation usage Apr 5, 2017
CGRectMake(offset, 0, width, FLT_MAX));
return ([frame->_lines count] > 0) ? static_cast<_CTLine*>([frame->_lines firstObject])->_strRange.length : 0;
CTFrameRef frame = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()),
CFRangeMake(index, [typesetter->_string length] - index),
Copy link

@DHowett-MSFT DHowett-MSFT Apr 5, 2017

Choose a reason for hiding this comment

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

this still has an objective-C message dispatch. #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 5, 2017

Choose a reason for hiding this comment

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

These are being moved with their associated class being RuntimeBase.
Now i can go a huge change that does all this, but it makes it easier for bugs to go unnoticed.

I'm just breaking out the main classes and it follows through.
#ByDesign

if (range.length <= 0) {
return frame;
}
CTFrameRef frame = __CTFrame::CreateInstance(kCFAllocatorDefault);
Copy link

@DHowett-MSFT DHowett-MSFT Apr 5, 2017

Choose a reason for hiding this comment

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

I'm vaguely worried about the implications of two different TUs containing CreateInstance calls. Do they share static storage? Do they call the same instance of GetTypeID? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only one occurrence.


In reply to: 110012166 [](ancestors = 110012166)

@@ -446,7 +446,8 @@ HRESULT STDMETHODCALLTYPE GetPixelsPerDip(_In_opt_ void* clientDrawingContext, _

while (i < numOfGlyphRuns) {
_CTLine* line = [[_CTLine new] autorelease];
NSMutableArray<_CTRun*>* runs = [NSMutableArray array];

woc::StrongCF<CFMutableArrayRef> runs{ CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks) };
Copy link

@DHowett-MSFT DHowett-MSFT Apr 5, 2017

Choose a reason for hiding this comment

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

This will leak. Please use woc::MakeStrongCF. #Resolved

Copy link
Contributor

@aballway aballway left a comment

Choose a reason for hiding this comment

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

I think this would be better suited to a larger, more comprehensive PR that converts all of the CT classes to CppBase and removes the dependency on foundation in one fell swoop. That way, we'd be guaranteed to catch all of the changes in one squashed commit rather than several which will have overlapping changes.

@@ -233,9 +233,9 @@ size_t GetRunCount() const {

BENCHMARK_F(CoreText, CTFrameDrawComplete);

class CTFrameDrawYuge : public TextBenchmarkBase {
class CTFrameDrawHuge : public TextBenchmarkBase {
Copy link
Contributor

@aballway aballway Apr 5, 2017

Choose a reason for hiding this comment

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

leave this #ByDesign

Copy link

@DHowett-MSFT DHowett-MSFT Apr 5, 2017

Choose a reason for hiding this comment

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

behold this, the death of character #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 5, 2017

Choose a reason for hiding this comment

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

😢 #ByDesign

Copy link
Contributor

@rajsesh rajsesh Apr 6, 2017

Choose a reason for hiding this comment

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

This was originally done by special request. 😿 #ByDesign

}
runs.emplace_back(GlyphRunData{ &curRun->_dwriteGlyphRun, relativePosition, (CFDictionaryRef)curRun->_attributes.get() });
void CTFrameDraw(CTFrameRef frame, CGContextRef ctx) {
RETURN_IF(!ctx);
Copy link
Contributor

@aballway aballway Apr 5, 2017

Choose a reason for hiding this comment

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

I don't think it's necessary to churn these files to add early returns #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 5, 2017

Choose a reason for hiding this comment

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

Code Clarity, it makes much easier to read + follow the standards of other frameworks. #ByDesign

@@ -25,7 +25,7 @@
#import <CoreGraphics/CGGeometry.h>
#import <CoreGraphics/CGPath.h>

typedef const struct __CTFrame* CTFrameRef;
typedef struct __CTFrame* CTFrameRef;
Copy link
Contributor

@aballway aballway Apr 5, 2017

Choose a reason for hiding this comment

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

this should remain const #Resolved

@@ -233,9 +233,9 @@ size_t GetRunCount() const {

BENCHMARK_F(CoreText, CTFrameDrawComplete);

class CTFrameDrawYuge : public TextBenchmarkBase {
class CTFrameDrawHuge : public TextBenchmarkBase {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 5, 2017

Choose a reason for hiding this comment

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

behold this, the death of character #ByDesign

@msft-Jeyaram msft-Jeyaram changed the title [CoreText] Implementation of CTFrame via Runtimebase with removal of associated Foundation usage [CoreText] Remove the Foundation dependency from CTFrame Apr 5, 2017

CGPoint relativePosition = frame->_lineOrigins[i];

for (size_t j = 0; j < [line->_runs count]; ++j) {
Copy link
Contributor

@ms-jihua ms-jihua Apr 6, 2017

Choose a reason for hiding this comment

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

nit: might want to leave a TODO here as a reminder for when you get to CTLine #ByDesign

Copy link

@DHowett-MSFT DHowett-MSFT Apr 6, 2017

Choose a reason for hiding this comment

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

the compiler will handily totally fall over for this line when that transition is made :) #ByDesign

Copy link
Contributor

@ms-jihua ms-jihua Apr 6, 2017

Choose a reason for hiding this comment

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

o, tru #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 6, 2017

Choose a reason for hiding this comment

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

also when you make it private, to track down all these places. well it really goes off ;) #ByDesign

}
}

/**
@Status Stub
@Notes
@Status Interoperable
Copy link
Contributor

@ms-jihua ms-jihua Apr 6, 2017

Choose a reason for hiding this comment

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

remove the annotation in the .h also #Resolved

@msft-Jeyaram
Copy link
Contributor Author

msft-Jeyaram commented Apr 6, 2017

@DHowett-MSFT @aballway @ms-jihua Ping! #ByDesign

StrongId<_CTFrame> ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameRect);
ret->_path.reset(CGPathRetain(path));
woc::StrongCF<__CTFrame*> ret;
ret =
Copy link
Contributor

@rajsesh rajsesh Apr 6, 2017

Choose a reason for hiding this comment

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

ret [](start = 4, length = 3)

collapse the declaration and assignment into initialization? there is no need to declare and then assign. #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 6, 2017

Choose a reason for hiding this comment

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

This is due to the minor shortfall of StrongCF, assignment of a return value will cause it to invoke a +0 recount and since we don't own the object, it will end up with over releases. #ByDesign

Copy link
Contributor

@aballway aballway Apr 6, 2017

Choose a reason for hiding this comment

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

woc::MakeStrongCF it 😸 #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 6, 2017

Choose a reason for hiding this comment

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

LOL yes was about to ;) #ByDesign

return frame;
}
__CTFrame* frame = __CTFrame::CreateInstance(kCFAllocatorDefault);
CFAutorelease(frame);
Copy link
Contributor

@aballway aballway Apr 7, 2017

Choose a reason for hiding this comment

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

nit: use AutoCF vs. CFAutorelease #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's returning and auto released object, i'd rather not AutoCF it it then detach it and autorelease it.


In reply to: 110446169 [](ancestors = 110446169)

Copy link

@DHowett-MSFT DHowett-MSFT Apr 7, 2017

Choose a reason for hiding this comment

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

I hate that this method returns an "un-owned" CTFrame. It should be a Create method or it should not exist. #Resolved

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 7, 2017

Choose a reason for hiding this comment

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

The way this method does stuff does makes me sad. The frame is created in parts :(
Sadly it's not the scope of this review to fix this up real good.
#ByDesign

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.

6 participants