|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #define MOZ_FATAL_ASSERTIONS_FOR_THREAD_SAFETY |
|
9 |
|
10 #include "nsBaseScreen.h" |
|
11 |
|
12 NS_IMPL_ISUPPORTS(nsBaseScreen, nsIScreen) |
|
13 |
|
14 nsBaseScreen::nsBaseScreen() |
|
15 { |
|
16 for (uint32_t i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++) |
|
17 mBrightnessLocks[i] = 0; |
|
18 } |
|
19 |
|
20 nsBaseScreen::~nsBaseScreen() { } |
|
21 |
|
22 NS_IMETHODIMP |
|
23 nsBaseScreen::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, |
|
24 int32_t *outWidth, int32_t *outHeight) |
|
25 { |
|
26 return GetRect(outLeft, outTop, outWidth, outHeight); |
|
27 } |
|
28 |
|
29 NS_IMETHODIMP |
|
30 nsBaseScreen::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, |
|
31 int32_t *outWidth, int32_t *outHeight) |
|
32 { |
|
33 return GetAvailRect(outLeft, outTop, outWidth, outHeight); |
|
34 } |
|
35 |
|
36 NS_IMETHODIMP |
|
37 nsBaseScreen::LockMinimumBrightness(uint32_t aBrightness) |
|
38 { |
|
39 NS_ABORT_IF_FALSE( |
|
40 aBrightness < nsIScreen::BRIGHTNESS_LEVELS, |
|
41 "Invalid brightness level to lock"); |
|
42 mBrightnessLocks[aBrightness]++; |
|
43 NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0, |
|
44 "Overflow after locking brightness level"); |
|
45 |
|
46 CheckMinimumBrightness(); |
|
47 |
|
48 return NS_OK; |
|
49 } |
|
50 |
|
51 NS_IMETHODIMP |
|
52 nsBaseScreen::UnlockMinimumBrightness(uint32_t aBrightness) |
|
53 { |
|
54 NS_ABORT_IF_FALSE( |
|
55 aBrightness < nsIScreen::BRIGHTNESS_LEVELS, |
|
56 "Invalid brightness level to lock"); |
|
57 NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0, |
|
58 "Unlocking a brightness level with no corresponding lock"); |
|
59 mBrightnessLocks[aBrightness]--; |
|
60 |
|
61 CheckMinimumBrightness(); |
|
62 |
|
63 return NS_OK; |
|
64 } |
|
65 |
|
66 void |
|
67 nsBaseScreen::CheckMinimumBrightness() |
|
68 { |
|
69 uint32_t brightness = nsIScreen::BRIGHTNESS_LEVELS; |
|
70 for (int32_t i = nsIScreen::BRIGHTNESS_LEVELS - 1; i >=0; i--) { |
|
71 if (mBrightnessLocks[i] > 0) { |
|
72 brightness = i; |
|
73 break; |
|
74 } |
|
75 } |
|
76 |
|
77 ApplyMinimumBrightness(brightness); |
|
78 } |
|
79 |
|
80 NS_IMETHODIMP |
|
81 nsBaseScreen::GetContentsScaleFactor(double* aContentsScaleFactor) |
|
82 { |
|
83 *aContentsScaleFactor = 1.0; |
|
84 return NS_OK; |
|
85 } |