Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 setUIState (const char *)
 
virtual const char * getClipboardText ()
 
virtual void setClipboardText (const char *)
 
void inval ()
 
virtual bool scaleContentToFit () const
 
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 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 ()
 
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:
127 fWindowContext = skwindow::MakeANGLEForMac(info, fRequestedDisplayParams);
128 break;
129#endif
130#ifdef SK_DAWN
131#if defined(SK_GRAPHITE)
132 case kGraphiteDawn_BackendType:
133 fWindowContext = MakeGraphiteDawnMetalForMac(info, fRequestedDisplayParams);
134 break;
135#endif
136#endif
137#ifdef SK_VULKAN
138 case kVulkan_BackendType:
139 fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams);
140 break;
141#endif
142#ifdef SK_METAL
143 case kMetal_BackendType:
144 fWindowContext = MakeMetalForMac(info, fRequestedDisplayParams);
145 break;
146#if defined(SK_GRAPHITE)
147 case kGraphiteMetal_BackendType:
148 fWindowContext = MakeGraphiteMetalForMac(info, fRequestedDisplayParams);
149 break;
150#endif
151#endif
152#ifdef SK_GL
153 case kNativeGL_BackendType:
155 break;
157 fWindowContext = MakeRasterForMac(info, fRequestedDisplayParams);
158 break;
159#endif
160 default:
161 SkASSERT_RELEASE(false);
162 }
163 this->onBackendCreated();
164
165 return SkToBool(fWindowContext);
166}
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:171
std::unique_ptr< skwindow::WindowContext > fWindowContext
Definition Window.h:174
void onBackendCreated()
Definition Window.cpp:44

◆ 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

◆ 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 172 of file Window_mac.mm.

172 {
173 gWindowMap.foreach([&](Window_mac* window) {
174 if (window->fIsContentInvalidated) {
175 window->onPaint();
176 }
177 });
178}
NSWindow * window()
Definition Window_mac.h:48

◆ scaleFactor()

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

Reimplemented from sk_app::Window.

Definition at line 168 of file Window_mac.mm.

168 {
169 return skwindow::GetBackingScaleFactor(fWindow.contentView);
170}
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

◆ 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: