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(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 35 | |
| 36 | enum SkBackEndTypes { |
| 37 | kNone_BackEndType, |
| 38 | kNativeGL_BackEndType, |
| 39 | }; |
| 40 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 41 | struct AttachmentInfo { |
| 42 | int fSampleCount; |
| 43 | int fStencilBits; |
| 44 | }; |
| 45 | |
| 46 | bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 47 | void detach(); |
| 48 | void present(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 50 | int getMSAASampleCount() const { return fMSAASampleCount; } |
| 51 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 52 | //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | protected: |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 55 | // Overridden from from SkWindow: |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 56 | virtual void onSetTitle(const char title[]) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | |
| 58 | private: |
reed@google.com | acb3d88 | 2013-06-17 13:42:43 +0000 | [diff] [blame^] | 59 | enum NextXEventResult { |
| 60 | kContinue_NextXEventResult, |
| 61 | kQuitRequest_NextXEventResult, |
| 62 | kPaintRequest_NextXEventResult |
| 63 | }; |
| 64 | |
| 65 | NextXEventResult nextXEvent(); |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 66 | void doPaint(); |
| 67 | void mapWindowAndWait(); |
| 68 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 69 | void closeWindow(); |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 70 | void initWindow(int newMSAASampleCount, AttachmentInfo* info); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 71 | |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 72 | SkUnixWindow fUnixWindow; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 73 | |
| 74 | // Needed for GL |
| 75 | XVisualInfo* fVi; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 76 | // we recreate the underlying xwindow if this changes |
| 77 | int fMSAASampleCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | typedef SkWindow INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |