blob: e0dbf1c4ad5476a933b86a3e4c8d98f2c4ca0b8f [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
12namespace skiagm {
13
14 /**
15 * The complete list of error types we might encounter in GM.
16 */
17 enum ErrorType {
18#if SK_SUPPORT_GPU
19 kNoGpuContext_ErrorType,
20#endif
21 kImageMismatch_ErrorType,
22 kMissingExpectations_ErrorType,
23 kWritingReferenceImage_ErrorType,
24 kLast_ErrorType = kWritingReferenceImage_ErrorType
25 };
26
27 /**
28 * A combination of 0 or more ErrorTypes.
29 */
30 class ErrorCombination {
31 public:
32 ErrorCombination() : fBitfield(0) {}
33 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {}
34
35 /**
36 * Returns true iff there are NO errors.
37 */
38 bool isEmpty() const {
39 return (0 == this->fBitfield);
40 }
41
42 /**
43 * Adds this ErrorType to this ErrorCombination.
44 */
45 void add(const ErrorType type) {
46 this->fBitfield |= (1 << type);
47 }
48
49 /**
50 * Adds all ErrorTypes in "other" to this ErrorCombination.
51 */
52 void add(const ErrorCombination other) {
53 this->fBitfield |= other.fBitfield;
54 }
55
56 /**
57 * Returns true iff this ErrorCombination includes this ErrorType.
58 */
59 bool includes(const ErrorType type) const {
60 return !(0 == (this->fBitfield & (1 << type)));
61 }
62
63 /**
64 * Returns a new ErrorCombination, which includes the union of all
65 * ErrorTypes in two ErrorCombination objects (this and other).
66 */
67 ErrorCombination plus(const ErrorCombination& other) const {
68 ErrorCombination retval;
69 retval.fBitfield = this->fBitfield | other.fBitfield;
70 return retval;
71 }
72
73 /**
74 * Returns a new ErrorCombination, which is a copy of "this"
75 * but with all ErrorTypes in "other" removed.
76 */
77 ErrorCombination minus(const ErrorCombination& other) const {
78 ErrorCombination retval;
79 retval.fBitfield = this->fBitfield & ~(other.fBitfield);
80 return retval;
81 }
82
83 private:
84 int fBitfield;
85 };
86
87 // No errors at all.
88 const static ErrorCombination kEmpty_ErrorCombination;
89}