• 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 class SkOSWindow : public SkWindow {
22 public:
23     struct WindowInit {
24         const TCHAR*    fClass;
25         HINSTANCE       fInstance;
26     };
27 
28     SkOSWindow(const void* winInit);
29     virtual ~SkOSWindow();
30 
31     static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
32 
33     enum SkBackEndTypes {
34         kNone_BackEndType,
35 #if SK_SUPPORT_GPU
36         kNativeGL_BackEndType,
37 #if SK_ANGLE
38         kANGLE_BackEndType,
39 #endif // SK_ANGLE
40 #endif // SK_SUPPORT_GPU
41     };
42 
43     bool attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor, AttachmentInfo*);
44     void release();
45     void present();
46 
47     bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
48     static bool QuitOnDeactivate(HWND hWnd);
49 
50     enum {
51         SK_WM_SkEvent = WM_APP + 1000,
52         SK_WM_SkTimerID = 0xFFFF    // just need a non-zero value
53     };
54 
55     bool makeFullscreen();
56     void setVsync(bool);
57     void closeWindow();
58 
GetOSWindowForHWND(void * hwnd)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 f over all the SkOSWindows and their corresponding HWNDs.
68     // The void* argument to f is a HWND.
ForAllWindows(const std::function<void (void *,SkOSWindow **)> & f)69     static void ForAllWindows(const std::function<void(void*, SkOSWindow**)>& f) {
70         gHwndToOSWindowMap.foreach(f);
71     }
72 
73 protected:
quitOnDeactivate()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 
81     virtual void onSetTitle(const char title[]);
82 
83 private:
84     static SkTHashMap<void*, SkOSWindow*> gHwndToOSWindowMap;
85 
86     WindowInit          fWinInit;
87     void*               fHWND;
88 
89     void                doPaint(void* ctx);
90 
91 #if SK_SUPPORT_GPU
92     void*               fHGLRC;
93 #if SK_ANGLE
94     EGLDisplay                 fDisplay;
95     EGLContext                 fContext;
96     EGLSurface                 fSurface;
97     EGLConfig                  fConfig;
98     sk_sp<const GrGLInterface> fANGLEInterface;
99 #endif // SK_ANGLE
100 #endif // SK_SUPPORT_GPU
101 
102     bool                fFullscreen;
103     struct SavedWindowState {
104         bool fZoomed;
105         LONG fStyle;
106         LONG fExStyle;
107         RECT fRect;
108         LONG fScreenWidth;
109         LONG fScreenHeight;
110         LONG fScreenBits;
111         void* fHWND;
112     } fSavedWindowState;
113 
114     HMENU               fMBar;
115 
116     SkBackEndTypes      fAttached;
117 
118     void updateSize();
119 #if SK_SUPPORT_GPU
120     bool attachGL(int msaaSampleCount, bool deepColor, AttachmentInfo* info);
121     void detachGL();
122     void presentGL();
123 
124 #if SK_ANGLE
125     bool attachANGLE(int msaaSampleCount, AttachmentInfo* info);
126     void detachANGLE();
127     void presentANGLE();
128 #endif // SK_ANGLE
129 
130 #endif // SK_SUPPORT_GPU
131 
132     typedef SkWindow INHERITED;
133 };
134 
135 #endif
136