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 static uint32_t sScreenId = 0;
12 nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
14 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
16 mScreen = [screen retain];
19 NS_OBJC_END_TRY_ABORT_BLOCK;
22 nsScreenCocoa::~nsScreenCocoa ()
24 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
28 NS_OBJC_END_TRY_ABORT_BLOCK;
32 nsScreenCocoa::GetId(uint32_t *outId)
34 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
39 NS_OBJC_END_TRY_ABORT_BLOCK;
43 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
45 NSRect frame = [mScreen frame];
47 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
52 *outHeight = r.height;
58 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
60 NSRect frame = [mScreen visibleFrame];
62 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
67 *outHeight = r.height;
73 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
75 NSRect frame = [mScreen frame];
77 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
82 *outHeight = r.height;
88 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
90 NSRect frame = [mScreen visibleFrame];
92 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
97 *outHeight = r.height;
103 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
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::GetColorDepth(int32_t *aColorDepth)
119 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
121 NSWindowDepth depth = [mScreen depth];
122 int bpp = NSBitsPerPixelFromDepth (depth);
127 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
131 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
133 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
135 *aContentsScaleFactor = (double) BackingScaleFactor();
138 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
142 nsScreenCocoa::BackingScaleFactor()
144 return nsCocoaUtils::GetBackingScaleFactor(mScreen);