/src/3rdparty/webkit/Source/WebCore/platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 205 lines · 153 code · 28 blank · 24 comment · 20 complexity · dc89f5aec2925ce6cbecc68d056724fe MD5 · raw file

  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. #include "config.h"
  26. #include "MediaPlayerPrivateFullscreenWindow.h"
  27. #include "IntRect.h"
  28. #include "WebCoreInstanceHandle.h"
  29. #include <windows.h>
  30. #if USE(CG)
  31. #include <CoreGraphics/CGColor.h>
  32. #endif
  33. #if USE(ACCELERATED_COMPOSITING)
  34. #include "CACFLayerTreeHost.h"
  35. #include "PlatformCALayer.h"
  36. #endif
  37. namespace WebCore {
  38. MediaPlayerPrivateFullscreenWindow::MediaPlayerPrivateFullscreenWindow(MediaPlayerPrivateFullscreenClient* client)
  39. : m_client(client)
  40. , m_hwnd(0)
  41. {
  42. }
  43. MediaPlayerPrivateFullscreenWindow::~MediaPlayerPrivateFullscreenWindow()
  44. {
  45. if (!m_hwnd)
  46. return;
  47. ::DestroyWindow(m_hwnd);
  48. ASSERT(!m_hwnd);
  49. }
  50. void MediaPlayerPrivateFullscreenWindow::createWindow(HWND parentHwnd)
  51. {
  52. static ATOM windowAtom;
  53. static LPCWSTR windowClassName = L"MediaPlayerPrivateFullscreenWindowClass";
  54. if (!windowAtom) {
  55. WNDCLASSEX wcex = {0};
  56. wcex.cbSize = sizeof(WNDCLASSEX);
  57. wcex.style = CS_HREDRAW | CS_VREDRAW;
  58. wcex.lpfnWndProc = staticWndProc;
  59. wcex.hInstance = instanceHandle();
  60. wcex.lpszClassName = windowClassName;
  61. windowAtom = ::RegisterClassEx(&wcex);
  62. }
  63. ASSERT(!m_hwnd);
  64. MONITORINFO mi = {0};
  65. mi.cbSize = sizeof(MONITORINFO);
  66. if (!GetMonitorInfo(MonitorFromWindow(parentHwnd, MONITOR_DEFAULTTONEAREST), &mi))
  67. return;
  68. IntRect monitorRect = mi.rcMonitor;
  69. ::CreateWindowExW(WS_EX_TOOLWINDOW, windowClassName, L"", WS_POPUP,
  70. monitorRect.x(), monitorRect.y(), monitorRect.width(), monitorRect.height(),
  71. parentHwnd, 0, WebCore::instanceHandle(), this);
  72. ASSERT(IsWindow(m_hwnd));
  73. #if USE(ACCELERATED_COMPOSITING)
  74. if (m_layerTreeHost)
  75. m_layerTreeHost->setWindow(m_hwnd);
  76. #endif
  77. ::SetFocus(m_hwnd);
  78. }
  79. #if USE(ACCELERATED_COMPOSITING)
  80. void MediaPlayerPrivateFullscreenWindow::setRootChildLayer(PassRefPtr<PlatformCALayer> rootChild)
  81. {
  82. if (m_rootChild == rootChild)
  83. return;
  84. if (m_rootChild)
  85. m_rootChild->removeFromSuperlayer();
  86. m_rootChild = rootChild;
  87. if (!m_rootChild) {
  88. m_layerTreeHost = nullptr;
  89. return;
  90. }
  91. if (!m_layerTreeHost) {
  92. m_layerTreeHost = CACFLayerTreeHost::create();
  93. if (m_hwnd)
  94. m_layerTreeHost->setWindow(m_hwnd);
  95. }
  96. m_layerTreeHost->setRootChildLayer(m_rootChild.get());
  97. PlatformCALayer* rootLayer = m_rootChild->rootLayer();
  98. CGRect rootBounds = m_rootChild->rootLayer()->bounds();
  99. m_rootChild->setFrame(rootBounds);
  100. m_rootChild->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack));
  101. #ifndef NDEBUG
  102. RetainPtr<CGColorRef> redColor(AdoptCF, CGColorCreateGenericRGB(1, 0, 0, 1));
  103. rootLayer->setBackgroundColor(redColor.get());
  104. #else
  105. rootLayer->setBackgroundColor(CGColorGetConstantColor(kCGColorBlack));
  106. #endif
  107. }
  108. #endif
  109. LRESULT MediaPlayerPrivateFullscreenWindow::staticWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  110. {
  111. LONG_PTR longPtr = GetWindowLongPtr(hWnd, GWLP_USERDATA);
  112. if (!longPtr && message == WM_CREATE) {
  113. LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
  114. longPtr = reinterpret_cast<LONG_PTR>(lpcs->lpCreateParams);
  115. ::SetWindowLongPtr(hWnd, GWLP_USERDATA, longPtr);
  116. }
  117. if (MediaPlayerPrivateFullscreenWindow* window = reinterpret_cast<MediaPlayerPrivateFullscreenWindow*>(longPtr))
  118. return window->wndProc(hWnd, message, wParam, lParam);
  119. return ::DefWindowProc(hWnd, message, wParam, lParam);
  120. }
  121. LRESULT MediaPlayerPrivateFullscreenWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  122. {
  123. LRESULT lResult = 0;
  124. switch (message) {
  125. case WM_CREATE:
  126. m_hwnd = hWnd;
  127. break;
  128. case WM_DESTROY:
  129. m_hwnd = 0;
  130. #if USE(ACCELERATED_COMPOSITING)
  131. if (m_layerTreeHost)
  132. m_layerTreeHost->setWindow(0);
  133. #endif
  134. break;
  135. case WM_WINDOWPOSCHANGED:
  136. {
  137. LPWINDOWPOS wp = reinterpret_cast<LPWINDOWPOS>(lParam);
  138. if (wp->flags & SWP_NOSIZE)
  139. break;
  140. #if USE(ACCELERATED_COMPOSITING)
  141. if (m_layerTreeHost) {
  142. m_layerTreeHost->resize();
  143. PlatformCALayer* rootLayer = m_rootChild->rootLayer();
  144. CGRect rootBounds = m_rootChild->rootLayer()->bounds();
  145. m_rootChild->setFrame(rootBounds);
  146. m_rootChild->setNeedsLayout();
  147. }
  148. #endif
  149. }
  150. break;
  151. case WM_PAINT:
  152. #if USE(ACCELERATED_COMPOSITING)
  153. if (m_layerTreeHost) {
  154. m_layerTreeHost->paint();
  155. ::ValidateRect(m_hwnd, 0);
  156. } else
  157. #endif
  158. {
  159. PAINTSTRUCT ps;
  160. HDC hdc = ::BeginPaint(m_hwnd, &ps);
  161. ::FillRect(hdc, &ps.rcPaint, (HBRUSH)::GetStockObject(BLACK_BRUSH));
  162. ::EndPaint(m_hwnd, &ps);
  163. }
  164. break;
  165. case WM_PRINTCLIENT:
  166. {
  167. RECT clientRect;
  168. HDC context = (HDC)wParam;
  169. ::GetClientRect(m_hwnd, &clientRect);
  170. ::FillRect(context, &clientRect, (HBRUSH)::GetStockObject(BLACK_BRUSH));
  171. }
  172. }
  173. if (m_client)
  174. lResult = m_client->fullscreenClientWndProc(hWnd, message, wParam, lParam);
  175. return lResult;
  176. }
  177. }