Bumping manifests a=b2g-bump
[gecko.git] / widget / cocoa / nsScreenCocoa.mm
blob5a9ccb6e26cb8a0ee35a46f5cbc1dba662566e99
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];
17   mId = ++sScreenId;
19   NS_OBJC_END_TRY_ABORT_BLOCK;
22 nsScreenCocoa::~nsScreenCocoa ()
24   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
26   [mScreen release];
28   NS_OBJC_END_TRY_ABORT_BLOCK;
31 NS_IMETHODIMP
32 nsScreenCocoa::GetId(uint32_t *outId)
34   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
36   *outId = mId;
37   return NS_OK;
39   NS_OBJC_END_TRY_ABORT_BLOCK;
42 NS_IMETHODIMP
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());
49   *outX = r.x;
50   *outY = r.y;
51   *outWidth = r.width;
52   *outHeight = r.height;
54   return NS_OK;
57 NS_IMETHODIMP
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());
64   *outX = r.x;
65   *outY = r.y;
66   *outWidth = r.width;
67   *outHeight = r.height;
69   return NS_OK;
72 NS_IMETHODIMP
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);
79   *outX = r.x;
80   *outY = r.y;
81   *outWidth = r.width;
82   *outHeight = r.height;
84   return NS_OK;
87 NS_IMETHODIMP
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);
94   *outX = r.x;
95   *outY = r.y;
96   *outWidth = r.width;
97   *outHeight = r.height;
99   return NS_OK;
102 NS_IMETHODIMP
103 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
105   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
107   NSWindowDepth depth = [mScreen depth];
108   int bpp = NSBitsPerPixelFromDepth(depth);
110   *aPixelDepth = bpp;
111   return NS_OK;
113   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
116 NS_IMETHODIMP
117 nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
119   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
121   NSWindowDepth depth = [mScreen depth];
122   int bpp = NSBitsPerPixelFromDepth (depth);
124   *aColorDepth = bpp;
125   return NS_OK;
127   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
130 NS_IMETHODIMP
131 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
133   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
135   *aContentsScaleFactor = (double) BackingScaleFactor();
136   return NS_OK;
138   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
141 CGFloat
142 nsScreenCocoa::BackingScaleFactor()
144   return nsCocoaUtils::GetBackingScaleFactor(mScreen);