epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkOSWindow_Win_DEFINED |
| 11 | #define SkOSWindow_Win_DEFINED |
| 12 | |
mtklein | fd8ed69 | 2015-07-28 09:54:52 -0700 | [diff] [blame] | 13 | #include "../private/SkTHash.h" |
| 14 | #include "SkWindow.h" |
mtklein | 6459352 | 2015-11-12 10:41:05 -0800 | [diff] [blame] | 15 | #include <functional> |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 17 | #if SK_ANGLE |
| 18 | #include "EGL/egl.h" |
| 19 | #endif |
| 20 | |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 21 | #if SK_COMMAND_BUFFER |
| 22 | class SkCommandBufferGLContext; |
| 23 | #endif |
| 24 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | class SkOSWindow : public SkWindow { |
| 26 | public: |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 27 | struct WindowInit { |
bsalomon | 48297f7 | 2015-06-16 12:21:00 -0700 | [diff] [blame] | 28 | const TCHAR* fClass; |
| 29 | HINSTANCE fInstance; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 30 | }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 32 | SkOSWindow(const void* winInit); |
| 33 | virtual ~SkOSWindow(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | |
| 35 | static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 36 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 37 | enum SkBackEndTypes { |
| 38 | kNone_BackEndType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 39 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 40 | kNativeGL_BackEndType, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 41 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 42 | kANGLE_BackEndType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 43 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 44 | #if SK_COMMAND_BUFFER |
kkinnunen | f655e93 | 2016-03-03 07:39:48 -0800 | [diff] [blame] | 45 | kCommandBuffer_BackEndType, |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 46 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 47 | #endif // SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 48 | }; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 50 | bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame^] | 51 | void release(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 52 | void present(); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 53 | |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 54 | bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
| 55 | static bool QuitOnDeactivate(HWND hWnd); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | |
| 57 | enum { |
| 58 | SK_WM_SkEvent = WM_APP + 1000, |
| 59 | SK_WM_SkTimerID = 0xFFFF // just need a non-zero value |
| 60 | }; |
| 61 | |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 62 | bool makeFullscreen(); |
| 63 | void setVsync(bool); |
| 64 | void closeWindow(); |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 65 | |
| 66 | static SkOSWindow* GetOSWindowForHWND(void* hwnd) { |
| 67 | SkOSWindow** win = gHwndToOSWindowMap.find(hwnd); |
| 68 | if (!win) { |
| 69 | return NULL; |
| 70 | } |
| 71 | return *win; |
| 72 | } |
| 73 | |
mtklein | 6459352 | 2015-11-12 10:41:05 -0800 | [diff] [blame] | 74 | // Iterates f over all the SkOSWindows and their corresponding HWNDs. |
| 75 | // The void* argument to f is a HWND. |
| 76 | static void ForAllWindows(const std::function<void(void*, SkOSWindow**)>& f) { |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 77 | gHwndToOSWindowMap.foreach(f); |
| 78 | } |
| 79 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 80 | protected: |
| 81 | virtual bool quitOnDeactivate() { return true; } |
| 82 | |
| 83 | // overrides from SkWindow |
| 84 | virtual void onHandleInval(const SkIRect&); |
| 85 | // overrides from SkView |
| 86 | virtual void onAddMenu(const SkOSMenu*); |
| 87 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 88 | virtual void onSetTitle(const char title[]); |
| 89 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | private: |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 91 | static SkTHashMap<void*, SkOSWindow*> gHwndToOSWindowMap; |
| 92 | |
| 93 | WindowInit fWinInit; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 94 | void* fHWND; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 95 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 96 | void doPaint(void* ctx); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 97 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 98 | #if SK_SUPPORT_GPU |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 99 | void* fHGLRC; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 100 | #if SK_ANGLE |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 101 | EGLDisplay fDisplay; |
| 102 | EGLContext fContext; |
| 103 | EGLSurface fSurface; |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 104 | EGLConfig fConfig; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 105 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 106 | #if SK_COMMAND_BUFFER |
| 107 | SkCommandBufferGLContext* fCommandBuffer; |
| 108 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 109 | #endif // SK_SUPPORT_GPU |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 111 | bool fFullscreen; |
| 112 | struct SavedWindowState { |
| 113 | bool fZoomed; |
| 114 | LONG fStyle; |
| 115 | LONG fExStyle; |
| 116 | RECT fRect; |
| 117 | LONG fScreenWidth; |
| 118 | LONG fScreenHeight; |
| 119 | LONG fScreenBits; |
| 120 | void* fHWND; |
| 121 | } fSavedWindowState; |
| 122 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 123 | HMENU fMBar; |
| 124 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 125 | SkBackEndTypes fAttached; |
| 126 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 127 | void updateSize(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 128 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 129 | bool attachGL(int msaaSampleCount, AttachmentInfo* info); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 130 | void detachGL(); |
| 131 | void presentGL(); |
| 132 | |
| 133 | #if SK_ANGLE |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 134 | bool attachANGLE(int msaaSampleCount, AttachmentInfo* info); |
bsalomon@google.com | 3c4d032 | 2012-04-03 18:04:51 +0000 | [diff] [blame] | 135 | void detachANGLE(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 136 | void presentANGLE(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 137 | #endif // SK_ANGLE |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 138 | |
| 139 | #if SK_COMMAND_BUFFER |
| 140 | bool attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info); |
| 141 | void detachCommandBuffer(); |
| 142 | void presentCommandBuffer(); |
| 143 | #endif // SK_COMMAND_BUFFER |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 144 | #endif // SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 145 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 146 | typedef SkWindow INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | #endif |