[macOS] Update FlutterView layer scale when backing properties change (flutter/engine#38402)

This commit is contained in:
Matej Knopp 2022-12-20 01:05:26 +01:00 committed by GitHub
parent 7ff15f1845
commit bc41422fb1
5 changed files with 40 additions and 1 deletions

View File

@ -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
@ -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

View File

@ -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",
]

View File

@ -88,7 +88,7 @@ void FlutterCompositor::PresentPlatformView(FlutterView* default_base_view,
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) {

View File

@ -106,6 +106,12 @@
[_reshapeListener viewDidReshape:self];
}
- (BOOL)layer:(CALayer*)layer
shouldInheritContentsScale:(CGFloat)newScale
fromWindow:(NSWindow*)window {
return YES;
}
- (void)shutdown {
[_threadSynchronizer shutdown];
}

View File

@ -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);
}