1 --- tools/sk_app/mac/WindowContextFactory_mac.h 2022-02-16 06:03:39.000000000 -0500
2 +++ tools/sk_app/mac/WindowContextFactory_mac.h 2023-01-25 08:09:00.000000000 -0500
7 -static inline CGFloat GetBackingScaleFactor(NSView* view) {
8 - #ifdef SK_BUILD_FOR_IOS
9 - UIScreen* screen = view.window.screen ?: [UIScreen mainScreen];
10 - return screen.nativeScale;
12 - NSScreen* screen = view.window.screen ?: [NSScreen mainScreen];
13 - return screen.backingScaleFactor;
16 +SK_API CGFloat GetBackingScaleFactor(NSView* view);
17 +SK_API void ResetBackingScaleFactor();
19 namespace window_context_factory {
21 --- tools/sk_app/mac/MetalWindowContext_mac.mm 2021-11-25 10:39:27.000000000 -0500
22 +++ tools/sk_app/mac/MetalWindowContext_mac.mm 2023-01-25 08:20:32.000000000 -0500
24 fMetalLayer.drawableSize = backingSize;
25 fMetalLayer.contentsScale = backingScaleFactor;
27 + // Related tdf#147342 Copy layer's colorspace to window's colorspace
28 + // This method is now called when the window's backing properties have
29 + // changed so copy any colorspace changes.
30 + NSColorSpace* cs = fMainView.window.colorSpace;
31 + fMetalLayer.colorspace = cs.CGColorSpace;
33 fWidth = backingSize.width;
34 fHeight = backingSize.height;
36 --- /dev/null 2023-01-25 09:20:55.000000000 -0500
37 +++ tools/sk_app/mac/WindowContextFactory_mac.mm 2023-01-25 09:21:22.000000000 -0500
40 + * Use of this source code is governed by a BSD-style license that can be
41 + * found in the LICENSE file.
44 +#include "tools/sk_app/mac/WindowContextFactory_mac.h"
48 +static bool bWindowScaling = false;
49 +static float fWindowScale = 1.0f;
51 +CGFloat GetBackingScaleFactor(NSView* view) {
52 + #ifdef SK_BUILD_FOR_IOS
53 + UIScreen* screen = view.window.screen ?: [UIScreen mainScreen];
54 + return screen.nativeScale;
56 + // Related: tdf#147342 This should always be an exact copy of the
57 + // sal::aqua::getWindowScaling() function in the following file:
58 + // vcl/osx/salgdiutils.cxx
61 + if (!bWindowScaling)
63 + NSArray *aScreens = [NSScreen screens];
66 + for (NSScreen *aScreen : aScreens)
68 + float fScale = [aScreen backingScaleFactor];
69 + if (fScale > fWindowScale)
70 + fWindowScale = fScale;
72 + bWindowScaling = true;
74 + if( const char* env = getenv("SAL_FORCE_HIDPI_SCALING"))
76 + fWindowScale = atof(env);
77 + bWindowScaling = true;
80 + return fWindowScale;
84 +void ResetBackingScaleFactor() {
85 + #ifndef SK_BUILD_FOR_IOS
86 + // Related: tdf#147342 Force recalculation of the window scaling but keep
87 + // the previous window scaling as the minimum so that we don't lose the
88 + // resolution in cached images if a HiDPI monitor is disconnected and
89 + // then reconnected.
90 + bWindowScaling = false;
91 + GetBackingScaleFactor(nil);
95 +} // namespace sk_app