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/. */ 5 6#include "nsScreenCocoa.h" 7#include "nsObjCExceptions.h" 8#include "nsCocoaUtils.h" 9 10static uint32_t sScreenId = 0; 11 12nsScreenCocoa::nsScreenCocoa (NSScreen *screen) 13{ 14 NS_OBJC_BEGIN_TRY_ABORT_BLOCK; 15 16 mScreen = [screen retain]; 17 mId = ++sScreenId; 18 19 NS_OBJC_END_TRY_ABORT_BLOCK; 20} 21 22nsScreenCocoa::~nsScreenCocoa () 23{ 24 NS_OBJC_BEGIN_TRY_ABORT_BLOCK; 25 26 [mScreen release]; 27 28 NS_OBJC_END_TRY_ABORT_BLOCK; 29} 30 31NS_IMETHODIMP 32nsScreenCocoa::GetId(uint32_t *outId) 33{ 34 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 35 36 *outId = mId; 37 return NS_OK; 38 39 NS_OBJC_END_TRY_ABORT_BLOCK; 40} 41 42NS_IMETHODIMP 43nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 44{ 45 NSRect frame = [mScreen frame]; 46 47 mozilla::LayoutDeviceIntRect r = 48 nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); 49 50 *outX = r.x; 51 *outY = r.y; 52 *outWidth = r.width; 53 *outHeight = r.height; 54 55 return NS_OK; 56} 57 58NS_IMETHODIMP 59nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 60{ 61 NSRect frame = [mScreen visibleFrame]; 62 63 mozilla::LayoutDeviceIntRect r = 64 nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); 65 66 *outX = r.x; 67 *outY = r.y; 68 *outWidth = r.width; 69 *outHeight = r.height; 70 71 return NS_OK; 72} 73 74NS_IMETHODIMP 75nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 76{ 77 NSRect frame = [mScreen frame]; 78 79 mozilla::DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); 80 81 *outX = r.x; 82 *outY = r.y; 83 *outWidth = r.width; 84 *outHeight = r.height; 85 86 return NS_OK; 87} 88 89NS_IMETHODIMP 90nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 91{ 92 NSRect frame = [mScreen visibleFrame]; 93 94 mozilla::DesktopIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); 95 96 *outX = r.x; 97 *outY = r.y; 98 *outWidth = r.width; 99 *outHeight = r.height; 100 101 return NS_OK; 102} 103 104NS_IMETHODIMP 105nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth) 106{ 107 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 108 109 NSWindowDepth depth = [mScreen depth]; 110 int bpp = NSBitsPerPixelFromDepth(depth); 111 112 *aPixelDepth = bpp; 113 return NS_OK; 114 115 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 116} 117 118NS_IMETHODIMP 119nsScreenCocoa::GetColorDepth(int32_t *aColorDepth) 120{ 121 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 122 123 NSWindowDepth depth = [mScreen depth]; 124 int bpp = NSBitsPerPixelFromDepth (depth); 125 126 *aColorDepth = bpp; 127 return NS_OK; 128 129 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 130} 131 132NS_IMETHODIMP 133nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor) 134{ 135 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 136 137 *aContentsScaleFactor = (double) BackingScaleFactor(); 138 return NS_OK; 139 140 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 141} 142 143CGFloat 144nsScreenCocoa::BackingScaleFactor() 145{ 146 return nsCocoaUtils::GetBackingScaleFactor(mScreen); 147} 148