Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: media/video/capture/screen/mac/desktop_configuration.mm

Issue 12221103: Fix ScreenCapturerMac handling of secondary configurations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/video/capture/screen/mac/desktop_configuration.h" 5 #include "media/video/capture/screen/mac/desktop_configuration.h"
6 6
7 #include <Cocoa/Cocoa.h> 7 #include <Cocoa/Cocoa.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "skia/ext/skia_utils_mac.h" 10 #include "skia/ext/skia_utils_mac.h"
11 11
12 #if !defined(MAC_OS_X_VERSION_10_7) || \ 12 #if !defined(MAC_OS_X_VERSION_10_7) || \
13 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 13 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
14 14
15 @interface NSScreen (LionAPI) 15 @interface NSScreen (LionAPI)
16 - (CGFloat)backingScaleFactor; 16 - (CGFloat)backingScaleFactor;
17 - (NSRect)convertRectToBacking:(NSRect)aRect; 17 - (NSRect)convertRectToBacking:(NSRect)aRect;
18 @end 18 @end
19 19
20 #endif // 10.7 20 #endif // 10.7
21 21
22 namespace media { 22 namespace media {
23 23
24 MacDisplayConfiguration::MacDisplayConfiguration() 24 namespace {
25 : id(0),
26 bounds(SkIRect::MakeEmpty()),
27 pixel_bounds(SkIRect::MakeEmpty()),
28 dip_to_pixel_scale(1.0f) {
29 }
30 25
31 static SkIRect NSRectToSkIRect(const NSRect& ns_rect) { 26 SkIRect NSRectToSkIRect(const NSRect& ns_rect) {
32 SkIRect result; 27 SkIRect result;
33 gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result); 28 gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result);
34 return result; 29 return result;
35 } 30 }
36 31
37 static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { 32 // Inverts the position of |rect| from bottom-up coordinates to top-down,
33 // relative to |bounds|.
34 void InvertRectYOrigin(const SkIRect& bounds, SkIRect* rect) {
35 DCHECK_EQ(0, bounds.top());
36 rect->setXYWH(rect->x(), bounds.bottom() - rect->bottom(),
37 rect->width(), rect->height());
38 }
39
40 MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
38 MacDisplayConfiguration display_config; 41 MacDisplayConfiguration display_config;
39 42
40 // Fetch the NSScreenNumber, which is also the CGDirectDisplayID. 43 // Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
41 NSDictionary* device_description = [screen deviceDescription]; 44 NSDictionary* device_description = [screen deviceDescription];
42 display_config.id = static_cast<CGDirectDisplayID>( 45 display_config.id = static_cast<CGDirectDisplayID>(
43 [[device_description objectForKey:@"NSScreenNumber"] intValue]); 46 [[device_description objectForKey:@"NSScreenNumber"] intValue]);
44 47
45 // Determine the display's logical & physical dimensions. 48 // Determine the display's logical & physical dimensions.
46 NSRect ns_bounds = [screen frame]; 49 NSRect ns_bounds = [screen frame];
47 display_config.bounds = NSRectToSkIRect(ns_bounds); 50 display_config.bounds = NSRectToSkIRect(ns_bounds);
48 51
49 // If the host is running Mac OS X 10.7+ or later, query the scaling factor 52 // If the host is running Mac OS X 10.7+ or later, query the scaling factor
50 // between logical and physical (aka "backing") pixels, otherwise assume 1:1. 53 // between logical and physical (aka "backing") pixels, otherwise assume 1:1.
51 if ([screen respondsToSelector:@selector(backingScaleFactor)] && 54 if ([screen respondsToSelector:@selector(backingScaleFactor)] &&
52 [screen respondsToSelector:@selector(convertRectToBacking:)]) { 55 [screen respondsToSelector:@selector(convertRectToBacking:)]) {
53 display_config.dip_to_pixel_scale = [screen backingScaleFactor]; 56 display_config.dip_to_pixel_scale = [screen backingScaleFactor];
54 NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds]; 57 NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds];
55 display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds); 58 display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds);
56 } else { 59 } else {
57 display_config.pixel_bounds = display_config.bounds; 60 display_config.pixel_bounds = display_config.bounds;
58 } 61 }
59 62
60 return display_config; 63 return display_config;
61 } 64 }
62 65
66 } // namespace
67
68 MacDisplayConfiguration::MacDisplayConfiguration()
69 : id(0),
70 bounds(SkIRect::MakeEmpty()),
71 pixel_bounds(SkIRect::MakeEmpty()),
72 dip_to_pixel_scale(1.0f) {
73 }
74
63 MacDesktopConfiguration::MacDesktopConfiguration() 75 MacDesktopConfiguration::MacDesktopConfiguration()
64 : bounds(SkIRect::MakeEmpty()), 76 : bounds(SkIRect::MakeEmpty()),
65 pixel_bounds(SkIRect::MakeEmpty()), 77 pixel_bounds(SkIRect::MakeEmpty()),
66 dip_to_pixel_scale(1.0f) { 78 dip_to_pixel_scale(1.0f) {
67 } 79 }
68 80
69 MacDesktopConfiguration::~MacDesktopConfiguration() { 81 MacDesktopConfiguration::~MacDesktopConfiguration() {
70 } 82 }
71 83
72 // static 84 // static
73 MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { 85 MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) {
74 MacDesktopConfiguration desktop_config; 86 MacDesktopConfiguration desktop_config;
75 87
76 NSArray* screens = [NSScreen screens]; 88 NSArray* screens = [NSScreen screens];
77 CHECK(screens != NULL); 89 CHECK(screens != NULL);
78 90
79 // Iterator over the monitors, adding the primary monitor and monitors whose 91 // Iterator over the monitors, adding the primary monitor and monitors whose
80 // DPI match that of the primary monitor. 92 // DPI match that of the primary monitor.
81 for (NSUInteger i = 0; i < [screens count]; ++i) { 93 for (NSUInteger i = 0; i < [screens count]; ++i) {
82 MacDisplayConfiguration display_config 94 MacDisplayConfiguration display_config
83 = GetConfigurationForScreen([screens objectAtIndex: i]); 95 = GetConfigurationForScreen([screens objectAtIndex: i]);
84 96
85 // Handling mixed-DPI is hard, so we only return displays that match the 97 // Handling mixed-DPI is hard, so we only return displays that match the
86 // "primary" display's DPI. The primary display is always the first in the 98 // "primary" display's DPI. The primary display is always the first in the
87 // list returned by [NSScreen screens]. 99 // list returned by [NSScreen screens].
88 if (i == 0) { 100 if (i == 0) {
89 desktop_config.dip_to_pixel_scale = display_config.dip_to_pixel_scale; 101 desktop_config.dip_to_pixel_scale = display_config.dip_to_pixel_scale;
90 } else if (desktop_config.dip_to_pixel_scale != 102 } else if (desktop_config.dip_to_pixel_scale !=
91 display_config.dip_to_pixel_scale) { 103 display_config.dip_to_pixel_scale) {
92 continue; 104 continue;
93 } 105 }
94 106
107 // Cocoa uses bottom-up coordinates, so if the caller wants top-down then
108 // we need to invert the positions of secondary monitors relative to the
109 // primary one (the primary monitor's position is (0,0) in both systems).
110 if (i > 0 && origin == TopLeftOrigin) {
111 InvertRectYOrigin(desktop_config.displays[0].bounds,
112 &display_config.bounds);
113 InvertRectYOrigin(desktop_config.displays[0].pixel_bounds,
114 &display_config.pixel_bounds);
115 }
116
95 // Add the display to the configuration. 117 // Add the display to the configuration.
96 desktop_config.displays.push_back(display_config); 118 desktop_config.displays.push_back(display_config);
97 119
98 // Update the desktop bounds to account for this display. 120 // Update the desktop bounds to account for this display.
99 desktop_config.bounds.join(display_config.bounds); 121 desktop_config.bounds.join(display_config.bounds);
100 desktop_config.pixel_bounds.join(display_config.pixel_bounds); 122 desktop_config.pixel_bounds.join(display_config.pixel_bounds);
101 } 123 }
102 124
103 return desktop_config; 125 return desktop_config;
104 } 126 }
105 127
106 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/screen/mac/desktop_configuration.h ('k') | media/video/capture/screen/screen_capturer_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698