• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h"
12 
13 namespace webrtc {
14 
15 bool
GetCroppedWindowRect(HWND window,DesktopRect * cropped_rect,DesktopRect * original_rect)16 GetCroppedWindowRect(HWND window,
17                      DesktopRect* cropped_rect,
18                      DesktopRect* original_rect) {
19   RECT rect;
20   if (!GetWindowRect(window, &rect)) {
21     return false;
22   }
23   WINDOWPLACEMENT window_placement;
24   window_placement.length = sizeof(window_placement);
25   if (!GetWindowPlacement(window, &window_placement)) {
26     return false;
27   }
28 
29   *original_rect = DesktopRect::MakeLTRB(
30       rect.left, rect.top, rect.right, rect.bottom);
31 
32   if (window_placement.showCmd == SW_SHOWMAXIMIZED) {
33     DesktopSize border = DesktopSize(GetSystemMetrics(SM_CXSIZEFRAME),
34                                      GetSystemMetrics(SM_CYSIZEFRAME));
35     *cropped_rect = DesktopRect::MakeLTRB(
36         rect.left + border.width(),
37         rect.top,
38         rect.right - border.width(),
39         rect.bottom - border.height());
40   } else {
41     *cropped_rect = *original_rect;
42   }
43   return true;
44 }
45 
AeroChecker()46 AeroChecker::AeroChecker() : dwmapi_library_(nullptr), func_(nullptr) {
47   // Try to load dwmapi.dll dynamically since it is not available on XP.
48   dwmapi_library_ = LoadLibrary(L"dwmapi.dll");
49   if (dwmapi_library_) {
50     func_ = reinterpret_cast<DwmIsCompositionEnabledFunc>(
51         GetProcAddress(dwmapi_library_, "DwmIsCompositionEnabled"));
52   }
53 }
54 
~AeroChecker()55 AeroChecker::~AeroChecker() {
56   if (dwmapi_library_) {
57     FreeLibrary(dwmapi_library_);
58   }
59 }
60 
IsAeroEnabled()61 bool AeroChecker::IsAeroEnabled() {
62   BOOL result = FALSE;
63   if (func_) {
64     func_(&result);
65   }
66   return result != FALSE;
67 }
68 
69 }  // namespace webrtc
70