blob: 16917435d3396a6864dbb8a34c925b74d787d5ec [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.comc8263e72013-04-10 12:17:34 +000029 kIntentionallySkipped_ErrorType,
epoger@google.comcaac3db2013-04-04 19:23:11 +000030 kRenderModeMismatch_ErrorType,
31 kExpectationsMismatch_ErrorType,
epoger@google.com6f6568b2013-03-22 17:29:46 +000032 kMissingExpectations_ErrorType,
33 kWritingReferenceImage_ErrorType,
34 kLast_ErrorType = kWritingReferenceImage_ErrorType
35 };
36
37 /**
epoger@google.com310478e2013-04-03 18:00:39 +000038 * Returns the name of the given ErrorType.
39 */
40 static const char *getErrorTypeName(ErrorType type) {
41 switch(type) {
42 case kNoGpuContext_ErrorType:
43 return "NoGpuContext";
epoger@google.comc8263e72013-04-10 12:17:34 +000044 case kIntentionallySkipped_ErrorType:
45 return "IntentionallySkipped";
epoger@google.comcaac3db2013-04-04 19:23:11 +000046 case kRenderModeMismatch_ErrorType:
47 return "RenderModeMismatch";
48 case kExpectationsMismatch_ErrorType:
49 return "ExpectationsMismatch";
epoger@google.com310478e2013-04-03 18:00:39 +000050 case kMissingExpectations_ErrorType:
51 return "MissingExpectations";
52 case kWritingReferenceImage_ErrorType:
53 return "WritingReferenceImage";
54 }
55 // control should never reach here
56 SkDEBUGFAIL("getErrorTypeName() called with unknown type");
57 return "Unknown";
58 }
59
60 /**
epoger@google.com6f6568b2013-03-22 17:29:46 +000061 * A combination of 0 or more ErrorTypes.
62 */
63 class ErrorCombination {
64 public:
65 ErrorCombination() : fBitfield(0) {}
66 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {}
67
68 /**
69 * Returns true iff there are NO errors.
70 */
71 bool isEmpty() const {
72 return (0 == this->fBitfield);
73 }
74
75 /**
76 * Adds this ErrorType to this ErrorCombination.
77 */
78 void add(const ErrorType type) {
79 this->fBitfield |= (1 << type);
80 }
81
82 /**
83 * Adds all ErrorTypes in "other" to this ErrorCombination.
84 */
85 void add(const ErrorCombination other) {
86 this->fBitfield |= other.fBitfield;
87 }
88
89 /**
90 * Returns true iff this ErrorCombination includes this ErrorType.
91 */
92 bool includes(const ErrorType type) const {
93 return !(0 == (this->fBitfield & (1 << type)));
94 }
95
96 /**
97 * Returns a new ErrorCombination, which includes the union of all
98 * ErrorTypes in two ErrorCombination objects (this and other).
99 */
100 ErrorCombination plus(const ErrorCombination& other) const {
101 ErrorCombination retval;
102 retval.fBitfield = this->fBitfield | other.fBitfield;
103 return retval;
104 }
105
106 /**
107 * Returns a new ErrorCombination, which is a copy of "this"
108 * but with all ErrorTypes in "other" removed.
109 */
110 ErrorCombination minus(const ErrorCombination& other) const {
111 ErrorCombination retval;
112 retval.fBitfield = this->fBitfield & ~(other.fBitfield);
113 return retval;
114 }
115
116 private:
117 int fBitfield;
118 };
119
120 // No errors at all.
121 const static ErrorCombination kEmpty_ErrorCombination;
122}
epoger@google.com310478e2013-04-03 18:00:39 +0000123
124#endif // ifndef gm_error_DEFINED