Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
WindowContextFactory_mac.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2016 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef WindowContextFactory_mac_DEFINED
10#define WindowContextFactory_mac_DEFINED
11
13
14#include <Cocoa/Cocoa.h>
15
16#include <memory>
17
18namespace skwindow {
19
20struct DisplayParams;
21
22static inline CGFloat GetBackingScaleFactor(NSView* view) {
23 #ifdef SK_BUILD_FOR_IOS
24 UIScreen* screen = view.window.screen ?: [UIScreen mainScreen];
25 return screen.nativeScale;
26 #else
27 NSScreen* screen = view.window.screen ?: [NSScreen mainScreen];
28 return screen.backingScaleFactor;
29 #endif
30}
31
33 NSView* fMainView;
34};
35
36#if defined(SK_GL) || defined(SK_ANGLE)
37static inline NSOpenGLPixelFormat* GetGLPixelFormat(int sampleCount) {
38 constexpr int kMaxAttributes = 19;
39 NSOpenGLPixelFormatAttribute attributes[kMaxAttributes];
40 int numAttributes = 0;
41 attributes[numAttributes++] = NSOpenGLPFAAccelerated;
42 attributes[numAttributes++] = NSOpenGLPFAClosestPolicy;
43 attributes[numAttributes++] = NSOpenGLPFADoubleBuffer;
44 attributes[numAttributes++] = NSOpenGLPFAOpenGLProfile;
45 attributes[numAttributes++] = NSOpenGLProfileVersion3_2Core;
46 attributes[numAttributes++] = NSOpenGLPFAColorSize;
47 attributes[numAttributes++] = 24;
48 attributes[numAttributes++] = NSOpenGLPFAAlphaSize;
49 attributes[numAttributes++] = 8;
50 attributes[numAttributes++] = NSOpenGLPFADepthSize;
51 attributes[numAttributes++] = 0;
52 attributes[numAttributes++] = NSOpenGLPFAStencilSize;
53 attributes[numAttributes++] = 8;
54 if (sampleCount > 1) {
55 attributes[numAttributes++] = NSOpenGLPFAMultisample;
56 attributes[numAttributes++] = NSOpenGLPFASampleBuffers;
57 attributes[numAttributes++] = 1;
58 attributes[numAttributes++] = NSOpenGLPFASamples;
59 attributes[numAttributes++] = sampleCount;
60 } else {
61 attributes[numAttributes++] = NSOpenGLPFASampleBuffers;
62 attributes[numAttributes++] = 0;
63 }
64 attributes[numAttributes++] = 0;
65 SkASSERT(numAttributes <= kMaxAttributes);
66 return [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
67}
68#endif // defined(SK_GL) || defined(SK_ANGLE)
69
70#ifdef SK_VULKAN
71inline std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo&, const DisplayParams&) {
72 // No Vulkan support on Mac.
73 return nullptr;
74}
75#endif
76
77#ifdef SK_GL
78std::unique_ptr<WindowContext> MakeRasterForMac(const MacWindowInfo&, const DisplayParams&);
79std::unique_ptr<WindowContext> MakeGLForMac(const MacWindowInfo&, const DisplayParams&);
80#endif
81
82#ifdef SK_ANGLE
83std::unique_ptr<WindowContext> MakeANGLEForMac(const MacWindowInfo&, const DisplayParams&);
84#endif
85
86#ifdef SK_DAWN
87#if defined(SK_GRAPHITE)
88std::unique_ptr<WindowContext> MakeGraphiteDawnMetalForMac(const MacWindowInfo&, const DisplayParams&);
89#endif
90#endif
91
92#ifdef SK_METAL
93std::unique_ptr<WindowContext> MakeMetalForMac(const MacWindowInfo&, const DisplayParams&);
94#if defined(SK_GRAPHITE)
95std::unique_ptr<WindowContext> MakeGraphiteMetalForMac(const MacWindowInfo&, const DisplayParams&);
96#endif
97#endif
98
99} // namespace skwindow
100
101#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
static CGFloat GetBackingScaleFactor(NSView *view)