SurfaceFlags.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  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. #ifndef mozilla_image_SurfaceFlags_h
  6. #define mozilla_image_SurfaceFlags_h
  7. #include "imgIContainer.h"
  8. #include "mozilla/TypedEnumBits.h"
  9. namespace mozilla {
  10. namespace image {
  11. /**
  12. * Flags that change the output a decoder generates. Because different
  13. * combinations of these flags result in logically different surfaces, these
  14. * flags must be taken into account in SurfaceCache lookups.
  15. */
  16. enum class SurfaceFlags : uint8_t
  17. {
  18. NO_PREMULTIPLY_ALPHA = 1 << 0,
  19. NO_COLORSPACE_CONVERSION = 1 << 1
  20. };
  21. MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags)
  22. /**
  23. * @return the default set of surface flags.
  24. */
  25. inline SurfaceFlags
  26. DefaultSurfaceFlags()
  27. {
  28. return SurfaceFlags();
  29. }
  30. /**
  31. * Given a set of imgIContainer FLAG_* flags, returns a set of SurfaceFlags with
  32. * the corresponding flags set.
  33. */
  34. inline SurfaceFlags
  35. ToSurfaceFlags(uint32_t aFlags)
  36. {
  37. SurfaceFlags flags = DefaultSurfaceFlags();
  38. if (aFlags & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA) {
  39. flags |= SurfaceFlags::NO_PREMULTIPLY_ALPHA;
  40. }
  41. if (aFlags & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) {
  42. flags |= SurfaceFlags::NO_COLORSPACE_CONVERSION;
  43. }
  44. return flags;
  45. }
  46. /**
  47. * Given a set of SurfaceFlags, returns a set of imgIContainer FLAG_* flags with
  48. * the corresponding flags set.
  49. */
  50. inline uint32_t
  51. FromSurfaceFlags(SurfaceFlags aFlags)
  52. {
  53. uint32_t flags = imgIContainer::DECODE_FLAGS_DEFAULT;
  54. if (aFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA) {
  55. flags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
  56. }
  57. if (aFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
  58. flags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
  59. }
  60. return flags;
  61. }
  62. } // namespace image
  63. } // namespace mozilla
  64. #endif // mozilla_image_SurfaceFlags_h