2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "MediaPlayerPrivateFullscreenWindow.h"
30 #include "WebCoreInstanceHandle.h"
34 #include <CoreGraphics/CGColor.h>
37 #if USE(ACCELERATED_COMPOSITING)
38 #include "CACFLayerTreeHost.h"
39 #include "PlatformCALayer.h"
44 MediaPlayerPrivateFullscreenWindow::MediaPlayerPrivateFullscreenWindow(MediaPlayerPrivateFullscreenClient* client)
50 MediaPlayerPrivateFullscreenWindow::~MediaPlayerPrivateFullscreenWindow()
55 ::DestroyWindow(m_hwnd);
59 void MediaPlayerPrivateFullscreenWindow::createWindow(HWND parentHwnd)
61 static ATOM windowAtom;
62 static LPCWSTR windowClassName = L"MediaPlayerPrivateFullscreenWindowClass";
64 WNDCLASSEX wcex = {0};
65 wcex.cbSize = sizeof(WNDCLASSEX);
66 wcex.style = CS_HREDRAW | CS_VREDRAW;
67 wcex.lpfnWndProc = staticWndProc;
68 wcex.hInstance = instanceHandle();
69 wcex.lpszClassName = windowClassName;
70 windowAtom = ::RegisterClassEx(&wcex);
76 mi.cbSize = sizeof(MONITORINFO);
77 if (!GetMonitorInfo(MonitorFromWindow(parentHwnd, MONITOR_DEFAULTTONEAREST), &mi))
80 IntRect monitorRect = mi.rcMonitor;
82 ::CreateWindowExW(WS_EX_TOOLWINDOW, windowClassName, L"", WS_POPUP,
83 monitorRect.x(), monitorRect.y(), monitorRect.width(), monitorRect.height(),
84 parentHwnd, 0, WebCore::instanceHandle(), this);
85 ASSERT(IsWindow(m_hwnd));
87 #if USE(ACCELERATED_COMPOSITING)
89 m_layerTreeHost->setWindow(m_hwnd);
95 #if USE(ACCELERATED_COMPOSITING)
96 void MediaPlayerPrivateFullscreenWindow::setRootChildLayer(PassRefPtr<PlatformCALayer> rootChild)
98 if (m_rootChild == rootChild)
102 m_rootChild->removeFromSuperlayer();
104 m_rootChild = rootChild;
107 m_layerTreeHost = nullptr;
111 if (!m_layerTreeHost) {
112 m_layerTreeHost = CACFLayerTreeHost::create();
114 m_layerTreeHost->setWindow(m_hwnd);
117 m_layerTreeHost->setRootChildLayer(m_rootChild.get());
118 PlatformCALayer* rootLayer = m_rootChild->rootLayer();
119 CGRect rootBounds = m_rootChild->rootLayer()->bounds();
120 m_rootChild->setFrame(rootBounds);
121 m_rootChild->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack));
123 RetainPtr<CGColorRef> redColor(AdoptCF, CGColorCreateGenericRGB(1, 0, 0, 1));
124 rootLayer->setBackgroundColor(redColor.get());
126 rootLayer->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack));
131 LRESULT MediaPlayerPrivateFullscreenWindow::staticWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
133 LONG_PTR longPtr = GetWindowLongPtr(hWnd, GWLP_USERDATA);
135 if (!longPtr && message == WM_CREATE) {
136 LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
137 longPtr = reinterpret_cast<LONG_PTR>(lpcs->lpCreateParams);
138 ::SetWindowLongPtr(hWnd, GWLP_USERDATA, longPtr);
141 if (MediaPlayerPrivateFullscreenWindow* window = reinterpret_cast<MediaPlayerPrivateFullscreenWindow*>(longPtr))
142 return window->wndProc(hWnd, message, wParam, lParam);
144 return ::DefWindowProc(hWnd, message, wParam, lParam);
147 LRESULT MediaPlayerPrivateFullscreenWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
156 #if USE(ACCELERATED_COMPOSITING)
158 m_layerTreeHost->setWindow(0);
161 case WM_WINDOWPOSCHANGED:
163 LPWINDOWPOS wp = reinterpret_cast<LPWINDOWPOS>(lParam);
164 if (wp->flags & SWP_NOSIZE)
166 #if USE(ACCELERATED_COMPOSITING)
167 if (m_layerTreeHost) {
168 m_layerTreeHost->resize();
169 PlatformCALayer* rootLayer = m_rootChild->rootLayer();
170 CGRect rootBounds = m_rootChild->rootLayer()->bounds();
171 m_rootChild->setFrame(rootBounds);
172 m_rootChild->setNeedsLayout();
178 #if USE(ACCELERATED_COMPOSITING)
179 if (m_layerTreeHost) {
180 m_layerTreeHost->paint();
181 ::ValidateRect(m_hwnd, 0);
186 HDC hdc = ::BeginPaint(m_hwnd, &ps);
187 ::FillRect(hdc, &ps.rcPaint, (HBRUSH)::GetStockObject(BLACK_BRUSH));
188 ::EndPaint(m_hwnd, &ps);
194 HDC context = (HDC)wParam;
195 ::GetClientRect(m_hwnd, &clientRect);
196 ::FillRect(context, &clientRect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
200 lResult = m_client->fullscreenClientWndProc(hWnd, message, wParam, lParam);