OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
23 * THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "MediaPlayerPrivateFullscreenWindow.h" | |
28 | |
29 #include "IntRect.h" | |
30 #include "WebCoreInstanceHandle.h" | |
31 #include <windows.h> | |
32 | |
33 #if USE(ACCELERATED_COMPOSITING) | |
34 #include "CACFLayerTreeHost.h" | |
35 #include "PlatformCALayer.h" | |
36 #endif | |
37 | |
38 namespace WebCore { | |
39 | |
40 MediaPlayerPrivateFullscreenWindow::MediaPlayerPrivateFullscreenWindow(MediaPlay
erPrivateFullscreenClient* client) | |
41 : m_client(client) | |
42 , m_hwnd(0) | |
43 { | |
44 } | |
45 | |
46 MediaPlayerPrivateFullscreenWindow::~MediaPlayerPrivateFullscreenWindow() | |
47 { | |
48 if (!m_hwnd) | |
49 return; | |
50 | |
51 ::DestroyWindow(m_hwnd); | |
52 ASSERT(!m_hwnd); | |
53 } | |
54 | |
55 void MediaPlayerPrivateFullscreenWindow::createWindow(HWND parentHwnd) | |
56 { | |
57 static ATOM windowAtom; | |
58 static LPCWSTR windowClassName = L"MediaPlayerPrivateFullscreenWindowClass"; | |
59 if (!windowAtom) { | |
60 WNDCLASSEX wcex = {0}; | |
61 wcex.cbSize = sizeof(WNDCLASSEX); | |
62 wcex.style = CS_HREDRAW | CS_VREDRAW; | |
63 wcex.lpfnWndProc = staticWndProc; | |
64 wcex.hInstance = instanceHandle(); | |
65 wcex.lpszClassName = windowClassName; | |
66 windowAtom = ::RegisterClassEx(&wcex); | |
67 } | |
68 | |
69 ASSERT(!m_hwnd); | |
70 | |
71 MONITORINFO mi = {0}; | |
72 mi.cbSize = sizeof(MONITORINFO); | |
73 if (!GetMonitorInfo(MonitorFromWindow(parentHwnd, MONITOR_DEFAULTTONEAREST),
&mi)) | |
74 return; | |
75 | |
76 IntRect monitorRect = mi.rcMonitor; | |
77 | |
78 ::CreateWindowExW(WS_EX_TOOLWINDOW, windowClassName, L"", WS_POPUP, | |
79 monitorRect.x(), monitorRect.y(), monitorRect.width(), monitorRect.heigh
t(), | |
80 parentHwnd, 0, WebCore::instanceHandle(), this); | |
81 ASSERT(IsWindow(m_hwnd)); | |
82 | |
83 #if USE(ACCELERATED_COMPOSITING) | |
84 if (m_layerTreeHost) | |
85 m_layerTreeHost->setWindow(m_hwnd); | |
86 #endif | |
87 | |
88 ::SetFocus(m_hwnd); | |
89 } | |
90 | |
91 #if USE(ACCELERATED_COMPOSITING) | |
92 void MediaPlayerPrivateFullscreenWindow::setRootChildLayer(PassRefPtr<PlatformCA
Layer> rootChild) | |
93 { | |
94 if (m_rootChild == rootChild) | |
95 return; | |
96 | |
97 if (m_rootChild) | |
98 m_rootChild->removeFromSuperlayer(); | |
99 | |
100 m_rootChild = rootChild; | |
101 | |
102 if (!m_rootChild) { | |
103 m_layerTreeHost = nullptr; | |
104 return; | |
105 } | |
106 | |
107 if (!m_layerTreeHost) { | |
108 m_layerTreeHost = CACFLayerTreeHost::create(); | |
109 if (m_hwnd) | |
110 m_layerTreeHost->setWindow(m_hwnd); | |
111 } | |
112 | |
113 m_layerTreeHost->setRootChildLayer(m_rootChild.get()); | |
114 PlatformCALayer* rootLayer = m_rootChild->rootLayer(); | |
115 CGRect rootBounds = m_rootChild->rootLayer()->bounds(); | |
116 m_rootChild->setFrame(rootBounds); | |
117 m_rootChild->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack)); | |
118 #ifndef NDEBUG | |
119 RetainPtr<CGColorRef> redColor(AdoptCF, CGColorCreateGenericRGB(1, 0, 0, 1))
; | |
120 rootLayer->setBackgroundColor(redColor.get()); | |
121 #else | |
122 rootLayer->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack)); | |
123 #endif | |
124 } | |
125 #endif | |
126 | |
127 LRESULT MediaPlayerPrivateFullscreenWindow::staticWndProc(HWND hWnd, UINT messag
e, WPARAM wParam, LPARAM lParam) | |
128 { | |
129 LONG_PTR longPtr = GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
130 | |
131 if (!longPtr && message == WM_CREATE) { | |
132 LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); | |
133 longPtr = reinterpret_cast<LONG_PTR>(lpcs->lpCreateParams); | |
134 ::SetWindowLongPtr(hWnd, GWLP_USERDATA, longPtr); | |
135 } | |
136 | |
137 if (MediaPlayerPrivateFullscreenWindow* window = reinterpret_cast<MediaPlaye
rPrivateFullscreenWindow*>(longPtr)) | |
138 return window->wndProc(hWnd, message, wParam, lParam); | |
139 | |
140 return ::DefWindowProc(hWnd, message, wParam, lParam); | |
141 } | |
142 | |
143 LRESULT MediaPlayerPrivateFullscreenWindow::wndProc(HWND hWnd, UINT message, WPA
RAM wParam, LPARAM lParam) | |
144 { | |
145 LRESULT lResult = 0; | |
146 switch (message) { | |
147 case WM_CREATE: | |
148 m_hwnd = hWnd; | |
149 break; | |
150 case WM_DESTROY: | |
151 m_hwnd = 0; | |
152 #if USE(ACCELERATED_COMPOSITING) | |
153 if (m_layerTreeHost) | |
154 m_layerTreeHost->setWindow(0); | |
155 #endif | |
156 break; | |
157 case WM_WINDOWPOSCHANGED: | |
158 { | |
159 LPWINDOWPOS wp = reinterpret_cast<LPWINDOWPOS>(lParam); | |
160 if (wp->flags & SWP_NOSIZE) | |
161 break; | |
162 #if USE(ACCELERATED_COMPOSITING) | |
163 if (m_layerTreeHost) { | |
164 m_layerTreeHost->resize(); | |
165 PlatformCALayer* rootLayer = m_rootChild->rootLayer(); | |
166 CGRect rootBounds = m_rootChild->rootLayer()->bounds(); | |
167 m_rootChild->setFrame(rootBounds); | |
168 m_rootChild->setNeedsLayout(); | |
169 } | |
170 #endif | |
171 } | |
172 break; | |
173 case WM_PAINT: | |
174 #if USE(ACCELERATED_COMPOSITING) | |
175 if (m_layerTreeHost) { | |
176 m_layerTreeHost->paint(); | |
177 ::ValidateRect(m_hwnd, 0); | |
178 } else | |
179 #endif | |
180 { | |
181 PAINTSTRUCT ps; | |
182 HDC hdc = ::BeginPaint(m_hwnd, &ps); | |
183 ::FillRect(hdc, &ps.rcPaint, (HBRUSH)::GetStockObject(BLACK_BRUSH)); | |
184 ::EndPaint(m_hwnd, &ps); | |
185 } | |
186 break; | |
187 case WM_PRINTCLIENT: | |
188 { | |
189 RECT clientRect; | |
190 HDC context = (HDC)wParam; | |
191 ::GetClientRect(m_hwnd, &clientRect); | |
192 ::FillRect(context, &clientRect, (HBRUSH)::GetStockObject(BLACK_BRUS
H)); | |
193 } | |
194 } | |
195 if (m_client) | |
196 lResult = m_client->fullscreenClientWndProc(hWnd, message, wParam, lPara
m); | |
197 | |
198 return lResult; | |
199 } | |
200 | |
201 } | |
OLD | NEW |