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 16class SkEvent; 17 18struct SkUnixWindow { 19 Display* fDisplay; 20 Window fWin; 21 size_t fOSWin; 22 GC fGc; 23 GLXContext fGLContext; 24}; 25 26class SkOSWindow : public SkWindow { 27public: 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 void post_linuxevent(); 36 37 enum SkBackEndTypes { 38 kNone_BackEndType, 39 kNativeGL_BackEndType, 40 }; 41 42 bool attach(SkBackEndTypes attachType, int msaaSampleCount); 43 void detach(); 44 void present(); 45 46 int getMSAASampleCount() const { return fMSAASampleCount; } 47 48 //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); 49 50protected: 51 // Overridden from from SkWindow: 52 virtual bool onEvent(const SkEvent&) SK_OVERRIDE; 53 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; 54 virtual bool onHandleChar(SkUnichar) SK_OVERRIDE; 55 virtual bool onHandleKey(SkKey) SK_OVERRIDE; 56 virtual bool onHandleKeyUp(SkKey) SK_OVERRIDE; 57 virtual void onSetTitle(const char title[]) SK_OVERRIDE; 58 59private: 60 void doPaint(); 61 void mapWindowAndWait(); 62 63 void closeWindow(); 64 void initWindow(int newMSAASampleCount); 65 66 SkUnixWindow fUnixWindow; 67 68 // Needed for GL 69 XVisualInfo* fVi; 70 // we recreate the underlying xwindow if this changes 71 int fMSAASampleCount; 72 73 typedef SkWindow INHERITED; 74}; 75 76#endif 77