yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame] | 1 | /* |
| 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.org | e229e92 | 2012-09-27 13:44:57 +0000 | [diff] [blame] | 8 | #if defined(SK_BUILD_FOR_MAC) |
yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame] | 9 | |
| 10 | #import <Cocoa/Cocoa.h> |
| 11 | #include "SkOSWindow_Mac.h" |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 12 | #include "SkOSMenu.h" |
| 13 | #include "SkTypes.h" |
| 14 | #include "SkWindow.h" |
yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame] | 15 | #import "SkNSView.h" |
| 16 | #import "SkEventNotifier.h" |
| 17 | #define kINVAL_NSVIEW_EventType "inval-nsview" |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | 2e40173 | 2012-08-03 19:25:10 +0000 | [diff] [blame] | 19 | SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build); |
| 20 | |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 21 | SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { |
| 22 | fInvalEventIsPending = false; |
| 23 | fGLContext = NULL; |
| 24 | fNotifier = [[SkEventNotifier alloc] init]; |
| 25 | } |
| 26 | SkOSWindow::~SkOSWindow() { |
| 27 | [(SkEventNotifier*)fNotifier release]; |
| 28 | } |
| 29 | |
| 30 | void SkOSWindow::onHandleInval(const SkIRect& r) { |
| 31 | if (!fInvalEventIsPending) { |
| 32 | fInvalEventIsPending = true; |
yangsu@google.com | f3493f0 | 2011-08-08 15:12:05 +0000 | [diff] [blame] | 33 | (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post(); |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
| 37 | bool 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 | |
| 51 | bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner) { |
| 52 | return this->INHERITED::onDispatchClick(x, y, state, owner); |
| 53 | } |
| 54 | |
| 55 | void SkOSWindow::onSetTitle(const char title[]) { |
| 56 | [(SkNSView*)fHWND setSkTitle:title]; |
| 57 | } |
| 58 | |
| 59 | void SkOSWindow::onAddMenu(const SkOSMenu* menu) { |
| 60 | [(SkNSView*)fHWND onAddMenu:menu]; |
| 61 | } |
| 62 | |
| 63 | void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) { |
| 64 | [(SkNSView*)fHWND onUpdateMenu:menu]; |
| 65 | } |
| 66 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 67 | bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount) { |
| 68 | return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount]; |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 69 | } |
| 70 | |
robertphillips@google.com | d5b05ef | 2012-04-02 20:19:28 +0000 | [diff] [blame] | 71 | void SkOSWindow::detach() { |
| 72 | [(SkNSView*)fHWND detach]; |
yangsu@google.com | 12d177d | 2011-08-01 17:07:12 +0000 | [diff] [blame] | 73 | } |
| 74 | |
robertphillips@google.com | d5b05ef | 2012-04-02 20:19:28 +0000 | [diff] [blame] | 75 | void SkOSWindow::present() { |
| 76 | [(SkNSView*)fHWND present]; |
yangsu@google.com | a854041 | 2011-08-30 14:40:49 +0000 | [diff] [blame] | 77 | } |
| 78 | |
caryclark@google.com | 4ee8aea | 2011-11-23 14:54:19 +0000 | [diff] [blame] | 79 | #endif |