WaE: C6011 Dereferencing NULL pointer warnings
[LibreOffice.git] / external / skia / tdf147342.patch.0
blob3b50038c07acc859c91a1d0233f4620ee2223b68
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
3 @@ -19,15 +19,8 @@
4  
5  struct DisplayParams;
6  
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;
11 -    #else
12 -    NSScreen* screen = view.window.screen ?: [NSScreen mainScreen];
13 -    return screen.backingScaleFactor;
14 -    #endif
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
23 @@ -11,6 +11,8 @@
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;
32 @@ -87,6 +89,18 @@
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;
50  }
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
53 @@ -0,0 +1,57 @@
54 +/*
55 + * Use of this source code is governed by a BSD-style license that can be
56 + * found in the LICENSE file.
57 + */
59 +#include "tools/sk_app/mac/WindowContextFactory_mac.h"
61 +namespace sk_app {
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;
70 +    #else
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
74 +    (void)view;
76 +    if (!bWindowScaling)
77 +    {
78 +        NSArray *aScreens = [NSScreen screens];
79 +        if (aScreens)
80 +        {
81 +            for (NSScreen *aScreen : aScreens)
82 +            {
83 +                float fScale = [aScreen backingScaleFactor];
84 +                if (fScale > fWindowScale)
85 +                  fWindowScale = fScale;
86 +            }
87 +            bWindowScaling = true;
88 +        }
89 +        if( const char* env = getenv("SAL_FORCE_HIDPI_SCALING"))
90 +        {
91 +            fWindowScale = atof(env);
92 +            bWindowScaling = true;
93 +        }
94 +    }
95 +    return fWindowScale;
96 +    #endif
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);
107 +    #endif
110 +}  // namespace sk_app