Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4bf6f6e

Browse files
author
Raj Seshasankaran
authored
Merge pull request #1273 from rajsesh-msft/cherry_pick_10_29
cherry-pick critical fixes for 11/7 release.
2 parents 5b18bb9 + 2048387 commit 4bf6f6e

File tree

22 files changed

+224
-190
lines changed

22 files changed

+224
-190
lines changed

Frameworks/AudioToolbox/CAFDecoder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ class CAFDecoder {
114114
int64_t mNumberValidFrames;
115115
int32_t mPrimingFrames;
116116
int32_t mRemainderFrames;
117-
118-
uint8_t mPacketDescriptions[1]; // this is a variable length array of
119-
// mNumberPackets elements
120117
} CAFPacketTableHeader;
121118

122119
typedef struct CAFDataChunk { uint32_t mEditCount; } CAFDataChunk;
@@ -142,7 +139,6 @@ class CAFDecoder {
142139
CAFAudioDescription cafDesc;
143140
CAFPacketTableHeader cafPacketTbl;
144141

145-
146142
ChannelStateList channelStates;
147143

148144
public:

Frameworks/AudioToolbox/CAFDecoder.mm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ uint64_t int64Swap(uint64_t val) {
213213
// clamp the number of packets to produce based on what is available in the
214214
// input buffer
215215
UInt32 inputPacketSize = mInputFormat.mBytesPerPacket;
216-
UInt32 numberOfInputPackets = 1;
216+
UInt32 numberOfInputPackets = ([stream hasBytesAvailable] ? 1 : 0);
217217
if (ioNumberPackets < numberOfInputPackets) {
218218
numberOfInputPackets = ioNumberPackets;
219219
} else if (ioNumberPackets > numberOfInputPackets) {
@@ -267,7 +267,7 @@ uint64_t int64Swap(uint64_t val) {
267267
isPcm = false;
268268

269269
while ([inStream hasBytesAvailable] && !stop) {
270-
CAFChunkHeader chunkHeader;
270+
CAFChunkHeader chunkHeader{};
271271
[inStream read:(uint8_t*)&chunkHeader maxLength:sizeof(CAFChunkHeader)];
272272
chunkHeader.mChunkType = int32Swap(chunkHeader.mChunkType);
273273
chunkHeader.mChunkSize = int64Swap(chunkHeader.mChunkSize);
@@ -331,13 +331,16 @@ uint64_t int64Swap(uint64_t val) {
331331
break;
332332

333333
default:
334-
bytesToSkip.reserve(chunkHeader.mChunkSize);
335-
bytesLeftUntilChunkEnd -= [inStream read:(uint8_t*)&bytesToSkip[0] maxLength:chunkHeader.mChunkSize];
334+
if (chunkHeader.mChunkSize > 0) {
335+
bytesToSkip.resize(chunkHeader.mChunkSize);
336+
bytesLeftUntilChunkEnd -= [inStream read:(uint8_t*)&bytesToSkip[0] maxLength:chunkHeader.mChunkSize];
337+
}
336338
break;
337339
}
338340

339341
if (!stop) {
340342
if (bytesLeftUntilChunkEnd > 0) {
343+
bytesToSkip.resize(bytesLeftUntilChunkEnd);
341344
[inStream read:(uint8_t*)&bytesToSkip[0] maxLength:bytesLeftUntilChunkEnd];
342345
}
343346
}

Frameworks/CoreGraphics/CGContextCairo.mm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,25 +1860,26 @@
18601860
// Technically there should be a horizontal translation to the center as well,
18611861
// but it's to the center of _each individual glyph_, as the reference platform applies the text matrix to each glyph individually
18621862
// Uncertain whether it's ever going to be worth it to support this using DWrite, so just ignore it for now
1863-
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, -1, 0, lineAscent / 2.0f);
1863+
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, -1, 0, -lineAscent / 2.0f);
18641864

18651865
// Apply text transforms
18661866
transform = CGAffineTransformConcat(curState->curTextMatrix, transform);
1867-
transform = CGAffineTransformTranslate(transform, curState->curTextPosition.x, curState->curTextPosition.y);
18681867

18691868
// Undo transform to text space
1870-
transform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, -lineAscent / 2.0f), transform);
1869+
transform = CGAffineTransformConcat(CGAffineTransformMake(1, 0, 0, -1, 0, lineAscent / 2.0f), transform);
18711870

1872-
// Apply the context CTM
1873-
transform = CGAffineTransformConcat(curState->curTransform, transform);
1871+
transform = CGAffineTransformTranslate(transform, curState->curTextPosition.x, curState->curTextPosition.y);
18741872

1875-
// Perform translation required to handle scaling.
1876-
CGFloat verticalScalingFactor = sqrt((transform.b * transform.b) + (transform.d * transform.d));
1873+
// Find transform that user created by multiplying given transform by necessary transforms to draw with CoreText
18771874
float height = _imgDest->Backing()->Height();
1878-
transform = CGAffineTransformTranslate(transform, 0, (height / verticalScalingFactor));
1875+
CGAffineTransform userTransform =
1876+
CGAffineTransformConcat(curState->curTransform, CGAffineTransformMake(1.0f / _scale, 0, 0, 1.0f / _scale, 0, -height / _scale));
1877+
1878+
// Apply the context CTM
1879+
transform = CGAffineTransformConcat(transform, userTransform);
18791880

18801881
// Perform anti-clockwise rotation required to match the reference platform.
1881-
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, -transform.b, transform.c, transform.d, transform.tx, transform.ty));
1882+
imgRenderTarget->SetTransform(D2D1::Matrix3x2F(transform.a, -transform.b, transform.c, transform.d, transform.tx, -transform.ty));
18821883

18831884
// Draw the glyph using ID2D1RenderTarget
18841885
ComPtr<ID2D1SolidColorBrush> brush;

Frameworks/CoreGraphics/DWriteWrapper.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ HRESULT _DWriteCreateFontFaceWithName(CFStringRef name, IDWriteFontFace** outFon
395395
// Eg: Bold, Condensed, Light, Italic
396396
_DWriteFontProperties properties = _DWriteGetFontPropertiesFromName(name);
397397

398+
// TODO: #1250: Need to be able to load fonts from the app's bundle
399+
// For now return a default font to avoid crashes in case of missing fonts
400+
// When #1250 is completed, remove this
401+
if (!properties.familyName) {
402+
name = CFSTR("Segoe UI");
403+
properties = _DWriteGetFontPropertiesFromName(name);
404+
}
405+
398406
RETURN_HR_IF_NULL(E_INVALIDARG, properties.familyName);
399407

400408
ComPtr<IDWriteFontFamily> fontFamily;

Frameworks/CoreText/CTFrame.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void CTFrameDraw(CTFrameRef frameRef, CGContextRef ctx) {
122122
CGContextScaleCTM(ctx, 1.0f, -1.0f);
123123

124124
for (_CTLine* line in static_cast<id<NSFastEnumeration>>(frame->_lines)) {
125-
CGContextSetTextPosition(ctx, line->_lineOrigin.x, line->_lineOrigin.y);
125+
CGContextSetTextPosition(ctx, line->_lineOrigin.x, -line->_lineOrigin.y);
126126
_CTLineDraw(static_cast<CTLineRef>(line), ctx, false);
127127
}
128128

Frameworks/CoreText/CTLine.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ void _CTLineDraw(CTLineRef lineRef, CGContextRef ctx, bool adjustTextPosition) {
221221
}
222222

223223
_CTLine* line = static_cast<_CTLine*>(lineRef);
224-
CGPoint curTextPos = { 0, 0 };
224+
CGPoint curTextPos = {};
225225
if (adjustTextPosition) {
226226
curTextPos = CGContextGetTextPosition(ctx);
227-
CGContextSetTextPosition(ctx, curTextPos.x + line->_relativeXOffset, curTextPos.y + line->_relativeYOffset);
227+
CGContextSetTextPosition(ctx, curTextPos.x, curTextPos.y + line->_relativeYOffset);
228228
}
229229

230230
for (size_t i = 0; i < [line->_runs count]; ++i) {

Frameworks/CoreText/CTRun.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void _CTRunDraw(CTRunRef run, CGContextRef ctx, CFRange textRange, bool adjustTe
277277

278278
if (adjustTextPosition) {
279279
CGPoint curTextPos = CGContextGetTextPosition(ctx);
280-
CGContextSetTextPosition(ctx, curTextPos.x + curRun->_relativeXOffset, curTextPos.y + curRun->_relativeYOffset);
280+
CGContextSetTextPosition(ctx, curTextPos.x, curTextPos.y + curRun->_relativeYOffset);
281281
}
282282

283283
id fontColor = [curRun->_attributes objectForKey:(id)kCTForegroundColorAttributeName];

Frameworks/CoreText/DWriteWrapper_CoreText.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ HRESULT STDMETHODCALLTYPE GetPixelsPerDip(_In_opt_ void* clientDrawingContext, _
455455
i++;
456456
}
457457

458-
if ([runs objectAtIndex:0]) {
458+
if ([runs count] > 0) {
459459
prevYPosForDraw = yPos;
460460
line->_runs = runs;
461461
line->_strRange.location = static_cast<_CTRun*>(line->_runs[0])->_range.location;

Frameworks/QuartzCore/CALayer.mm

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,9 @@ - (void)display {
623623
CGContextTranslateCTM(drawContext, 0, float(target->Backing()->Height()));
624624
}
625625
if (priv->contentsScale != 1.0f) {
626-
CGContextScaleCTM(drawContext, priv->contentsScale, priv->contentsScale);
627-
628626
// TODO 1077:: Remove once D2D render target is implemented
629627
_CGContextSetScaleFactor(drawContext, priv->contentsScale);
628+
CGContextScaleCTM(drawContext, priv->contentsScale, priv->contentsScale);
630629
}
631630

632631
CGContextScaleCTM(drawContext, 1.0f, -1.0f);
@@ -2133,11 +2132,11 @@ - (BOOL)containsPoint:(CGPoint)point {
21332132
- (void)dealloc {
21342133
if (DEBUG_VERBOSE) {
21352134
TraceVerbose(TAG,
2136-
L"CALayer dealloc: (%hs - 0x%p, %hs - 0x%p).",
2137-
object_getClassName(self),
2138-
self,
2139-
priv->delegate ? object_getClassName(priv->delegate) : "nil",
2140-
priv->delegate);
2135+
L"CALayer dealloc: (%hs - 0x%p, %hs - 0x%p).",
2136+
object_getClassName(self),
2137+
self,
2138+
priv->delegate ? object_getClassName(priv->delegate) : "nil",
2139+
priv->delegate);
21412140
}
21422141

21432142
[self removeAllAnimations];
@@ -2400,63 +2399,58 @@ - (void)_displayChanged {
24002399
//////////////////////////////////////////////////////////////////////////////////////////////
24012400
// TODO: Switch to ARC
24022401
// We don't want to do display updates on an object that's currently deallocating.
2403-
// In order to ensure that we're not mid-deallocation during the display update,
2402+
// In order to ensure that we're not mid-deallocation during the display update,
24042403
// we create a weak reference here, and then *immediately* acquire a strong reference to it.
24052404
// If that succeeds, we're guaranteed to not dealloc until after the block executes.
2406-
2405+
24072406
// Store a weak reference - this will fail if we're already deallocating
24082407
id weakSuperLayer = nil;
24092408
objc_storeWeak(&weakSuperLayer, superLayer);
2410-
2409+
24112410
// Grab a strong reference that we can pass into the block - this will fail if we're already deallocating
24122411
auto strongSuperLayer = reinterpret_cast<CALayer*>(objc_loadWeakRetained(&weakSuperLayer));
2413-
2412+
24142413
// We need to make sure the retain we just performed above is released *after* we construct the block
2415-
auto releaseSuperLayer = wil::ScopeExit([&strongSuperLayer]() {
2416-
objc_release(strongSuperLayer);
2417-
});
2414+
auto releaseSuperLayer = wil::ScopeExit([&strongSuperLayer]() { objc_release(strongSuperLayer); });
24182415

24192416
// The weak reference is no longer needed, so clean up after ourselves
24202417
objc_destroyWeak(&weakSuperLayer);
24212418

24222419
// Grab a raw pointer (so it's not block-retained) - for logging purposes (if needed)
24232420
void* rawSuperLayerForLog = reinterpret_cast<void*>(superLayer);
24242421

2425-
dispatch_async(
2426-
dispatch_get_main_queue(),
2427-
^{
2428-
// If we have a valid non-dealloc'd object, run its display update pass
2429-
if (strongSuperLayer) {
2430-
// Only run the update pass for this superLayer if it's a 'root layer' - aka a UIWindow layer,
2431-
// or if we're running as a framework - aka for middleware scenarios - where the layer won't have
2432-
// a 'root' superlayer.
2433-
if (strongSuperLayer->priv->isRootLayer || GetCACompositor()->IsRunningAsFramework()) {
2434-
strongSuperLayer->priv->_displayPending = false;
2435-
2436-
if (DEBUG_VERBOSE) {
2437-
TraceVerbose(
2438-
TAG,
2439-
L"Performing _displayChanged work for superlayer (%hs - 0x%p, %hs - 0x%p).",
2440-
object_getClassName(strongSuperLayer),
2441-
strongSuperLayer,
2442-
strongSuperLayer->priv->delegate ? object_getClassName(strongSuperLayer->priv->delegate) : "nil",
2443-
strongSuperLayer->priv->delegate);
2444-
}
2445-
2446-
// Recalculate layouts
2447-
DoLayerLayouts(strongSuperLayer, true);
2448-
2449-
// Redisplay anything necessary
2450-
DoDisplayList(strongSuperLayer);
2422+
dispatch_async(dispatch_get_main_queue(), ^{
2423+
// If we have a valid non-dealloc'd object, run its display update pass
2424+
if (strongSuperLayer) {
2425+
// Only run the update pass for this superLayer if it's a 'root layer' - aka a UIWindow layer,
2426+
// or if we're running as a framework - aka for middleware scenarios - where the layer won't have
2427+
// a 'root' superlayer.
2428+
if (strongSuperLayer->priv->isRootLayer || GetCACompositor()->IsRunningAsFramework()) {
2429+
strongSuperLayer->priv->_displayPending = false;
2430+
2431+
if (DEBUG_VERBOSE) {
2432+
TraceVerbose(TAG,
2433+
L"Performing _displayChanged work for superlayer (%hs - 0x%p, %hs - 0x%p).",
2434+
object_getClassName(strongSuperLayer),
2435+
strongSuperLayer,
2436+
strongSuperLayer->priv->delegate ? object_getClassName(strongSuperLayer->priv->delegate) : "nil",
2437+
strongSuperLayer->priv->delegate);
24512438
}
2452-
} else if (DEBUG_VERBOSE) {
2453-
TraceVerbose(TAG, L"Skipping _displayChanged work for currently-dealloc'd object (0x%p).", rawSuperLayerForLog);
2439+
2440+
// Recalculate layouts
2441+
DoLayerLayouts(strongSuperLayer, true);
2442+
2443+
// Redisplay anything necessary
2444+
DoDisplayList(strongSuperLayer);
24542445
}
2446+
} else if (DEBUG_VERBOSE) {
2447+
TraceVerbose(TAG, L"Skipping _displayChanged work for currently-dealloc'd object (0x%p).", rawSuperLayerForLog);
2448+
}
24552449

2456-
// Always commit and process all queued CATransactions
2457-
[CATransaction _commitRootQueue];
2458-
GetCACompositor()->ProcessTransactions();
2459-
});
2450+
// Always commit and process all queued CATransactions
2451+
[CATransaction _commitRootQueue];
2452+
GetCACompositor()->ProcessTransactions();
2453+
});
24602454
}
24612455
}
24622456

@@ -2592,7 +2586,7 @@ + (CGPoint)convertPoint:(CGPoint)point fromLayer:(CALayer*)fromLayer toLayer:(CA
25922586
}
25932587

25942588
if (DEBUG_VERBOSE) {
2595-
TraceVerbose(TAG, L"convertPoint: {%f, %f} to {%f, %f}", point.x, point.y, ret.x, ret.y);
2589+
TraceVerbose(TAG, L"convertPoint: {%f, %f} to {%f, %f}", point.x, point.y, ret.x, ret.y);
25962590
}
25972591

25982592
return ret;

Frameworks/UIKit/NSLayoutManager.mm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ - (void)__layoutAllText {
156156

157157
// Save line and origin for when it is drawn
158158
[_ctLines addObject:(id)fitLine];
159-
_lineOrigins.push_back(rect.origin);
159+
_lineOrigins.emplace_back(CGPoint{ rect.origin.x, rect.origin.y + lineHeight });
160160

161161
double fitWidth = CTLineGetTypographicBounds(fitLine, nullptr, nullptr, nullptr);
162162
drawnWidth += fitWidth;
@@ -245,12 +245,11 @@ - (void)drawGlyphsForGlyphRange:(NSRange)range atPoint:(CGPoint)position {
245245
int count = [_ctLines count];
246246
for (int curLine = 0; curLine < count; curLine++) {
247247
CTLineRef line = (CTLineRef)_ctLines[curLine];
248-
249-
float ascent, descent, leading;
250-
CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
251-
252248
CGContextSaveGState(curCtx);
253-
CGContextSetTextPosition(curCtx, _lineOrigins[curLine].x, _lineOrigins[curLine].y);
249+
250+
CGFloat ascent, leading;
251+
CTLineGetTypographicBounds(line, &ascent, nullptr, &leading);
252+
CGContextSetTextPosition(curCtx, _lineOrigins[curLine].x, -(_lineOrigins[curLine].y + ascent + leading));
254253
CTLineDraw(line, curCtx);
255254
CGContextRestoreGState(curCtx);
256255
}
@@ -745,10 +744,10 @@ - (void)ensureLayoutForTextContainer:(NSTextContainer*)container {
745744
@Notes
746745
*/
747746
- (void)setGlyphs:(const CGGlyph*)glyphs
748-
properties:(const NSGlyphProperty*)props
749-
characterIndexes:(const NSUInteger*)charIndexes
750-
font:(UIFont*)aFont
751-
forGlyphRange:(NSRange)glyphRange {
747+
properties:(const NSGlyphProperty*)props
748+
characterIndexes:(const NSUInteger*)charIndexes
749+
font:(UIFont*)aFont
750+
forGlyphRange:(NSRange)glyphRange {
752751
UNIMPLEMENTED();
753752
}
754753

0 commit comments

Comments
 (0)