Flutter Engine
The Flutter Engine
ANGLEWindowContext_mac.mm
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10
14
15namespace {
16
17class ANGLEWindowContext_mac : public ANGLEWindowContext {
18public:
19 ANGLEWindowContext_mac(const MacWindowInfo&, const DisplayParams&);
20
21protected:
22 EGLDisplay onGetEGLDisplay(
23 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const override;
24 NativeWindowType onGetNativeWindow() const override;
25 SkISize onGetSize() const override;
26 int onGetStencilBits() const override;
27
28private:
29 NSView* fMainView;
30};
31
32ANGLEWindowContext_mac::ANGLEWindowContext_mac(const MacWindowInfo& info,
33 const DisplayParams& params)
34 : ANGLEWindowContext(params), fMainView(info.fMainView) {
35 this->initializeContext();
36}
37
38EGLDisplay ANGLEWindowContext_mac::onGetEGLDisplay(
39 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const {
40 static constexpr EGLint kType = EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE;
41 static constexpr EGLint attribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, kType, EGL_NONE};
42 return eglGetPlatformDisplayEXT(
43 EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), attribs);
44}
45
46NativeWindowType ANGLEWindowContext_mac::onGetNativeWindow() const {
47 [fMainView setWantsLayer:YES];
48 return fMainView.layer;
49}
50
51int ANGLEWindowContext_mac::onGetStencilBits() const {
52 GLint stencilBits;
53 NSOpenGLPixelFormat* pixelFormat = skwindow::GetGLPixelFormat(fDisplayParams.fMSAASampleCount);
54 [pixelFormat getValues:&stencilBits forAttribute:NSOpenGLPFAStencilSize forVirtualScreen:0];
55 return stencilBits;
56}
57
58SkISize ANGLEWindowContext_mac::onGetSize() const {
59 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(fMainView);
60 return SkISize::Make(fMainView.bounds.size.width * backingScaleFactor,
61 fMainView.bounds.size.height * backingScaleFactor);
62}
63
64} // anonymous namespace
65
66namespace skwindow {
67
68std::unique_ptr<WindowContext> MakeANGLEForMac(const MacWindowInfo& info,
69 const DisplayParams& params) {
70 std::unique_ptr<WindowContext> ctx(new ANGLEWindowContext_mac(info, params));
71 if (!ctx->isValid()) {
72 return nullptr;
73 }
74 return ctx;
75}
76
77} // namespace skwindow
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE
#define EGL_PLATFORM_ANGLE_ANGLE
#define EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE
virtual SkISize onGetSize() const =0
virtual int onGetStencilBits() const =0
virtual EGLDisplay onGetEGLDisplay(PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT) const =0
virtual NativeWindowType onGetNativeWindow() const =0
const EmbeddedViewParams * params
std::unique_ptr< WindowContext > MakeANGLEForMac(const MacWindowInfo &info, const DisplayParams &params)
static CGFloat GetBackingScaleFactor(NSView *view)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20