Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/ImgDrawResult.h
Line
Count
Source (jump to first uncovered line)
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
6
#ifndef mozilla_image_ImgDrawResult_h
7
#define mozilla_image_ImgDrawResult_h
8
9
#include <cstdint> // for uint8_t
10
#include "mozilla/Attributes.h"
11
#include "mozilla/Likely.h"
12
13
namespace mozilla {
14
namespace image {
15
16
/**
17
 * An enumeration representing the result of a drawing operation.
18
 *
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.
22
 *
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.
25
 *
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
 * nsStyleImage::StartDecoding. This should probably go away eventually,
30
 * somehow, see bug 1471583.
31
 *
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.
35
 *
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.
41
 *
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!)
46
 *
47
 * TEMPORARY_ERROR: We failed to draw due to a temporary error. Drawing may
48
 * succeed at a later time.
49
 *
50
 * BAD_IMAGE: We failed to draw because the image has an error. This is a
51
 * permanent condition.
52
 *
53
 * BAD_ARGS: We failed to draw because bad arguments were passed to draw().
54
 *
55
 * NOT_SUPPORTED: The requested operation is not supported, but the image is
56
 *                otherwise valid.
57
 */
58
enum class MOZ_MUST_USE_TYPE ImgDrawResult : uint8_t
59
{
60
  SUCCESS,
61
  SUCCESS_NOT_COMPLETE,
62
  INCOMPLETE,
63
  WRONG_SIZE,
64
  NOT_READY,
65
  TEMPORARY_ERROR,
66
  BAD_IMAGE,
67
  BAD_ARGS,
68
  NOT_SUPPORTED
69
};
70
71
/**
72
 * You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is
73
 * ImgDrawResult::SUCCESS only if both operands are ImgDrawResult::SUCCESS. Otherwise,
74
 * a failing ImgDrawResult is returned; we favor the left operand's failure when
75
 * deciding which failure to return, with the exception that we always prefer
76
 * any other kind of failure over ImgDrawResult::BAD_IMAGE, since other failures
77
 * are recoverable and we want to know if any recoverable failures occurred.
78
 */
79
inline ImgDrawResult
80
operator&(const ImgDrawResult aLeft, const ImgDrawResult aRight)
81
0
{
82
0
  if (MOZ_LIKELY(aLeft == ImgDrawResult::SUCCESS)) {
83
0
    return aRight;
84
0
  }
85
0
86
0
  if (aLeft == ImgDrawResult::NOT_SUPPORTED ||
87
0
      aRight == ImgDrawResult::NOT_SUPPORTED) {
88
0
    return ImgDrawResult::NOT_SUPPORTED;
89
0
  }
90
0
91
0
  if ((aLeft == ImgDrawResult::BAD_IMAGE ||
92
0
       aLeft == ImgDrawResult::SUCCESS_NOT_COMPLETE) &&
93
0
      aRight != ImgDrawResult::SUCCESS &&
94
0
      aRight != ImgDrawResult::SUCCESS_NOT_COMPLETE) {
95
0
    return aRight;
96
0
  }
97
0
  return aLeft;
98
0
}
99
100
inline ImgDrawResult&
101
operator&=(ImgDrawResult& aLeft, const ImgDrawResult aRight)
102
0
{
103
0
  aLeft = aLeft & aRight;
104
0
  return aLeft;
105
0
}
106
107
/**
108
 * A struct used during painting to provide input flags to determine how
109
 * imagelib draw calls should behave and an output ImgDrawResult to return
110
 * information about the result of any imagelib draw calls that may have
111
 * occurred.
112
 */
113
struct imgDrawingParams {
114
  explicit imgDrawingParams(uint32_t aImageFlags = 0)
115
    : imageFlags(aImageFlags), result(ImgDrawResult::SUCCESS)
116
0
  {}
117
118
  const uint32_t imageFlags; // imgIContainer::FLAG_* image flags to pass to
119
                             // image lib draw calls.
120
  ImgDrawResult result;         // To return results from image lib painting.
121
};
122
123
} // namespace image
124
} // namespace mozilla
125
126
#endif // mozilla_image_ImgDrawResult_h