blob: aab0ec0b25c4ce8bf742ef8993c0a1532db21b65 [file] [log] [blame]
epoger@google.com6f6568b2013-03-22 17:29:46 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8/*
9 * Error codes used by gmmain.cpp.
10 */
11
epoger@google.com310478e2013-04-03 18:00:39 +000012#ifndef gm_error_DEFINED
13#define gm_error_DEFINED
14
15#include "gm.h"
16
epoger@google.com6f6568b2013-03-22 17:29:46 +000017namespace skiagm {
18
19 /**
20 * The complete list of error types we might encounter in GM.
21 */
22 enum ErrorType {
epoger@google.com310478e2013-04-03 18:00:39 +000023 // Even though kNoGpuContext_ErrorType only occurs when SK_SUPPORT_GPU
24 // is turned on, we always include this type in our enum so that
25 // reports will be consistent whether SK_SUPPORT_GPU is turned on
26 // or off (as long as the number of these errors is 0).
epoger@google.com6f6568b2013-03-22 17:29:46 +000027 kNoGpuContext_ErrorType,
epoger@google.com310478e2013-04-03 18:00:39 +000028
epoger@google.comcaac3db2013-04-04 19:23:11 +000029 kRenderModeMismatch_ErrorType,
30 kExpectationsMismatch_ErrorType,
epoger@google.com6f6568b2013-03-22 17:29:46 +000031 kMissingExpectations_ErrorType,
32 kWritingReferenceImage_ErrorType,
33 kLast_ErrorType = kWritingReferenceImage_ErrorType
34 };
35
36 /**
epoger@google.com310478e2013-04-03 18:00:39 +000037 * Returns the name of the given ErrorType.
38 */
39 static const char *getErrorTypeName(ErrorType type) {
40 switch(type) {
41 case kNoGpuContext_ErrorType:
42 return "NoGpuContext";
epoger@google.comcaac3db2013-04-04 19:23:11 +000043 case kRenderModeMismatch_ErrorType:
44 return "RenderModeMismatch";
45 case kExpectationsMismatch_ErrorType:
46 return "ExpectationsMismatch";
epoger@google.com310478e2013-04-03 18:00:39 +000047 case kMissingExpectations_ErrorType:
48 return "MissingExpectations";
49 case kWritingReferenceImage_ErrorType:
50 return "WritingReferenceImage";
51 }
52 // control should never reach here
53 SkDEBUGFAIL("getErrorTypeName() called with unknown type");
54 return "Unknown";
55 }
56
57 /**
epoger@google.com6f6568b2013-03-22 17:29:46 +000058 * A combination of 0 or more ErrorTypes.
59 */
60 class ErrorCombination {
61 public:
62 ErrorCombination() : fBitfield(0) {}
63 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {}
64
65 /**
66 * Returns true iff there are NO errors.
67 */
68 bool isEmpty() const {
69 return (0 == this->fBitfield);
70 }
71
72 /**
73 * Adds this ErrorType to this ErrorCombination.
74 */
75 void add(const ErrorType type) {
76 this->fBitfield |= (1 << type);
77 }
78
79 /**
80 * Adds all ErrorTypes in "other" to this ErrorCombination.
81 */
82 void add(const ErrorCombination other) {
83 this->fBitfield |= other.fBitfield;
84 }
85
86 /**
87 * Returns true iff this ErrorCombination includes this ErrorType.
88 */
89 bool includes(const ErrorType type) const {
90 return !(0 == (this->fBitfield & (1 << type)));
91 }
92
93 /**
94 * Returns a new ErrorCombination, which includes the union of all
95 * ErrorTypes in two ErrorCombination objects (this and other).
96 */
97 ErrorCombination plus(const ErrorCombination& other) const {
98 ErrorCombination retval;
99 retval.fBitfield = this->fBitfield | other.fBitfield;
100 return retval;
101 }
102
103 /**
104 * Returns a new ErrorCombination, which is a copy of "this"
105 * but with all ErrorTypes in "other" removed.
106 */
107 ErrorCombination minus(const ErrorCombination& other) const {
108 ErrorCombination retval;
109 retval.fBitfield = this->fBitfield & ~(other.fBitfield);
110 return retval;
111 }
112
113 private:
114 int fBitfield;
115 };
116
117 // No errors at all.
118 const static ErrorCombination kEmpty_ErrorCombination;
119}
epoger@google.com310478e2013-04-03 18:00:39 +0000120
121#endif // ifndef gm_error_DEFINED