DrawResult.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_DrawResult_h
  6. #define mozilla_image_DrawResult_h
  7. #include <cstdint> // for uint8_t
  8. #include "mozilla/Attributes.h"
  9. #include "mozilla/Likely.h"
  10. namespace mozilla {
  11. namespace image {
  12. /**
  13. * An enumeration representing the result of a drawing operation.
  14. *
  15. * Most users of DrawResult will only be interested in whether the value is
  16. * SUCCESS or not. The other values are primarily useful for debugging and error
  17. * handling.
  18. *
  19. * SUCCESS: We successfully drew a completely decoded frame of the requested
  20. * size. Drawing again with FLAG_SYNC_DECODE would not change the result.
  21. *
  22. * INCOMPLETE: We successfully drew a frame that was partially decoded. (Note
  23. * that successfully drawing a partially decoded frame may not actually draw any
  24. * pixels!) Drawing again with FLAG_SYNC_DECODE would improve the result.
  25. *
  26. * WRONG_SIZE: We successfully drew a wrongly-sized frame that had to be scaled.
  27. * This is only returned if drawing again with FLAG_SYNC_DECODE would improve
  28. * the result; if the size requested was larger than the intrinsic size of the
  29. * image, for example, we would generally have to scale whether FLAG_SYNC_DECODE
  30. * was specified or not, and therefore we would not return WRONG_SIZE.
  31. *
  32. * NOT_READY: We failed to draw because no decoded version of the image was
  33. * available. Drawing again with FLAG_SYNC_DECODE would improve the result.
  34. * (Though FLAG_SYNC_DECODE will not necessarily work until after the image's
  35. * load event!)
  36. *
  37. * TEMPORARY_ERROR: We failed to draw due to a temporary error. Drawing may
  38. * succeed at a later time.
  39. *
  40. * BAD_IMAGE: We failed to draw because the image has an error. This is a
  41. * permanent condition.
  42. *
  43. * BAD_ARGS: We failed to draw because bad arguments were passed to draw().
  44. */
  45. enum class MOZ_MUST_USE_TYPE DrawResult : uint8_t
  46. {
  47. SUCCESS,
  48. INCOMPLETE,
  49. WRONG_SIZE,
  50. NOT_READY,
  51. TEMPORARY_ERROR,
  52. BAD_IMAGE,
  53. BAD_ARGS
  54. };
  55. /**
  56. * You can combine DrawResults with &. By analogy to bitwise-&, the result is
  57. * DrawResult::SUCCESS only if both operands are DrawResult::SUCCESS. Otherwise,
  58. * a failing DrawResult is returned; we favor the left operand's failure when
  59. * deciding which failure to return, with the exception that we always prefer
  60. * any other kind of failure over DrawResult::BAD_IMAGE, since other failures
  61. * are recoverable and we want to know if any recoverable failures occurred.
  62. */
  63. inline DrawResult
  64. operator&(const DrawResult aLeft, const DrawResult aRight)
  65. {
  66. if (MOZ_LIKELY(aLeft == DrawResult::SUCCESS)) {
  67. return aRight;
  68. }
  69. if (aLeft == DrawResult::BAD_IMAGE && aRight != DrawResult::SUCCESS) {
  70. return aRight;
  71. }
  72. return aLeft;
  73. }
  74. inline DrawResult&
  75. operator&=(DrawResult& aLeft, const DrawResult aRight)
  76. {
  77. aLeft = aLeft & aRight;
  78. return aLeft;
  79. }
  80. } // namespace image
  81. } // namespace mozilla
  82. #endif // mozilla_image_DrawResult_h