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