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

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: 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 top- to bottom-relative with respect to
33 // the specified |reference| coordinates.
Jamie 2013/02/11 22:12:44 It's not clear to me from this comment what this f
Wez 2013/02/11 22:56:11 Done.
34 void InvertRectYOrigin(const SkIRect& reference, SkIRect* rect) {
35 rect->setXYWH(rect->x(), reference.bottom() - rect->bottom(),
36 rect->width(), rect->height());
37 }
38
39 MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
38 MacDisplayConfiguration display_config; 40 MacDisplayConfiguration display_config;
39 41
40 // Fetch the NSScreenNumber, which is also the CGDirectDisplayID. 42 // Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
41 NSDictionary* device_description = [screen deviceDescription]; 43 NSDictionary* device_description = [screen deviceDescription];
42 display_config.id = static_cast<CGDirectDisplayID>( 44 display_config.id = static_cast<CGDirectDisplayID>(
43 [[device_description objectForKey:@"NSScreenNumber"] intValue]); 45 [[device_description objectForKey:@"NSScreenNumber"] intValue]);
44 46
45 // Determine the display's logical & physical dimensions. 47 // Determine the display's logical & physical dimensions.
46 NSRect ns_bounds = [screen frame]; 48 NSRect ns_bounds = [screen frame];
47 display_config.bounds = NSRectToSkIRect(ns_bounds); 49 display_config.bounds = NSRectToSkIRect(ns_bounds);
48 50
49 // If the host is running Mac OS X 10.7+ or later, query the scaling factor 51 // 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. 52 // between logical and physical (aka "backing") pixels, otherwise assume 1:1.
51 if ([screen respondsToSelector:@selector(backingScaleFactor)] && 53 if ([screen respondsToSelector:@selector(backingScaleFactor)] &&
52 [screen respondsToSelector:@selector(convertRectToBacking:)]) { 54 [screen respondsToSelector:@selector(convertRectToBacking:)]) {
Sergey Ulanov 2013/02/11 22:57:20 nit: this line was indented correctly.
Wez 2013/02/11 23:12:03 Done.
53 display_config.dip_to_pixel_scale = [screen backingScaleFactor]; 55 display_config.dip_to_pixel_scale = [screen backingScaleFactor];
54 NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds]; 56 NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds];
55 display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds); 57 display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds);
56 } else { 58 } else {
57 display_config.pixel_bounds = display_config.bounds; 59 display_config.pixel_bounds = display_config.bounds;
58 } 60 }
59 61
60 return display_config; 62 return display_config;
61 } 63 }
62 64
65 } // namespace
66
67 MacDisplayConfiguration::MacDisplayConfiguration()
68 : id(0),
Sergey Ulanov 2013/02/11 22:57:20 nit: this line should be indented 4 spaces and the
Wez 2013/02/11 23:12:03 Done.
69 bounds(SkIRect::MakeEmpty()),
70 pixel_bounds(SkIRect::MakeEmpty()),
71 dip_to_pixel_scale(1.0f) {
72 }
73
63 MacDesktopConfiguration::MacDesktopConfiguration() 74 MacDesktopConfiguration::MacDesktopConfiguration()
64 : bounds(SkIRect::MakeEmpty()), 75 : bounds(SkIRect::MakeEmpty()),
65 pixel_bounds(SkIRect::MakeEmpty()), 76 pixel_bounds(SkIRect::MakeEmpty()),
66 dip_to_pixel_scale(1.0f) { 77 dip_to_pixel_scale(1.0f) {
67 } 78 }
68 79
69 MacDesktopConfiguration::~MacDesktopConfiguration() { 80 MacDesktopConfiguration::~MacDesktopConfiguration() {
70 } 81 }
71 82
72 // static 83 // static
73 MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { 84 MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) {
74 MacDesktopConfiguration desktop_config; 85 MacDesktopConfiguration desktop_config;
75 86
76 NSArray* screens = [NSScreen screens]; 87 NSArray* screens = [NSScreen screens];
77 CHECK(screens != NULL); 88 CHECK(screens != NULL);
78 89
79 // Iterator over the monitors, adding the primary monitor and monitors whose 90 // Iterator over the monitors, adding the primary monitor and monitors whose
80 // DPI match that of the primary monitor. 91 // DPI match that of the primary monitor.
81 for (NSUInteger i = 0; i < [screens count]; ++i) { 92 for (NSUInteger i = 0; i < [screens count]; ++i) {
82 MacDisplayConfiguration display_config 93 MacDisplayConfiguration display_config
83 = GetConfigurationForScreen([screens objectAtIndex: i]); 94 = GetConfigurationForScreen([screens objectAtIndex: i]);
84 95
85 // Handling mixed-DPI is hard, so we only return displays that match the 96 // 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 97 // "primary" display's DPI. The primary display is always the first in the
87 // list returned by [NSScreen screens]. 98 // list returned by [NSScreen screens].
88 if (i == 0) { 99 if (i == 0) {
89 desktop_config.dip_to_pixel_scale = display_config.dip_to_pixel_scale; 100 desktop_config.dip_to_pixel_scale = display_config.dip_to_pixel_scale;
90 } else if (desktop_config.dip_to_pixel_scale != 101 } else if (desktop_config.dip_to_pixel_scale !=
91 display_config.dip_to_pixel_scale) { 102 display_config.dip_to_pixel_scale) {
92 continue; 103 continue;
93 } 104 }
94 105
106 // Mac uses Cartesian (bottom-left origin) coordinates, so if the caller
107 // wants inverse Cartesian (top-left origin), secondary monitors need
108 // their coordinates adjusting.
Jamie 2013/02/11 22:12:44 Why only secondary monitors?
Wez 2013/02/11 22:56:11 The coordinate space is primary-monitor-relative.
109 if (i > 0 && origin == TopLeftOrigin) {
110 InvertRectYOrigin(desktop_config.displays[0].bounds,
Sergey Ulanov 2013/02/11 22:57:20 This doesn't look right to me. why invert bounds r
Wez 2013/02/11 23:12:03 The first parameter is the coordinate scheme about
Sergey Ulanov 2013/02/11 23:16:02 Ah, I see. Thanks for clarifying.
111 &display_config.bounds);
112 InvertRectYOrigin(desktop_config.displays[0].pixel_bounds,
113 &display_config.pixel_bounds);
114 }
115
95 // Add the display to the configuration. 116 // Add the display to the configuration.
96 desktop_config.displays.push_back(display_config); 117 desktop_config.displays.push_back(display_config);
97 118
98 // Update the desktop bounds to account for this display. 119 // Update the desktop bounds to account for this display.
99 desktop_config.bounds.join(display_config.bounds); 120 desktop_config.bounds.join(display_config.bounds);
100 desktop_config.pixel_bounds.join(display_config.pixel_bounds); 121 desktop_config.pixel_bounds.join(display_config.pixel_bounds);
101 } 122 }
102 123
103 return desktop_config; 124 return desktop_config;
104 } 125 }
105 126
106 } // namespace media 127 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698