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

[macOS] Update FlutterView layer scale when backing properties change #38402

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2638,6 +2638,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterVie
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap.g.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap_Internal.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/TestFlutterPlatformView.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -5100,6 +5101,7 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewE
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProviderTest.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap.g.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/KeyCodeMap_Internal.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/TestFlutterPlatformView.h
Expand Down
1 change: 1 addition & 0 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ executable("flutter_desktop_darwin_unittests") {
"framework/Source/FlutterViewControllerTestUtils.h",
"framework/Source/FlutterViewControllerTestUtils.mm",
"framework/Source/FlutterViewEngineProviderTest.mm",
"framework/Source/FlutterViewTest.mm",
"framework/Source/TestFlutterPlatformView.h",
"framework/Source/TestFlutterPlatformView.mm",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

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

CGFloat scale = platform_view.layer.contentsScale;
CGFloat scale = default_base_view.layer.contentsScale;
platform_view.frame = CGRectMake(layer->offset.x / scale, layer->offset.y / scale,
layer->size.width / scale, layer->size.height / scale);
if (platform_view.superview == nil) {
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ - (void)viewDidChangeBackingProperties {
[_reshapeListener viewDidReshape:self];
}

- (BOOL)layer:(CALayer*)layer
shouldInheritContentsScale:(CGFloat)newScale
fromWindow:(NSWindow*)window {
return YES;
}

- (void)shutdown {
[_threadSynchronizer shutdown];
}
Expand Down
30 changes: 30 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterViewTest.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"

#import <Metal/Metal.h>

#import "flutter/testing/testing.h"

@interface TestReshapeListener : NSObject <FlutterViewReshapeListener>

@end

@implementation TestReshapeListener

- (void)viewDidReshape:(nonnull NSView*)view {
}

@end

TEST(FlutterView, ShouldInheritContentsScaleReturnsYes) {
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> queue = [device newCommandQueue];
TestReshapeListener* listener = [[TestReshapeListener alloc] init];
FlutterView* view = [[FlutterView alloc] initWithMTLDevice:device
commandQueue:queue
reshapeListener:listener];
EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
}