| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/child_window_surface_win.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "base/win/wrapped_window_proc.h" |
| 9 #include "content/common/gpu/gpu_channel_manager.h" |
| 10 #include "content/common/gpu/gpu_messages.h" |
| 11 #include "ui/base/win/hidden_window.h" |
| 12 #include "ui/gfx/native_widget_types.h" |
| 13 #include "ui/gl/gl_surface_egl.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace { |
| 18 |
| 19 ATOM g_window_class; |
| 20 |
| 21 LRESULT CALLBACK IntermediateWindowProc(HWND window, |
| 22 UINT message, |
| 23 WPARAM w_param, |
| 24 LPARAM l_param) { |
| 25 switch (message) { |
| 26 case WM_ERASEBKGND: |
| 27 // Prevent windows from erasing the background. |
| 28 return 1; |
| 29 case WM_PAINT: |
| 30 // Do not paint anything. |
| 31 PAINTSTRUCT paint; |
| 32 if (BeginPaint(window, &paint)) { |
| 33 // DirectComposition composites with the contents under the SwapChain, |
| 34 // so ensure that's cleared. |
| 35 if (!IsRectEmpty(&paint.rcPaint)) { |
| 36 FillRect(paint.hdc, &paint.rcPaint, |
| 37 (HBRUSH)GetStockObject(BLACK_BRUSH)); |
| 38 } |
| 39 EndPaint(window, &paint); |
| 40 } |
| 41 return 0; |
| 42 default: |
| 43 return DefWindowProc(window, message, w_param, l_param); |
| 44 } |
| 45 } |
| 46 |
| 47 void InitializeWindowClass() { |
| 48 if (g_window_class) |
| 49 return; |
| 50 |
| 51 WNDCLASSEX intermediate_class; |
| 52 base::win::InitializeWindowClass( |
| 53 L"Intermediate D3D Window", |
| 54 &base::win::WrappedWindowProc<IntermediateWindowProc>, CS_OWNDC, 0, 0, |
| 55 nullptr, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)), nullptr, |
| 56 nullptr, nullptr, &intermediate_class); |
| 57 g_window_class = RegisterClassEx(&intermediate_class); |
| 58 if (!g_window_class) { |
| 59 LOG(ERROR) << "RegisterClass failed."; |
| 60 return; |
| 61 } |
| 62 } |
| 63 } |
| 64 |
| 65 ChildWindowSurfaceWin::ChildWindowSurfaceWin(GpuChannelManager* manager, |
| 66 HWND parent_window) |
| 67 : gfx::NativeViewGLSurfaceEGL(0), |
| 68 parent_window_(parent_window), |
| 69 manager_(manager) { |
| 70 // Don't use EGL_ANGLE_window_fixed_size so that we can avoid recreating the |
| 71 // window surface, which can cause flicker on DirectComposition. |
| 72 enable_fixed_size_angle_ = false; |
| 73 } |
| 74 |
| 75 bool ChildWindowSurfaceWin::InitializeNativeWindow() { |
| 76 if (window_) |
| 77 return true; |
| 78 InitializeWindowClass(); |
| 79 DCHECK(g_window_class); |
| 80 |
| 81 RECT windowRect; |
| 82 GetClientRect(parent_window_, &windowRect); |
| 83 |
| 84 window_ = CreateWindowEx( |
| 85 WS_EX_NOPARENTNOTIFY, reinterpret_cast<wchar_t*>(g_window_class), L"", |
| 86 WS_CHILDWINDOW | WS_DISABLED | WS_VISIBLE, 0, 0, |
| 87 windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, |
| 88 ui::GetHiddenWindow(), NULL, NULL, NULL); |
| 89 manager_->Send(new GpuHostMsg_AcceleratedSurfaceCreatedChildWindow( |
| 90 parent_window_, window_)); |
| 91 return true; |
| 92 } |
| 93 |
| 94 bool ChildWindowSurfaceWin::Resize(const gfx::Size& size, |
| 95 float scale_factor, |
| 96 bool has_alpha) { |
| 97 if (!SupportsPostSubBuffer()) { |
| 98 if (!MoveWindow(window_, 0, 0, size.width(), size.height(), FALSE)) { |
| 99 return false; |
| 100 } |
| 101 return gfx::NativeViewGLSurfaceEGL::Resize(size, scale_factor, has_alpha); |
| 102 } else { |
| 103 if (size == GetSize() && has_alpha == alpha_) |
| 104 return true; |
| 105 |
| 106 alpha_ = has_alpha; |
| 107 size_ = size; |
| 108 if (!MoveWindow(window_, 0, 0, size.width(), size.height(), FALSE)) { |
| 109 return false; |
| 110 } |
| 111 // A 0-size PostSubBuffer doesn't swap but forces the swap chain to resize |
| 112 // to match the window. |
| 113 PostSubBuffer(0, 0, 0, 0); |
| 114 return true; |
| 115 } |
| 116 } |
| 117 |
| 118 ChildWindowSurfaceWin::~ChildWindowSurfaceWin() { |
| 119 DestroyWindow(window_); |
| 120 } |
| 121 |
| 122 } // namespace content |
| OLD | NEW |