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 | |
| 13 | #include "SkWindow.h" |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 14 | #include "../../src/core/SkFunction.h" |
| 15 | #include "../../src/core/SkTHash.h" |
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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | class SkOSWindow : public SkWindow { |
| 22 | public: |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 23 | struct WindowInit { |
bsalomon | 48297f7 | 2015-06-16 12:21:00 -0700 | [diff] [blame] | 24 | const TCHAR* fClass; |
| 25 | HINSTANCE fInstance; |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 26 | }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 28 | SkOSWindow(const void* winInit); |
| 29 | virtual ~SkOSWindow(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
| 31 | static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 32 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 33 | enum SkBackEndTypes { |
| 34 | kNone_BackEndType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 35 | #if SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 36 | kNativeGL_BackEndType, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 37 | #if SK_ANGLE |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 38 | kANGLE_BackEndType, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 39 | #endif // SK_ANGLE |
| 40 | #endif // SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 41 | }; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 42 | |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 43 | bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 44 | void detach(); |
| 45 | void present(); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 46 | |
reed@android.com | e191b16 | 2009-12-18 21:33:39 +0000 | [diff] [blame] | 47 | bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
| 48 | static bool QuitOnDeactivate(HWND hWnd); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
| 50 | enum { |
| 51 | SK_WM_SkEvent = WM_APP + 1000, |
| 52 | SK_WM_SkTimerID = 0xFFFF // just need a non-zero value |
| 53 | }; |
| 54 | |
bsalomon | 85ab551 | 2015-06-16 12:47:25 -0700 | [diff] [blame] | 55 | bool makeFullscreen(); |
| 56 | void setVsync(bool); |
| 57 | void closeWindow(); |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 58 | |
| 59 | static SkOSWindow* GetOSWindowForHWND(void* hwnd) { |
| 60 | SkOSWindow** win = gHwndToOSWindowMap.find(hwnd); |
| 61 | if (!win) { |
| 62 | return NULL; |
| 63 | } |
| 64 | return *win; |
| 65 | } |
| 66 | |
| 67 | // Iterates SkFunction over all the SkOSWindows and their corresponding HWNDs. |
| 68 | // The void* argument to the SkFunction is a HWND. |
| 69 | static void ForAllWindows(const SkFunction<void(void*, SkOSWindow**)>& f) { |
| 70 | gHwndToOSWindowMap.foreach(f); |
| 71 | } |
| 72 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | protected: |
| 74 | virtual bool quitOnDeactivate() { return true; } |
| 75 | |
| 76 | // overrides from SkWindow |
| 77 | virtual void onHandleInval(const SkIRect&); |
| 78 | // overrides from SkView |
| 79 | virtual void onAddMenu(const SkOSMenu*); |
| 80 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 81 | virtual void onSetTitle(const char title[]); |
| 82 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | private: |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 84 | static SkTHashMap<void*, SkOSWindow*> gHwndToOSWindowMap; |
| 85 | |
| 86 | WindowInit fWinInit; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 87 | void* fHWND; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 88 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 89 | void doPaint(void* ctx); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 91 | #if SK_SUPPORT_GPU |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 92 | void* fHGLRC; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 93 | #if SK_ANGLE |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 94 | EGLDisplay fDisplay; |
| 95 | EGLContext fContext; |
| 96 | EGLSurface fSurface; |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 97 | EGLConfig fConfig; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 98 | #endif // SK_ANGLE |
| 99 | #endif // SK_SUPPORT_GPU |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 101 | bool fFullscreen; |
| 102 | struct SavedWindowState { |
| 103 | bool fZoomed; |
| 104 | LONG fStyle; |
| 105 | LONG fExStyle; |
| 106 | RECT fRect; |
| 107 | LONG fScreenWidth; |
| 108 | LONG fScreenHeight; |
| 109 | LONG fScreenBits; |
| 110 | void* fHWND; |
| 111 | } fSavedWindowState; |
| 112 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 113 | HMENU fMBar; |
| 114 | |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 115 | SkBackEndTypes fAttached; |
| 116 | |
bsalomon | 1e7951f | 2015-06-16 07:04:43 -0700 | [diff] [blame] | 117 | void updateSize(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 118 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 119 | bool attachGL(int msaaSampleCount, AttachmentInfo* info); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 120 | void detachGL(); |
| 121 | void presentGL(); |
| 122 | |
| 123 | #if SK_ANGLE |
bsalomon@google.com | 64cc810 | 2013-03-05 20:06:05 +0000 | [diff] [blame] | 124 | bool attachANGLE(int msaaSampleCount, AttachmentInfo* info); |
bsalomon@google.com | 3c4d032 | 2012-04-03 18:04:51 +0000 | [diff] [blame] | 125 | void detachANGLE(); |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 126 | void presentANGLE(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 127 | #endif // SK_ANGLE |
| 128 | #endif // SK_SUPPORT_GPU |
robertphillips@google.com | b442a6d | 2012-04-02 19:24:21 +0000 | [diff] [blame] | 129 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 130 | typedef SkWindow INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | #endif |