1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsScreenCocoa.h"
7 #include "nsObjCExceptions.h"
8 #include "nsCocoaUtils.h"
10 nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
12 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
14 mScreen = [screen retain];
16 NS_OBJC_END_TRY_ABORT_BLOCK;
19 nsScreenCocoa::~nsScreenCocoa ()
21 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
25 NS_OBJC_END_TRY_ABORT_BLOCK;
29 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
31 NSRect frame = [mScreen frame];
33 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
38 *outHeight = r.height;
44 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
46 NSRect frame = [mScreen visibleFrame];
48 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
53 *outHeight = r.height;
59 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
61 NSRect frame = [mScreen frame];
63 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
68 *outHeight = r.height;
74 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
76 NSRect frame = [mScreen visibleFrame];
78 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
83 *outHeight = r.height;
89 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
91 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
93 NSWindowDepth depth = [mScreen depth];
94 int bpp = NSBitsPerPixelFromDepth(depth);
99 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
103 nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
105 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
107 NSWindowDepth depth = [mScreen depth];
108 int bpp = NSBitsPerPixelFromDepth (depth);
113 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
117 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
119 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
121 *aContentsScaleFactor = (double) BackingScaleFactor();
124 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
128 nsScreenCocoa::BackingScaleFactor()
130 return nsCocoaUtils::GetBackingScaleFactor(mScreen);