• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkOSWindow_Win_DEFINED
11 #define SkOSWindow_Win_DEFINED
12 
13 #include "../private/SkTHash.h"
14 #include "SkWindow.h"
15 #include <functional>
16 
17 #if SK_ANGLE
18 #include "EGL/egl.h"
19 #endif
20 
21 #if SK_COMMAND_BUFFER
22 class SkCommandBufferGLContext;
23 #endif
24 
25 class SkOSWindow : public SkWindow {
26 public:
27     struct WindowInit {
28         const TCHAR*    fClass;
29         HINSTANCE       fInstance;
30     };
31 
32     SkOSWindow(const void* winInit);
33     virtual ~SkOSWindow();
34 
35     static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
36 
37     enum SkBackEndTypes {
38         kNone_BackEndType,
39 #if SK_SUPPORT_GPU
40         kNativeGL_BackEndType,
41 #if SK_ANGLE
42         kANGLE_BackEndType,
43 #endif // SK_ANGLE
44 #if SK_COMMAND_BUFFER
45         kCommandBufferES2_BackEndType,
46 #endif // SK_COMMAND_BUFFER
47 #endif // SK_SUPPORT_GPU
48     };
49 
50     bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
51     void detach();
52     void present();
53 
54     bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
55     static bool QuitOnDeactivate(HWND hWnd);
56 
57     enum {
58         SK_WM_SkEvent = WM_APP + 1000,
59         SK_WM_SkTimerID = 0xFFFF    // just need a non-zero value
60     };
61 
62     bool makeFullscreen();
63     void setVsync(bool);
64     void closeWindow();
65 
GetOSWindowForHWND(void * hwnd)66     static SkOSWindow* GetOSWindowForHWND(void* hwnd) {
67         SkOSWindow** win = gHwndToOSWindowMap.find(hwnd);
68         if (!win) {
69             return NULL;
70         }
71         return *win;
72     }
73 
74     // Iterates f over all the SkOSWindows and their corresponding HWNDs.
75     // The void* argument to f is a HWND.
ForAllWindows(const std::function<void (void *,SkOSWindow **)> & f)76     static void ForAllWindows(const std::function<void(void*, SkOSWindow**)>& f) {
77         gHwndToOSWindowMap.foreach(f);
78     }
79 
80 protected:
quitOnDeactivate()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 
88     virtual void onSetTitle(const char title[]);
89 
90 private:
91     static SkTHashMap<void*, SkOSWindow*> gHwndToOSWindowMap;
92 
93     WindowInit          fWinInit;
94     void*               fHWND;
95 
96     void                doPaint(void* ctx);
97 
98 #if SK_SUPPORT_GPU
99     void*               fHGLRC;
100 #if SK_ANGLE
101     EGLDisplay          fDisplay;
102     EGLContext          fContext;
103     EGLSurface          fSurface;
104     EGLConfig           fConfig;
105 #endif // SK_ANGLE
106 #if SK_COMMAND_BUFFER
107     SkCommandBufferGLContext* fCommandBuffer;
108 #endif // SK_COMMAND_BUFFER
109 #endif // SK_SUPPORT_GPU
110 
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 
123     HMENU               fMBar;
124 
125     SkBackEndTypes      fAttached;
126 
127     void updateSize();
128 #if SK_SUPPORT_GPU
129     bool attachGL(int msaaSampleCount, AttachmentInfo* info);
130     void detachGL();
131     void presentGL();
132 
133 #if SK_ANGLE
134     bool attachANGLE(int msaaSampleCount, AttachmentInfo* info);
135     void detachANGLE();
136     void presentANGLE();
137 #endif // SK_ANGLE
138 
139 #if SK_COMMAND_BUFFER
140     bool attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info);
141     void detachCommandBuffer();
142     void presentCommandBuffer();
143 #endif // SK_COMMAND_BUFFER
144 #endif // SK_SUPPORT_GPU
145 
146     typedef SkWindow INHERITED;
147 };
148 
149 #endif
150