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

Commit 6de29d1

Browse files
authored
[macOS] Update FlutterView layer scale when backing properties change (#38402)
1 parent 955a35a commit 6de29d1

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVie
26382638
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm + ../../../flutter/LICENSE
26392639
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm + ../../../flutter/LICENSE
26402640
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h + ../../../flutter/LICENSE
2641+
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm + ../../../flutter/LICENSE
26412642
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap.g.mm + ../../../flutter/LICENSE
26422643
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap_Internal.h + ../../../flutter/LICENSE
26432644
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/TestFlutterPlatformView.h + ../../../flutter/LICENSE
@@ -5100,6 +5101,7 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewE
51005101
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm
51015102
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm
51025103
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h
5104+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm
51035105
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap.g.mm
51045106
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap_Internal.h
51055107
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/TestFlutterPlatformView.h

shell/platform/darwin/macos/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ executable("flutter_desktop_darwin_unittests") {
182182
"framework/Source/FlutterViewControllerTestUtils.h",
183183
"framework/Source/FlutterViewControllerTestUtils.mm",
184184
"framework/Source/FlutterViewEngineProviderTest.mm",
185+
"framework/Source/FlutterViewTest.mm",
185186
"framework/Source/TestFlutterPlatformView.h",
186187
"framework/Source/TestFlutterPlatformView.mm",
187188
]

shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
FML_DCHECK(platform_view) << "Platform view not found for id: " << platform_view_id;
9090

91-
CGFloat scale = platform_view.layer.contentsScale;
91+
CGFloat scale = default_base_view.layer.contentsScale;
9292
platform_view.frame = CGRectMake(layer->offset.x / scale, layer->offset.y / scale,
9393
layer->size.width / scale, layer->size.height / scale);
9494
if (platform_view.superview == nil) {

shell/platform/darwin/macos/framework/Source/FlutterView.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ - (void)viewDidChangeBackingProperties {
106106
[_reshapeListener viewDidReshape:self];
107107
}
108108

109+
- (BOOL)layer:(CALayer*)layer
110+
shouldInheritContentsScale:(CGFloat)newScale
111+
fromWindow:(NSWindow*)window {
112+
return YES;
113+
}
114+
109115
- (void)shutdown {
110116
[_threadSynchronizer shutdown];
111117
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
6+
7+
#import <Metal/Metal.h>
8+
9+
#import "flutter/testing/testing.h"
10+
11+
@interface TestReshapeListener : NSObject <FlutterViewReshapeListener>
12+
13+
@end
14+
15+
@implementation TestReshapeListener
16+
17+
- (void)viewDidReshape:(nonnull NSView*)view {
18+
}
19+
20+
@end
21+
22+
TEST(FlutterView, ShouldInheritContentsScaleReturnsYes) {
23+
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
24+
id<MTLCommandQueue> queue = [device newCommandQueue];
25+
TestReshapeListener* listener = [[TestReshapeListener alloc] init];
26+
FlutterView* view = [[FlutterView alloc] initWithMTLDevice:device
27+
commandQueue:queue
28+
reshapeListener:listener];
29+
EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
30+
}

0 commit comments

Comments
 (0)