nsBaseScreen.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define MOZ_FATAL_ASSERTIONS_FOR_THREAD_SAFETY
  8. #include "nsBaseScreen.h"
  9. NS_IMPL_ISUPPORTS(nsBaseScreen, nsIScreen)
  10. nsBaseScreen::nsBaseScreen()
  11. {
  12. for (uint32_t i = 0; i < nsIScreen::BRIGHTNESS_LEVELS; i++)
  13. mBrightnessLocks[i] = 0;
  14. }
  15. nsBaseScreen::~nsBaseScreen() { }
  16. NS_IMETHODIMP
  17. nsBaseScreen::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
  18. int32_t *outWidth, int32_t *outHeight)
  19. {
  20. return GetRect(outLeft, outTop, outWidth, outHeight);
  21. }
  22. NS_IMETHODIMP
  23. nsBaseScreen::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop,
  24. int32_t *outWidth, int32_t *outHeight)
  25. {
  26. return GetAvailRect(outLeft, outTop, outWidth, outHeight);
  27. }
  28. NS_IMETHODIMP
  29. nsBaseScreen::LockMinimumBrightness(uint32_t aBrightness)
  30. {
  31. MOZ_ASSERT(aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
  32. "Invalid brightness level to lock");
  33. mBrightnessLocks[aBrightness]++;
  34. MOZ_ASSERT(mBrightnessLocks[aBrightness] > 0,
  35. "Overflow after locking brightness level");
  36. CheckMinimumBrightness();
  37. return NS_OK;
  38. }
  39. NS_IMETHODIMP
  40. nsBaseScreen::UnlockMinimumBrightness(uint32_t aBrightness)
  41. {
  42. MOZ_ASSERT(aBrightness < nsIScreen::BRIGHTNESS_LEVELS,
  43. "Invalid brightness level to lock");
  44. MOZ_ASSERT(mBrightnessLocks[aBrightness] > 0,
  45. "Unlocking a brightness level with no corresponding lock");
  46. mBrightnessLocks[aBrightness]--;
  47. CheckMinimumBrightness();
  48. return NS_OK;
  49. }
  50. void
  51. nsBaseScreen::CheckMinimumBrightness()
  52. {
  53. uint32_t brightness = nsIScreen::BRIGHTNESS_LEVELS;
  54. for (int32_t i = nsIScreen::BRIGHTNESS_LEVELS - 1; i >=0; i--) {
  55. if (mBrightnessLocks[i] > 0) {
  56. brightness = i;
  57. break;
  58. }
  59. }
  60. ApplyMinimumBrightness(brightness);
  61. }
  62. NS_IMETHODIMP
  63. nsBaseScreen::GetContentsScaleFactor(double* aContentsScaleFactor)
  64. {
  65. *aContentsScaleFactor = 1.0;
  66. return NS_OK;
  67. }
  68. NS_IMETHODIMP
  69. nsBaseScreen::GetDefaultCSSScaleFactor(double* aScaleFactor)
  70. {
  71. *aScaleFactor = 1.0;
  72. return NS_OK;
  73. }