33
33
// Private class for ModalHostingWindow window that doesn't work with drawViewHierarchyInRect.
34
34
static Class gUIModalItemHostingWindowClass ;
35
35
36
- /* *
37
- * @return A current screen if the window exists and @c nil if it does not.
38
- */
39
- static UIScreen *MainScreen (void ) {
40
- UIScreen *mainScreen = [GREYUILibUtils screen ];
41
- if (!mainScreen || CGRectEqualToRect (mainScreen.bounds , CGRectNull)) {
42
- return nil ;
43
- } else {
44
- return mainScreen;
45
- }
46
- }
47
-
48
36
@implementation GREYScreenshotter
49
37
50
38
+ (void )initialize {
@@ -60,8 +48,7 @@ + (void)drawScreenInContext:(CGContextRef)bitmapContextRef
60
48
withStatusBar : (BOOL )includeStatusBar {
61
49
GREYFatalAssertWithMessage (CGBitmapContextGetBitmapInfo (bitmapContextRef) != 0 ,
62
50
@" The context ref must point to a CGBitmapContext." );
63
- UIScreen *mainScreen = MainScreen ();
64
- if (!mainScreen) return ;
51
+ UIScreen *mainScreen = [GREYUILibUtils screen ];
65
52
CGRect screenRect = mainScreen.bounds ;
66
53
[self drawScreenInContext: bitmapContextRef
67
54
afterScreenUpdates: afterUpdates
@@ -89,9 +76,7 @@ + (UIImage *)snapshotElement:(id)element {
89
76
? (UIView *)element
90
77
: [element grey_viewContainingSelf ];
91
78
92
- UIScreen *mainScreen = MainScreen ();
93
- if (!mainScreen) return nil ;
94
- UIGraphicsBeginImageContextWithOptions (elementAXFrame.size , NO , mainScreen.scale );
79
+ UIGraphicsBeginImageContextWithOptions (elementAXFrame.size , NO , [GREYUILibUtils screen ].scale );
95
80
[self drawViewInContext: UIGraphicsGetCurrentContext ()
96
81
view: viewToSnapshot
97
82
bounds: elementAXFrame
@@ -111,9 +96,7 @@ + (NSString *)saveImageAsPNG:(UIImage *)image
111
96
112
97
+ (UIImage *)grey_takeScreenshotAfterScreenUpdates : (BOOL )afterScreenUpdates
113
98
withStatusBar : (BOOL )includeStatusBar {
114
- UIScreen *mainScreen = MainScreen ();
115
- if (!mainScreen) return nil ;
116
- CGRect screenRect = mainScreen.bounds ;
99
+ CGRect screenRect = [GREYUILibUtils screen ].bounds ;
117
100
return [self grey_takeScreenshotAfterScreenUpdates: afterScreenUpdates
118
101
inScreenRect: screenRect
119
102
withStatusBar: includeStatusBar];
@@ -169,8 +152,8 @@ + (void)drawViewInContext:(CGContextRef)bitmapContextRef
169
152
view : (UIView *)view
170
153
bounds : (CGRect)boundsInScreenRect
171
154
afterScreenUpdates : (BOOL )afterScreenUpdates {
172
- UIScreen *mainScreen = MainScreen () ;
173
- if (!mainScreen) return ;
155
+ UIScreen *mainScreen = [GREYUILibUtils screen ] ;
156
+
174
157
// The bitmap context width and height are scaled, so we need to undo the scale adjustment.
175
158
CGFloat scale = mainScreen.scale ;
176
159
CGFloat contextWidth = CGBitmapContextGetWidth (bitmapContextRef) / scale;
0 commit comments