Home | History | Annotate | Download | only in mac
      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 
     19 static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");
     20 
     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;
     33         (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
     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                                  unsigned modi) {
     53     return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
     54 }
     55 
     56 void SkOSWindow::onSetTitle(const char title[]) {
     57     [(SkNSView*)fHWND setSkTitle:title];
     58 }
     59 
     60 void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
     61     [(SkNSView*)fHWND onAddMenu:menu];
     62 }
     63 
     64 void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
     65     [(SkNSView*)fHWND onUpdateMenu:menu];
     66 }
     67 
     68 bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, AttachmentInfo* info) {
     69     return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info];
     70 }
     71 
     72 void SkOSWindow::detach() {
     73     [(SkNSView*)fHWND detach];
     74 }
     75 
     76 void SkOSWindow::present() {
     77     [(SkNSView*)fHWND present];
     78 }
     79 
     80 void SkOSWindow::closeWindow() {
     81     [[(SkNSView*)fHWND window] close];
     82 }
     83 
     84 void SkOSWindow::setVsync(bool enable) {
     85     [(SkNSView*)fHWND setVSync:enable];
     86 }
     87 
     88 bool SkOSWindow::makeFullscreen() {
     89     [(SkNSView*)fHWND enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
     90     return true;
     91 }
     92 
     93 
     94 #endif
     95