aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac/SkOSWindow_Mac.mm
blob: a256b39fa31a1021bb3d43a83ccb66d68715fa0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#import  <Cocoa/Cocoa.h>
#include "SkOSWindow_Mac.h"
#include "SkOSMenu.h"
#include "SkTypes.h"
#include "SkWindow.h"
#import  "SkNSView.h"
#import  "SkEventNotifier.h"
#define  kINVAL_NSVIEW_EventType "inval-nsview"

static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");

SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
    fInvalEventIsPending = false;
    fGLContext = NULL;
    fNotifier = [[SkEventNotifier alloc] init];
}
SkOSWindow::~SkOSWindow() {
    [(SkEventNotifier*)fNotifier release];
}

void SkOSWindow::onHandleInval(const SkIRect& r) {
    if (!fInvalEventIsPending) {
        fInvalEventIsPending = true;
        (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
    }
}

bool SkOSWindow::onEvent(const SkEvent& evt) {
    if (evt.isType(kINVAL_NSVIEW_EventType)) {
        fInvalEventIsPending = false;
        const SkIRect& r = this->getDirtyBounds();
        [(SkNSView*)fHWND postInvalWithRect:&r];
        [(NSOpenGLContext*)fGLContext update];
        return true;
    }
    if ([(SkNSView*)fHWND onHandleEvent:evt]) {
        return true;
    }
    return this->INHERITED::onEvent(evt);
}

bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner,
                                 unsigned modi) {
    return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
}

void SkOSWindow::onSetTitle(const char title[]) {
    [(SkNSView*)fHWND setSkTitle:title];
}

void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
    [(SkNSView*)fHWND onAddMenu:menu];
}

void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
    [(SkNSView*)fHWND onUpdateMenu:menu];
}

bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, bool /*deepColor*/,
                        AttachmentInfo* info) {
    return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info];
}

void SkOSWindow::release() {
    [(SkNSView*)fHWND detach];
}

void SkOSWindow::present() {
    [(SkNSView*)fHWND present];
}

void SkOSWindow::closeWindow() {
    [[(SkNSView*)fHWND window] close];
}

void SkOSWindow::setVsync(bool enable) {
    [(SkNSView*)fHWND setVSync:enable];
}

bool SkOSWindow::makeFullscreen() {
    NSScreen* _Nullable screen = [NSScreen mainScreen];
    if (screen) {
        [(SkNSView*)fHWND enterFullScreenMode:(NSScreen* _Nonnull)screen withOptions:nil];
    }
    return true;
}