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();
     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     };
     40 
     41     struct AttachmentInfo {
     42         int fSampleCount;
     43         int fStencilBits;
     44     };
     45 
     46     bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
     47     void detach();
     48     void present();
     49 
     50     int getMSAASampleCount() const { return fMSAASampleCount; }
     51 
     52     //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
     53 
     54 protected:
     55     // Overridden from from SkWindow:
     56     virtual void onSetTitle(const char title[]) SK_OVERRIDE;
     57 
     58 private:
     59     enum NextXEventResult {
     60         kContinue_NextXEventResult,
     61         kQuitRequest_NextXEventResult,
     62         kPaintRequest_NextXEventResult
     63     };
     64 
     65     NextXEventResult nextXEvent();
     66     void doPaint();
     67     void mapWindowAndWait();
     68 
     69     void closeWindow();
     70     void initWindow(int newMSAASampleCount, AttachmentInfo* info);
     71 
     72     SkUnixWindow fUnixWindow;
     73 
     74     // Needed for GL
     75     XVisualInfo* fVi;
     76     // we recreate the underlying xwindow if this changes
     77     int fMSAASampleCount;
     78 
     79     typedef SkWindow INHERITED;
     80 };
     81 
     82 #endif
     83