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 8#if defined(SK_BUILD_FOR_MAC) 9 10#import <Cocoa/Cocoa.h> 11#include "SkOSWindow_Mac.h" 12#include "SkOSMenu.h" 13#include "SkTypes.h" 14#include "SkWindow.h" 15#import "SkNSView.h" 16#import "SkEventNotifier.h" 17#define kINVAL_NSVIEW_EventType "inval-nsview" 18 19SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build); 20 21SkOSWindow::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; 33 (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post(); 34 } 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 unsigned modi) { 53 return this->INHERITED::onDispatchClick(x, y, state, owner, modi); 54} 55 56void SkOSWindow::onSetTitle(const char title[]) { 57 [(SkNSView*)fHWND setSkTitle:title]; 58} 59 60void SkOSWindow::onAddMenu(const SkOSMenu* menu) { 61 [(SkNSView*)fHWND onAddMenu:menu]; 62} 63 64void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) { 65 [(SkNSView*)fHWND onUpdateMenu:menu]; 66} 67 68bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, AttachmentInfo* info) { 69 return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info]; 70} 71 72void SkOSWindow::detach() { 73 [(SkNSView*)fHWND detach]; 74} 75 76void SkOSWindow::present() { 77 [(SkNSView*)fHWND present]; 78} 79 80#endif 81