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 #import  <Cocoa/Cocoa.h>
      9 #include "SkOSWindow_Mac.h"
     10 #include "SkOSMenu.h"
     11 #include "SkTypes.h"
     12 #include "SkWindow.h"
     13 #import  "SkNSView.h"
     14 #import  "SkEventNotifier.h"
     15 #define  kINVAL_NSVIEW_EventType "inval-nsview"
     16 
     17 static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");
     18 
     19 SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
     20     fInvalEventIsPending = false;
     21     fGLContext = NULL;
     22     fNotifier = [[SkEventNotifier alloc] init];
     23 }
     24 SkOSWindow::~SkOSWindow() {
     25     [(SkEventNotifier*)fNotifier release];
     26 }
     27 
     28 void SkOSWindow::onHandleInval(const SkIRect& r) {
     29     if (!fInvalEventIsPending) {
     30         fInvalEventIsPending = true;
     31         (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
     32     }
     33 }
     34 
     35 bool SkOSWindow::onEvent(const SkEvent& evt) {
     36     if (evt.isType(kINVAL_NSVIEW_EventType)) {
     37         fInvalEventIsPending = false;
     38         const SkIRect& r = this->getDirtyBounds();
     39         [(SkNSView*)fHWND postInvalWithRect:&r];
     40         [(NSOpenGLContext*)fGLContext update];
     41         return true;
     42     }
     43     if ([(SkNSView*)fHWND onHandleEvent:evt]) {
     44         return true;
     45     }
     46     return this->INHERITED::onEvent(evt);
     47 }
     48 
     49 bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner,
     50                                  unsigned modi) {
     51     return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
     52 }
     53 
     54 void SkOSWindow::onSetTitle(const char title[]) {
     55     [(SkNSView*)fHWND setSkTitle:title];
     56 }
     57 
     58 void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
     59     [(SkNSView*)fHWND onAddMenu:menu];
     60 }
     61 
     62 void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
     63     [(SkNSView*)fHWND onUpdateMenu:menu];
     64 }
     65 
     66 bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, bool /*deepColor*/,
     67                         AttachmentInfo* info) {
     68     return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info];
     69 }
     70 
     71 void SkOSWindow::release() {
     72     [(SkNSView*)fHWND detach];
     73 }
     74 
     75 void SkOSWindow::present() {
     76     [(SkNSView*)fHWND present];
     77 }
     78 
     79 void SkOSWindow::closeWindow() {
     80     [[(SkNSView*)fHWND window] close];
     81 }
     82 
     83 void SkOSWindow::setVsync(bool enable) {
     84     [(SkNSView*)fHWND setVSync:enable];
     85 }
     86 
     87 bool SkOSWindow::makeFullscreen() {
     88     NSScreen* _Nullable screen = [NSScreen mainScreen];
     89     if (screen) {
     90         [(SkNSView*)fHWND enterFullScreenMode:(NSScreen* _Nonnull)screen withOptions:nil];
     91     }
     92     return true;
     93 }
     94 
     95