Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* | 8 /* |
| 9 * Error codes used by gmmain.cpp. | 9 * Error codes used by gmmain.cpp. |
| 10 */ | 10 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 return "MissingExpectations"; | 51 return "MissingExpectations"; |
| 52 case kWritingReferenceImage_ErrorType: | 52 case kWritingReferenceImage_ErrorType: |
| 53 return "WritingReferenceImage"; | 53 return "WritingReferenceImage"; |
| 54 } | 54 } |
| 55 // control should never reach here | 55 // control should never reach here |
| 56 SkDEBUGFAIL("getErrorTypeName() called with unknown type"); | 56 SkDEBUGFAIL("getErrorTypeName() called with unknown type"); |
| 57 return "Unknown"; | 57 return "Unknown"; |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Fills in "type" with the ErrorType associated with name "name". | |
| 62 * Returns true if we found one, false if it is an unknown type name. | |
| 63 */ | |
| 64 static bool getErrorTypeByName(const char name[], ErrorType *type) { | |
| 65 // TODO(epoger): how can we make sure this method stays in sync with the | |
| 66 // complete list of ErrorTypes? Unlike getErrorTypeName(), in this case | |
| 67 // we don't have the compiler warning about missing enum values to keep | |
| 68 // us in sync... | |
| 69 if (0 == strcmp(name, "NoGpuContext")) { | |
|
borenet
2013/04/12 00:29:45
Suggest making these strings constant and using th
epoger
2013/04/12 02:44:43
Hey, I came up with an elegant, robust (IMHO) appr
borenet
2013/04/12 11:55:37
I like it!
| |
| 70 *type = kNoGpuContext_ErrorType; | |
| 71 return true; | |
| 72 } | |
| 73 if (0 == strcmp(name, "IntentionallySkipped")) { | |
| 74 *type = kIntentionallySkipped_ErrorType; | |
| 75 return true; | |
| 76 } | |
| 77 if (0 == strcmp(name, "RenderModeMismatch")) { | |
| 78 *type = kRenderModeMismatch_ErrorType; | |
| 79 return true; | |
| 80 } | |
| 81 if (0 == strcmp(name, "ExpectationsMismatch")) { | |
| 82 *type = kExpectationsMismatch_ErrorType; | |
| 83 return true; | |
| 84 } | |
| 85 if (0 == strcmp(name, "MissingExpectations")) { | |
| 86 *type = kMissingExpectations_ErrorType; | |
| 87 return true; | |
| 88 } | |
| 89 if (0 == strcmp(name, "WritingReferenceImage")) { | |
| 90 *type = kWritingReferenceImage_ErrorType; | |
| 91 return true; | |
| 92 } | |
| 93 return false; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 61 * A combination of 0 or more ErrorTypes. | 97 * A combination of 0 or more ErrorTypes. |
| 62 */ | 98 */ |
| 63 class ErrorCombination { | 99 class ErrorCombination { |
| 64 public: | 100 public: |
| 65 ErrorCombination() : fBitfield(0) {} | 101 ErrorCombination() : fBitfield(0) {} |
| 66 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {} | 102 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {} |
| 67 | 103 |
| 68 /** | 104 /** |
| 69 * Returns true iff there are NO errors. | 105 * Returns true iff there are NO errors. |
| 70 */ | 106 */ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 87 } | 123 } |
| 88 | 124 |
| 89 /** | 125 /** |
| 90 * Returns true iff this ErrorCombination includes this ErrorType. | 126 * Returns true iff this ErrorCombination includes this ErrorType. |
| 91 */ | 127 */ |
| 92 bool includes(const ErrorType type) const { | 128 bool includes(const ErrorType type) const { |
| 93 return !(0 == (this->fBitfield & (1 << type))); | 129 return !(0 == (this->fBitfield & (1 << type))); |
| 94 } | 130 } |
| 95 | 131 |
| 96 /** | 132 /** |
| 133 * Returns a string representation of all ErrorTypes in this | |
| 134 * ErrorCombination. | |
| 135 * | |
| 136 * @param separator text with which to separate ErrorType names | |
| 137 */ | |
| 138 SkString asString(const char separator[]) const { | |
| 139 SkString s; | |
| 140 int howMany = 0; | |
| 141 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) { | |
| 142 ErrorType type = static_cast<ErrorType>(typeInt); | |
| 143 if (this->includes(type)) { | |
| 144 if (0 < howMany++) { | |
|
borenet
2013/04/12 00:29:45
Is this significantly faster than (s.size() == 0)?
epoger
2013/04/12 02:44:43
Probably not. Now calling s.isEmpty()... thanks f
| |
| 145 s.append(separator); | |
| 146 } | |
| 147 s.append(getErrorTypeName(type)); | |
| 148 } | |
| 149 } | |
| 150 return s; | |
| 151 } | |
| 152 | |
| 153 /** | |
| 97 * Returns a new ErrorCombination, which includes the union of all | 154 * Returns a new ErrorCombination, which includes the union of all |
| 98 * ErrorTypes in two ErrorCombination objects (this and other). | 155 * ErrorTypes in two ErrorCombination objects (this and other). |
| 99 */ | 156 */ |
| 100 ErrorCombination plus(const ErrorCombination& other) const { | 157 ErrorCombination plus(const ErrorCombination& other) const { |
| 101 ErrorCombination retval; | 158 ErrorCombination retval; |
| 102 retval.fBitfield = this->fBitfield | other.fBitfield; | 159 retval.fBitfield = this->fBitfield | other.fBitfield; |
| 103 return retval; | 160 return retval; |
| 104 } | 161 } |
| 105 | 162 |
| 106 /** | 163 /** |
| 107 * Returns a new ErrorCombination, which is a copy of "this" | 164 * Returns a new ErrorCombination, which is a copy of "this" |
| 108 * but with all ErrorTypes in "other" removed. | 165 * but with all ErrorTypes in "other" removed. |
| 109 */ | 166 */ |
| 110 ErrorCombination minus(const ErrorCombination& other) const { | 167 ErrorCombination minus(const ErrorCombination& other) const { |
| 111 ErrorCombination retval; | 168 ErrorCombination retval; |
| 112 retval.fBitfield = this->fBitfield & ~(other.fBitfield); | 169 retval.fBitfield = this->fBitfield & ~(other.fBitfield); |
| 113 return retval; | 170 return retval; |
| 114 } | 171 } |
| 115 | 172 |
| 116 private: | 173 private: |
| 117 int fBitfield; | 174 int fBitfield; |
| 118 }; | 175 }; |
| 119 | 176 |
| 120 // No errors at all. | 177 // No errors at all. |
| 121 const static ErrorCombination kEmpty_ErrorCombination; | 178 const static ErrorCombination kEmpty_ErrorCombination; |
| 122 } | 179 } |
| 123 | 180 |
| 124 #endif // ifndef gm_error_DEFINED | 181 #endif // ifndef gm_error_DEFINED |
| OLD | NEW |