Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
sk_app::Window_mac Class Reference

#include <Window_mac.h>

Inheritance diagram for sk_app::Window_mac:
sk_app::Window

Public Member Functions

 Window_mac ()
 
 ~Window_mac () override
 
bool initWindow ()
 
void setTitle (const char *) override
 
void show () override
 
bool attach (BackendType) override
 
void onInval () override
 
float scaleFactor () const override
 
NSWindow * window ()
 
void closeWindow ()
 
- Public Member Functions inherited from sk_app::Window
virtual ~Window ()
 
virtual void setTitle (const char *)=0
 
virtual void show ()=0
 
virtual void setUIState (const char *)
 
virtual const char * getClipboardText ()
 
virtual void setClipboardText (const char *)
 
void inval ()
 
virtual bool scaleContentToFit () const
 
virtual bool attach (BackendType)=0
 
void detach ()
 
void pushLayer (Layer *layer)
 
void onBackendCreated ()
 
bool onChar (SkUnichar c, skui::ModifierKey modifiers)
 
bool onKey (skui::Key key, skui::InputState state, skui::ModifierKey modifiers)
 
bool onMouse (int x, int y, skui::InputState state, skui::ModifierKey modifiers)
 
bool onMouseWheel (float delta, int x, int y, skui::ModifierKey modifiers)
 
bool onTouch (intptr_t owner, skui::InputState state, float x, float y)
 
bool onFling (skui::InputState state)
 
bool onPinch (skui::InputState state, float scale, float x, float y)
 
void onUIStateChanged (const SkString &stateName, const SkString &stateValue)
 
void onPaint ()
 
void onResize (int width, int height)
 
void onActivate (bool isActive)
 
int width () const
 
int height () const
 
virtual float scaleFactor () const
 
virtual const DisplayParamsgetRequestedDisplayParams ()
 
virtual void setRequestedDisplayParams (const DisplayParams &, bool allowReattach=true)
 
int sampleCount () const
 
int stencilBits () const
 
GrDirectContextdirectContext () const
 
skgpu::graphite::ContextgraphiteContext () const
 
skgpu::graphite::RecordergraphiteRecorder () const
 

Static Public Member Functions

static void PaintWindows ()
 
static const NSInteger & GetKey (const Window_mac &w)
 
static uint32_t Hash (const NSInteger &windowNumber)
 
- Static Public Member Functions inherited from sk_app::Window
static WindowCreateNativeWindow (void *platformData)
 

Additional Inherited Members

- Public Types inherited from sk_app::Window
enum  BackendType { kRaster_BackendType , kLast_BackendType = kRaster_BackendType }
 
enum  { kBackendTypeCount = kLast_BackendType + 1 }
 
- Protected Member Functions inherited from sk_app::Window
 Window ()
 
virtual void onInval ()=0
 
void markInvalProcessed ()
 
void visitLayers (const std::function< void(Layer *)> &visitor)
 
bool signalLayers (const std::function< bool(Layer *)> &visitor)
 
- Protected Attributes inherited from sk_app::Window
SkTDArray< Layer * > fLayers
 
DisplayParams fRequestedDisplayParams
 
bool fIsActive = true
 
std::unique_ptr< skwindow::WindowContextfWindowContext
 
bool fIsContentInvalidated = false
 

Detailed Description

Definition at line 18 of file Window_mac.h.

Constructor & Destructor Documentation

◆ Window_mac()

sk_app::Window_mac::Window_mac ( )
inline

Definition at line 20 of file Window_mac.h.

21 : Window()
22 , fWindow(nil) {}

◆ ~Window_mac()

sk_app::Window_mac::~Window_mac ( )
inlineoverride

Definition at line 23 of file Window_mac.h.

23 {
24 this->closeWindow();
25 }

Member Function Documentation

◆ attach()

bool sk_app::Window_mac::attach ( BackendType  attachType)
overridevirtual

Implements sk_app::Window.

Definition at line 119 of file Window_mac.mm.

119 {
120 this->initWindow();
121
123 info.fMainView = [fWindow contentView];
124 switch (attachType) {
125#if SK_ANGLE
126 case kANGLE_BackendType:
128 break;
129#endif
130#ifdef SK_DAWN
131#if defined(SK_GRAPHITE)
132 case kGraphiteDawn_BackendType:
134 break;
135#endif
136#endif
137#ifdef SK_VULKAN
138 case kVulkan_BackendType:
139 fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams);
140 break;
141#if defined(SK_GRAPHITE)
142 case kGraphiteVulkan_BackendType:
143 fWindowContext = nullptr;
144 return false;
145#endif
146#endif
147#ifdef SK_METAL
148 case kMetal_BackendType:
150 break;
151#if defined(SK_GRAPHITE)
152 case kGraphiteMetal_BackendType:
154 break;
155#endif
156#endif
157#ifdef SK_GL
158 case kNativeGL_BackendType:
160 break;
163 break;
164#endif
165 default:
166 SkASSERT_RELEASE(false);
167 }
168 this->onBackendCreated();
169
170 return SkToBool(fWindowContext);
171}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
@ kRaster_BackendType
Definition: Window.h:90
DisplayParams fRequestedDisplayParams
Definition: Window.h:176
std::unique_ptr< skwindow::WindowContext > fWindowContext
Definition: Window.h:179
void onBackendCreated()
Definition: Window.cpp:44
std::unique_ptr< WindowContext > MakeGraphiteDawnMetalForMac(const MacWindowInfo &info, const DisplayParams &params)
std::unique_ptr< WindowContext > MakeGLForMac(const MacWindowInfo &info, const DisplayParams &params)
std::unique_ptr< WindowContext > MakeRasterForMac(const MacWindowInfo &info, const DisplayParams &params)
std::unique_ptr< WindowContext > MakeMetalForMac(const MacWindowInfo &info, const DisplayParams &params)
std::unique_ptr< WindowContext > MakeANGLEForMac(const MacWindowInfo &info, const DisplayParams &params)
std::unique_ptr< WindowContext > MakeGraphiteMetalForMac(const MacWindowInfo &info, const DisplayParams &params)

◆ closeWindow()

void sk_app::Window_mac::closeWindow ( )

Definition at line 95 of file Window_mac.mm.

95 {
96 if (nil != fWindow) {
97 gWindowMap.remove(fWindowNumber);
98 if (sk_app::Window_mac::gWindowMap.count() < 1) {
99 [NSApp terminate:fWindow];
100 }
101 [fWindow close];
102 fWindow = nil;
103 }
104}
int count
Definition: FontMgrTest.cpp:50

◆ GetKey()

static const NSInteger & sk_app::Window_mac::GetKey ( const Window_mac w)
inlinestatic

Definition at line 40 of file Window_mac.h.

40 {
41 return w.fWindowNumber;
42 }
SkScalar w

◆ Hash()

static uint32_t sk_app::Window_mac::Hash ( const NSInteger &  windowNumber)
inlinestatic

Definition at line 44 of file Window_mac.h.

44 {
45 return windowNumber;
46 }

◆ initWindow()

bool sk_app::Window_mac::initWindow ( )

Definition at line 45 of file Window_mac.mm.

45 {
46 // we already have a window
47 if (fWindow) {
48 return true;
49 }
50
51 // Create a delegate to track certain events
52 WindowDelegate* delegate = [[WindowDelegate alloc] initWithWindow:this];
53 if (nil == delegate) {
54 return false;
55 }
56
57 // Create Cocoa window
58 constexpr int initialWidth = 1280;
59 constexpr int initialHeight = 960;
60 NSRect windowRect = NSMakeRect(100, 100, initialWidth, initialHeight);
61
62 NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask |
63 NSMiniaturizableWindowMask);
64
65 fWindow = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle
66 backing:NSBackingStoreBuffered defer:NO];
67 if (nil == fWindow) {
68 [delegate release];
69 return false;
70 }
71
72 // create view
73 MainView* view = [[MainView alloc] initWithWindow:this];
74 if (nil == view) {
75 [fWindow release];
76 [delegate release];
77 return false;
78 }
79
80 [fWindow setContentView:view];
81 [fWindow makeFirstResponder:view];
82 [fWindow setDelegate:delegate];
83 [fWindow setAcceptsMouseMovedEvents:YES];
84 [fWindow setRestorable:NO];
85
86 // Should be retained by window now
87 [view release];
88
89 fWindowNumber = fWindow.windowNumber;
90 gWindowMap.add(this);
91
92 return true;
93}

◆ onInval()

void sk_app::Window_mac::onInval ( )
inlineoverridevirtual

Implements sk_app::Window.

Definition at line 34 of file Window_mac.h.

34{}

◆ PaintWindows()

void sk_app::Window_mac::PaintWindows ( )
static

Definition at line 177 of file Window_mac.mm.

177 {
178 gWindowMap.foreach([&](Window_mac* window) {
179 if (window->fIsContentInvalidated) {
180 window->onPaint();
181 }
182 });
183}
NSWindow * window()
Definition: Window_mac.h:48

◆ scaleFactor()

float sk_app::Window_mac::scaleFactor ( ) const
overridevirtual

Reimplemented from sk_app::Window.

Definition at line 173 of file Window_mac.mm.

173 {
174 return skwindow::GetBackingScaleFactor(fWindow.contentView);
175}
static CGFloat GetBackingScaleFactor(NSView *view)

◆ setTitle()

void sk_app::Window_mac::setTitle ( const char *  title)
overridevirtual

Implements sk_app::Window.

Definition at line 106 of file Window_mac.mm.

106 {
107 if (NSString* titleStr = [NSString stringWithUTF8String:title]) {
108 [fWindow setTitle:titleStr];
109 }
110}
void setTitle(const char *) override
Definition: Window_mac.mm:106

◆ show()

void sk_app::Window_mac::show ( )
overridevirtual

Implements sk_app::Window.

Definition at line 112 of file Window_mac.mm.

112 {
113 [fWindow orderFront:nil];
114
115 [NSApp activateIgnoringOtherApps:YES];
116 [fWindow makeKeyAndOrderFront:NSApp];
117}

◆ window()

NSWindow * sk_app::Window_mac::window ( )
inline

Definition at line 48 of file Window_mac.h.

48{ return fWindow; }

The documentation for this class was generated from the following files: