Bug 1885337 - Part 2: Implement to/from base64 methods. r=dminor
[gecko.git] / image / ImgDrawResult.h
blobd33b63d71ce7829446b8f261f834f59ebf26ef15
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/. */
6 #ifndef mozilla_image_ImgDrawResult_h
7 #define mozilla_image_ImgDrawResult_h
9 #include <cstdint> // for uint8_t
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Likely.h"
13 namespace mozilla {
14 namespace image {
16 /**
17 * An enumeration representing the result of a drawing operation.
19 * Most users of ImgDrawResult will only be interested in whether the value is
20 * SUCCESS or not. The other values are primarily useful for debugging and error
21 * handling.
23 * SUCCESS: We successfully drew a completely decoded frame of the requested
24 * size. Drawing again with FLAG_SYNC_DECODE would not change the result.
26 * SUCCESS_NOT_COMPLETE: The image was drawn successfully and completely, but
27 * it hasn't notified about the sync-decode yet. This can only happen when
28 * layout pokes at the internal image state beforehand via the result of
29 * StartDecodingWithResult. This should probably go away eventually, somehow,
30 * see bug 1471583.
32 * INCOMPLETE: We successfully drew a frame that was partially decoded. (Note
33 * that successfully drawing a partially decoded frame may not actually draw any
34 * pixels!) Drawing again with FLAG_SYNC_DECODE would improve the result.
36 * WRONG_SIZE: We successfully drew a wrongly-sized frame that had to be scaled.
37 * This is only returned if drawing again with FLAG_SYNC_DECODE would improve
38 * the result; if the size requested was larger than the intrinsic size of the
39 * image, for example, we would generally have to scale whether FLAG_SYNC_DECODE
40 * was specified or not, and therefore we would not return WRONG_SIZE.
42 * NOT_READY: We failed to draw because no decoded version of the image was
43 * available. Drawing again with FLAG_SYNC_DECODE would improve the result.
44 * (Though FLAG_SYNC_DECODE will not necessarily work until after the image's
45 * load event!)
47 * TEMPORARY_ERROR: We failed to draw due to a temporary error. Drawing may
48 * succeed at a later time.
50 * BAD_IMAGE: We failed to draw because the image has an error. This is a
51 * permanent condition.
53 * BAD_ARGS: We failed to draw because bad arguments were passed to draw().
55 * NOT_SUPPORTED: The requested operation is not supported, but the image is
56 * otherwise valid.
58 enum class [[nodiscard]] ImgDrawResult : uint8_t {
59 SUCCESS,
60 SUCCESS_NOT_COMPLETE,
61 INCOMPLETE,
62 WRONG_SIZE,
63 NOT_READY,
64 TEMPORARY_ERROR,
65 BAD_IMAGE,
66 BAD_ARGS,
67 NOT_SUPPORTED
70 /**
71 * You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is
72 * ImgDrawResult::SUCCESS only if both operands are ImgDrawResult::SUCCESS.
73 * Otherwise, a failing ImgDrawResult is returned; we favor the left operand's
74 * failure when deciding which failure to return, with the exception that we
75 * always prefer any other kind of failure over ImgDrawResult::BAD_IMAGE, since
76 * other failures are recoverable and we want to know if any recoverable
77 * failures occurred.
79 inline ImgDrawResult operator&(const ImgDrawResult aLeft,
80 const ImgDrawResult aRight) {
81 if (MOZ_LIKELY(aLeft == ImgDrawResult::SUCCESS)) {
82 return aRight;
85 if (aLeft == ImgDrawResult::NOT_SUPPORTED ||
86 aRight == ImgDrawResult::NOT_SUPPORTED) {
87 return ImgDrawResult::NOT_SUPPORTED;
90 if ((aLeft == ImgDrawResult::BAD_IMAGE ||
91 aLeft == ImgDrawResult::SUCCESS_NOT_COMPLETE) &&
92 aRight != ImgDrawResult::SUCCESS &&
93 aRight != ImgDrawResult::SUCCESS_NOT_COMPLETE) {
94 return aRight;
96 return aLeft;
99 inline ImgDrawResult& operator&=(ImgDrawResult& aLeft,
100 const ImgDrawResult aRight) {
101 aLeft = aLeft & aRight;
102 return aLeft;
106 * A struct used during painting to provide input flags to determine how
107 * imagelib draw calls should behave and an output ImgDrawResult to return
108 * information about the result of any imagelib draw calls that may have
109 * occurred.
111 struct imgDrawingParams {
112 explicit imgDrawingParams(uint32_t aImageFlags = 0)
113 : imageFlags(aImageFlags), result(ImgDrawResult::SUCCESS) {}
115 const uint32_t imageFlags; // imgIContainer::FLAG_* image flags to pass to
116 // image lib draw calls.
117 ImgDrawResult result; // To return results from image lib painting.
120 } // namespace image
121 } // namespace mozilla
123 #endif // mozilla_image_ImgDrawResult_h