Home | History | Annotate | Download | only in views
      1 /*
      2  * Copyright 2006 The Android Open Source Project
      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 #ifndef SkOSWindow_Unix_DEFINED
      9 #define SkOSWindow_Unix_DEFINED
     10 
     11 #include <GL/glx.h>
     12 #include <X11/Xlib.h>
     13 
     14 #include "SkWindow.h"
     15 
     16 class SkEvent;
     17 
     18 struct SkUnixWindow {
     19   Display* fDisplay;
     20   Window fWin;
     21   size_t fOSWin;
     22   GC fGc;
     23   GLXContext fGLContext;
     24 };
     25 
     26 class SkOSWindow : public SkWindow {
     27 public:
     28     SkOSWindow(void*);
     29     ~SkOSWindow() override;
     30 
     31     void* getHWND() const { return (void*)fUnixWindow.fWin; }
     32     void* getDisplay() const { return (void*)fUnixWindow.fDisplay; }
     33     void* getUnixWindow() const { return (void*)&fUnixWindow; }
     34     void loop();
     35 
     36     enum SkBackEndTypes {
     37         kNone_BackEndType,
     38         kNativeGL_BackEndType,
     39 #if SK_ANGLE
     40         kANGLE_BackEndType,
     41 #endif // SK_ANGLE
     42     };
     43 
     44     bool attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor, AttachmentInfo*);
     45     void release();
     46     void present();
     47 
     48     int getMSAASampleCount() const { return fMSAASampleCount; }
     49 
     50     //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
     51 
     52     bool makeFullscreen();
     53     void setVsync(bool);
     54     void closeWindow();
     55 
     56 protected:
     57     // Overridden from from SkWindow:
     58     void onSetTitle(const char title[]) override;
     59 
     60 private:
     61     enum NextXEventResult {
     62         kContinue_NextXEventResult,
     63         kQuitRequest_NextXEventResult,
     64         kPaintRequest_NextXEventResult
     65     };
     66 
     67     NextXEventResult nextXEvent();
     68     void doPaint();
     69     void mapWindowAndWait();
     70 
     71     // Forcefully closes the window.  If a graceful shutdown is desired then call the public
     72     // closeWindow method
     73     void internalCloseWindow();
     74     void initWindow(int newMSAASampleCount, AttachmentInfo* info);
     75 
     76     SkUnixWindow fUnixWindow;
     77 
     78     // Needed for GL
     79     XVisualInfo* fVi;
     80     // we recreate the underlying xwindow if this changes
     81     int fMSAASampleCount;
     82 
     83     typedef SkWindow INHERITED;
     84 };
     85 
     86 #endif
     87