michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #define MOZ_FATAL_ASSERTIONS_FOR_THREAD_SAFETY michael@0: michael@0: #include "nsBaseScreen.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(nsBaseScreen, nsIScreen) michael@0: michael@0: nsBaseScreen::nsBaseScreen() michael@0: { michael@0: for (uint32_t i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++) michael@0: mBrightnessLocks[i] = 0; michael@0: } michael@0: michael@0: nsBaseScreen::~nsBaseScreen() { } michael@0: michael@0: NS_IMETHODIMP michael@0: nsBaseScreen::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, michael@0: int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: return GetRect(outLeft, outTop, outWidth, outHeight); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsBaseScreen::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, michael@0: int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: return GetAvailRect(outLeft, outTop, outWidth, outHeight); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsBaseScreen::LockMinimumBrightness(uint32_t aBrightness) michael@0: { michael@0: NS_ABORT_IF_FALSE( michael@0: aBrightness < nsIScreen::BRIGHTNESS_LEVELS, michael@0: "Invalid brightness level to lock"); michael@0: mBrightnessLocks[aBrightness]++; michael@0: NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0, michael@0: "Overflow after locking brightness level"); michael@0: michael@0: CheckMinimumBrightness(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsBaseScreen::UnlockMinimumBrightness(uint32_t aBrightness) michael@0: { michael@0: NS_ABORT_IF_FALSE( michael@0: aBrightness < nsIScreen::BRIGHTNESS_LEVELS, michael@0: "Invalid brightness level to lock"); michael@0: NS_ABORT_IF_FALSE(mBrightnessLocks[aBrightness] > 0, michael@0: "Unlocking a brightness level with no corresponding lock"); michael@0: mBrightnessLocks[aBrightness]--; michael@0: michael@0: CheckMinimumBrightness(); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsBaseScreen::CheckMinimumBrightness() michael@0: { michael@0: uint32_t brightness = nsIScreen::BRIGHTNESS_LEVELS; michael@0: for (int32_t i = nsIScreen::BRIGHTNESS_LEVELS - 1; i >=0; i--) { michael@0: if (mBrightnessLocks[i] > 0) { michael@0: brightness = i; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: ApplyMinimumBrightness(brightness); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsBaseScreen::GetContentsScaleFactor(double* aContentsScaleFactor) michael@0: { michael@0: *aContentsScaleFactor = 1.0; michael@0: return NS_OK; michael@0: }