blob: a288ae34ba5df82b3b54e730cd4ec4fcbaa1662e [file] [log] [blame]
yangsu@google.coma8540412011-08-30 14:40:49 +00001/*
2 * Copyright 2011 Google Inc.
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
tfarina@chromium.orge229e922012-09-27 13:44:57 +00008#if defined(SK_BUILD_FOR_MAC)
yangsu@google.coma8540412011-08-30 14:40:49 +00009
10#import <Cocoa/Cocoa.h>
11#include "SkOSWindow_Mac.h"
yangsu@google.com12d177d2011-08-01 17:07:12 +000012#include "SkOSMenu.h"
13#include "SkTypes.h"
14#include "SkWindow.h"
yangsu@google.coma8540412011-08-30 14:40:49 +000015#import "SkNSView.h"
16#import "SkEventNotifier.h"
17#define kINVAL_NSVIEW_EventType "inval-nsview"
yangsu@google.com12d177d2011-08-01 17:07:12 +000018
bsalomon@google.com2e401732012-08-03 19:25:10 +000019SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
20
yangsu@google.com12d177d2011-08-01 17:07:12 +000021SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
22 fInvalEventIsPending = false;
23 fGLContext = NULL;
24 fNotifier = [[SkEventNotifier alloc] init];
25}
26SkOSWindow::~SkOSWindow() {
27 [(SkEventNotifier*)fNotifier release];
28}
29
30void SkOSWindow::onHandleInval(const SkIRect& r) {
31 if (!fInvalEventIsPending) {
32 fInvalEventIsPending = true;
yangsu@google.comf3493f02011-08-08 15:12:05 +000033 (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
yangsu@google.com12d177d2011-08-01 17:07:12 +000034 }
35}
36
37bool SkOSWindow::onEvent(const SkEvent& evt) {
38 if (evt.isType(kINVAL_NSVIEW_EventType)) {
39 fInvalEventIsPending = false;
40 const SkIRect& r = this->getDirtyBounds();
41 [(SkNSView*)fHWND postInvalWithRect:&r];
42 [(NSOpenGLContext*)fGLContext update];
43 return true;
44 }
45 if ([(SkNSView*)fHWND onHandleEvent:evt]) {
46 return true;
47 }
48 return this->INHERITED::onEvent(evt);
49}
50
51bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) {
52 return this->INHERITED::onDispatchClick(x, y, state, owner);
53}
54
55void SkOSWindow::onSetTitle(const char title[]) {
56 [(SkNSView*)fHWND setSkTitle:title];
57}
58
59void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
60 [(SkNSView*)fHWND onAddMenu:menu];
61}
62
63void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
64 [(SkNSView*)fHWND onUpdateMenu:menu];
65}
66
bsalomon@google.com11959252012-04-06 20:13:38 +000067bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount) {
68 return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount];
yangsu@google.com12d177d2011-08-01 17:07:12 +000069}
70
robertphillips@google.comd5b05ef2012-04-02 20:19:28 +000071void SkOSWindow::detach() {
72 [(SkNSView*)fHWND detach];
yangsu@google.com12d177d2011-08-01 17:07:12 +000073}
74
robertphillips@google.comd5b05ef2012-04-02 20:19:28 +000075void SkOSWindow::present() {
76 [(SkNSView*)fHWND present];
yangsu@google.coma8540412011-08-30 14:40:49 +000077}
78
caryclark@google.com4ee8aea2011-11-23 14:54:19 +000079#endif