reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkOSWindow_Unix_DEFINED |
| 9 | #define SkOSWindow_Unix_DEFINED |
| 10 | |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 11 | #include <GL/glx.h> |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 12 | #include <X11/Xlib.h> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 14 | #include "SkWindow.h" |
| 15 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 16 | class SkEvent; |
| 17 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | struct SkUnixWindow { |
| 19 | Display* fDisplay; |
| 20 | Window fWin; |
| 21 | size_t fOSWin; |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 22 | GC fGc; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 23 | GLXContext fGLContext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | class SkOSWindow : public SkWindow { |
| 27 | public: |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 28 | SkOSWindow(void*); |
| 29 | ~SkOSWindow(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 31 | void* getHWND() const { return (void*)fUnixWindow.fWin; } |
| 32 | void* getDisplay() const { return (void*)fUnixWindow.fDisplay; } |
| 33 | void* getUnixWindow() const { return (void*)&fUnixWindow; } |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 34 | void loop(); |
| 35 | void post_linuxevent(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 36 | |
| 37 | enum SkBackEndTypes { |
| 38 | kNone_BackEndType, |
| 39 | kNativeGL_BackEndType, |
| 40 | }; |
| 41 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 42 | bool attach(SkBackEndTypes attachType, int msaaSampleCount); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 43 | void detach(); |
| 44 | void present(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 46 | int getMSAASampleCount() const { return fMSAASampleCount; } |
| 47 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 48 | //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | protected: |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 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; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 60 | void doPaint(); |
| 61 | void mapWindowAndWait(); |
| 62 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 63 | void closeWindow(); |
| 64 | void initWindow(int newMSAASampleCount); |
| 65 | |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 66 | SkUnixWindow fUnixWindow; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 67 | |
| 68 | // Needed for GL |
| 69 | XVisualInfo* fVi; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 70 | // we recreate the underlying xwindow if this changes |
| 71 | int fMSAASampleCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | typedef SkWindow INHERITED; |
| 74 | }; |
| 75 | |
| 76 | #endif |