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
29 * StyleImage::StartDecoding. 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 MOZ_MUST_USE_TYPE ImgDrawResult
: uint8_t {
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
79 inline ImgDrawResult
operator&(const ImgDrawResult aLeft
,
80 const ImgDrawResult aRight
) {
81 if (MOZ_LIKELY(aLeft
== ImgDrawResult::SUCCESS
)) {
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
) {
99 inline ImgDrawResult
& operator&=(ImgDrawResult
& aLeft
,
100 const ImgDrawResult aRight
) {
101 aLeft
= aLeft
& aRight
;
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
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.
121 } // namespace mozilla
123 #endif // mozilla_image_ImgDrawResult_h