-
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] Remove the Foundation dependency from CTFrame #2427
Conversation
@public | ||
#pragma region CTFrame | ||
struct __CTFrame : CoreFoundation::CppBase<__CTFrame> { | ||
__CTFrame() : _lines(CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)) { |
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.
sadly due to the extensive usage of the internal vars outside the actual class, these had to go internal-public 😢 #ByDesign
Please reword this title to be concise and imperative. 😄 #Resolved |
Frameworks/CoreText/CTTypesetter.mm
Outdated
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), |
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.
this still has an objective-C message dispatch. #ByDesign
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 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); |
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.
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
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.
@@ -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) }; |
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.
This will leak. Please use woc::MakeStrongCF
. #Resolved
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.
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 { |
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.
leave this #ByDesign
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.
behold this, the death of character #ByDesign
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.
😢 #ByDesign
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.
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); |
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.
I don't think it's necessary to churn these files to add early returns #ByDesign
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.
Code Clarity, it makes much easier to read + follow the standards of other frameworks. #ByDesign
include/CoreText/CTFrame.h
Outdated
@@ -25,7 +25,7 @@ | |||
#import <CoreGraphics/CGGeometry.h> | |||
#import <CoreGraphics/CGPath.h> | |||
|
|||
typedef const struct __CTFrame* CTFrameRef; | |||
typedef struct __CTFrame* CTFrameRef; |
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.
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 { |
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.
behold this, the death of character #ByDesign
|
||
CGPoint relativePosition = frame->_lineOrigins[i]; | ||
|
||
for (size_t j = 0; j < [line->_runs count]; ++j) { |
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.
nit: might want to leave a TODO here as a reminder for when you get to CTLine #ByDesign
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.
the compiler will handily totally fall over for this line when that transition is made :) #ByDesign
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.
o, tru #ByDesign
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.
also when you make it private, to track down all these places. well it really goes off ;) #ByDesign
} | ||
} | ||
|
||
/** | ||
@Status Stub | ||
@Notes | ||
@Status Interoperable |
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.
remove the annotation in the .h also #Resolved
@DHowett-MSFT @aballway @ms-jihua Ping! #ByDesign |
Frameworks/CoreText/CTFramesetter.mm
Outdated
StrongId<_CTFrame> ret = _DWriteGetFrame(static_cast<CFAttributedStringRef>(typesetter->_attributedString.get()), range, frameRect); | ||
ret->_path.reset(CGPathRetain(path)); | ||
woc::StrongCF<__CTFrame*> ret; | ||
ret = |
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.
ret [](start = 4, length = 3)
collapse the declaration and assignment into initialization? there is no need to declare and then assign. #ByDesign
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.
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
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.
woc::MakeStrongCF it 😸 #ByDesign
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.
LOL yes was about to ;) #ByDesign
return frame; | ||
} | ||
__CTFrame* frame = __CTFrame::CreateInstance(kCFAllocatorDefault); | ||
CFAutorelease(frame); |
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.
nit: use AutoCF vs. CFAutorelease #ByDesign
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.
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)
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.
I hate that this method returns an "un-owned" CTFrame. It should be a Create method or it should not exist. #Resolved
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.
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
- Implemented CTFrame via Runtimebase - Removed associated Foundation dependency - Improvements to the code - Performance gain Fixes microsoft#2359
554ce83
to
fb28d71
Compare
Fixes #2359
Develop:
With The Changes: