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-28 14:55:57.000000000 -0500
24 #import <Cocoa/Cocoa.h>
25 #import <QuartzCore/CAConstraintLayoutManager.h>
27 +#include <sal/log.hxx>
29 using sk_app::DisplayParams;
30 using sk_app::window_context_factory::MacWindowInfo;
31 using sk_app::MetalWindowContext;
33 fMetalLayer.drawableSize = backingSize;
34 fMetalLayer.contentsScale = backingScaleFactor;
36 + // Related: tdf#147342 Copy layer's colorspace to window's colorspace
37 + // This method is now called when the window's backing properties have
38 + // changed so copy any colorspace changes.
39 + NSColorSpace* cs = fMainView.window.colorSpace;
40 + fMetalLayer.colorspace = cs.CGColorSpace;
41 + // Related tdf#145988 Reset layer's pixel format to MTLPixelFormatBGRA8Unorm
42 + // Skia initally sets the layer's pixel format to be BGRA8888 but macOS
43 + // may change the layer's pixel format when a window has moved to a screen
44 + // with 30-bit color depth so reset it back to BGRA8888.
45 + SAL_WARN_IF(fMetalLayer.pixelFormat != MTLPixelFormatBGRA8Unorm, "vcl.skia.metal", "CAMetalLayer pixel format is " << fMetalLayer.pixelFormat << " but should be " << MTLPixelFormatBGRA8Unorm << " (MTLPixelFormatBGRA8Unorm)");
46 + fMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
48 fWidth = backingSize.width;
49 fHeight = backingSize.height;
51 --- /dev/null 2023-01-25 09:20:55.000000000 -0500
52 +++ tools/sk_app/mac/WindowContextFactory_mac.mm 2023-01-25 09:21:22.000000000 -0500
55 + * Use of this source code is governed by a BSD-style license that can be
56 + * found in the LICENSE file.
59 +#include "tools/sk_app/mac/WindowContextFactory_mac.h"
63 +static bool bWindowScaling = false;
64 +static float fWindowScale = 1.0f;
66 +CGFloat GetBackingScaleFactor(NSView* view) {
67 + #ifdef SK_BUILD_FOR_IOS
68 + UIScreen* screen = view.window.screen ?: [UIScreen mainScreen];
69 + return screen.nativeScale;
71 + // Related: tdf#147342 This should always be an exact copy of the
72 + // sal::aqua::getWindowScaling() function in the following file:
73 + // vcl/osx/salgdiutils.cxx
76 + if (!bWindowScaling)
78 + NSArray *aScreens = [NSScreen screens];
81 + for (NSScreen *aScreen : aScreens)
83 + float fScale = [aScreen backingScaleFactor];
84 + if (fScale > fWindowScale)
85 + fWindowScale = fScale;
87 + bWindowScaling = true;
89 + if( const char* env = getenv("SAL_FORCE_HIDPI_SCALING"))
91 + fWindowScale = atof(env);
92 + bWindowScaling = true;
95 + return fWindowScale;
99 +void ResetBackingScaleFactor() {
100 + #ifndef SK_BUILD_FOR_IOS
101 + // Related: tdf#147342 Force recalculation of the window scaling but keep
102 + // the previous window scaling as the minimum so that we don't lose the
103 + // resolution in cached images if a HiDPI monitor is disconnected and
104 + // then reconnected.
105 + bWindowScaling = false;
106 + GetBackingScaleFactor(nil);
110 +} // namespace sk_app