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"
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
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,
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
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
58 enum class [[nodiscard
]] ImgDrawResult
: uint8_t{
59 SUCCESS
, SUCCESS_NOT_COMPLETE
, INCOMPLETE
, WRONG_SIZE
,
60 NOT_READY
, TEMPORARY_ERROR
, BAD_IMAGE
, BAD_ARGS
,
64 * You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is
65 * ImgDrawResult::SUCCESS only if both operands are ImgDrawResult::SUCCESS.
66 * Otherwise, a failing ImgDrawResult is returned; we favor the left operand's
67 * failure when deciding which failure to return, with the exception that we
68 * always prefer any other kind of failure over ImgDrawResult::BAD_IMAGE, since
69 * other failures are recoverable and we want to know if any recoverable
72 inline ImgDrawResult
operator&(const ImgDrawResult aLeft
,
73 const ImgDrawResult aRight
) {
74 if (MOZ_LIKELY(aLeft
== ImgDrawResult::SUCCESS
)) {
78 if (aLeft
== ImgDrawResult::NOT_SUPPORTED
||
79 aRight
== ImgDrawResult::NOT_SUPPORTED
) {
80 return ImgDrawResult::NOT_SUPPORTED
;
83 if ((aLeft
== ImgDrawResult::BAD_IMAGE
||
84 aLeft
== ImgDrawResult::SUCCESS_NOT_COMPLETE
) &&
85 aRight
!= ImgDrawResult::SUCCESS
&&
86 aRight
!= ImgDrawResult::SUCCESS_NOT_COMPLETE
) {
92 inline ImgDrawResult
& operator&=(ImgDrawResult
& aLeft
,
93 const ImgDrawResult aRight
) {
94 aLeft
= aLeft
& aRight
;
99 * A struct used during painting to provide input flags to determine how
100 * imagelib draw calls should behave and an output ImgDrawResult to return
101 * information about the result of any imagelib draw calls that may have
104 struct imgDrawingParams
{
105 explicit imgDrawingParams(uint32_t aImageFlags
= 0)
106 : imageFlags(aImageFlags
), result(ImgDrawResult::SUCCESS
) {}
108 const uint32_t imageFlags
; // imgIContainer::FLAG_* image flags to pass to
109 // image lib draw calls.
110 ImgDrawResult result
; // To return results from image lib painting.
114 } // namespace mozilla
116 #endif // mozilla_image_ImgDrawResult_h