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*); |
Yuqian Li | 6e3d995 | 2017-09-27 13:25:36 -0400 | [diff] [blame] | 29 | SkOSWindow(void*, int width, int height); |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 30 | ~SkOSWindow() override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 32 | void* getHWND() const { return (void*)fUnixWindow.fWin; } |
| 33 | void* getDisplay() const { return (void*)fUnixWindow.fDisplay; } |
| 34 | void* getUnixWindow() const { return (void*)&fUnixWindow; } |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 35 | void loop(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 36 | |
| 37 | enum SkBackEndTypes { |
| 38 | kNone_BackEndType, |
| 39 | kNativeGL_BackEndType, |
hendrikw | 6f0fdac | 2015-09-23 11:35:55 -0700 | [diff] [blame] | 40 | #if SK_ANGLE |
| 41 | kANGLE_BackEndType, |
| 42 | #endif // SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 45 | bool attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor, AttachmentInfo*); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 46 | void release(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 47 | void present(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 49 | int getMSAASampleCount() const { return fMSAASampleCount; } |
| 50 | |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 51 | //static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 53 | bool makeFullscreen(); |
| 54 | void setVsync(bool); |
| 55 | void closeWindow(); |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | protected: |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 58 | // Overridden from from SkWindow: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 59 | void onSetTitle(const char title[]) override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | |
| 61 | private: |
reed@google.com | acb3d88 | 2013-06-17 13:42:43 +0000 | [diff] [blame] | 62 | enum NextXEventResult { |
| 63 | kContinue_NextXEventResult, |
| 64 | kQuitRequest_NextXEventResult, |
| 65 | kPaintRequest_NextXEventResult |
| 66 | }; |
| 67 | |
| 68 | NextXEventResult nextXEvent(); |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 69 | void doPaint(); |
| 70 | void mapWindowAndWait(); |
| 71 | |
joshualitt | 7fe8ee4 | 2015-06-01 10:03:54 -0700 | [diff] [blame] | 72 | // Forcefully closes the window. If a graceful shutdown is desired then call the public |
| 73 | // closeWindow method |
| 74 | void internalCloseWindow(); |
Yuqian Li | 6e3d995 | 2017-09-27 13:25:36 -0400 | [diff] [blame] | 75 | void initWindow(int newMSAASampleCount, AttachmentInfo* info, int w, int h); |
| 76 | void init(int w, int h); |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 77 | |
tomhudson@google.com | 178b8e0 | 2012-03-05 18:29:23 +0000 | [diff] [blame] | 78 | SkUnixWindow fUnixWindow; |
Scroggo | 9df214e | 2011-04-15 14:48:08 +0000 | [diff] [blame] | 79 | |
| 80 | // Needed for GL |
| 81 | XVisualInfo* fVi; |
bsalomon@google.com | 1195925 | 2012-04-06 20:13:38 +0000 | [diff] [blame] | 82 | // we recreate the underlying xwindow if this changes |
| 83 | int fMSAASampleCount; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | typedef SkWindow INHERITED; |
| 86 | }; |
| 87 | |
| 88 | #endif |