| Flutter Impeller |

validation.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/base/validation.h"
6
7 #include <atomic>
8
9 #include "flutter/fml/logging.h"
10
11 namespace impeller {
12
13 static std::atomic_int32_t sValidationLogsDisabledCount = 0;
14 static std::atomic_int32_t sValidationLogsAreFatal = 0;
15
16 void ImpellerValidationErrorsSetFatal(bool fatal) {
17 sValidationLogsAreFatal = fatal;
18 }
19
20 ScopedValidationDisable::ScopedValidationDisable() {
21 sValidationLogsDisabledCount++;
22 }
23
24 ScopedValidationDisable::~ScopedValidationDisable() {
25 sValidationLogsDisabledCount--;
26 }
27
28 ScopedValidationFatal::ScopedValidationFatal() {
29 sValidationLogsAreFatal++;
30 }
31
32 ScopedValidationFatal::~ScopedValidationFatal() {
33 sValidationLogsAreFatal--;
34 }
35
36 ValidationLog::ValidationLog() = default;
37
38 ValidationLog::~ValidationLog() {
39 if (sValidationLogsDisabledCount <= 0) {
40 ImpellerValidationBreak(stream_.str().c_str());
41 }
42 }
43
44 std::ostream& ValidationLog::GetStream() {
45 return stream_;
46 }
47
48 void ImpellerValidationBreak(const char* message) {
49 std::stringstream stream;
50 #if FLUTTER_RELEASE
51 stream << "Impeller validation: " << message;
52 #else
53 stream << "Break on '" << __FUNCTION__
54 << "' to inspect point of failure: " << message;
55 #endif
56 if (sValidationLogsAreFatal > 0) {
57 FML_LOG(FATAL) << stream.str();
58 } else {
59 FML_LOG(ERROR) << stream.str();
60 }
61 }
62
63 bool ImpellerValidationErrorsAreFatal() {
64 return sValidationLogsAreFatal;
65 }
66
67 } // namespace impeller
impeller::ImpellerValidationBreak
void ImpellerValidationBreak(const char *message)
Definition: validation.cc:48
impeller::ScopedValidationFatal::ScopedValidationFatal
ScopedValidationFatal()
Definition: validation.cc:28
impeller::sValidationLogsAreFatal
static std::atomic_int32_t sValidationLogsAreFatal
Definition: validation.cc:14
impeller::ScopedValidationDisable::~ScopedValidationDisable
~ScopedValidationDisable()
Definition: validation.cc:24
impeller::ScopedValidationFatal::~ScopedValidationFatal
~ScopedValidationFatal()
Definition: validation.cc:32
validation.h
impeller::ValidationLog::~ValidationLog
~ValidationLog()
Definition: validation.cc:38
impeller::ValidationLog::ValidationLog
ValidationLog()
impeller::ScopedValidationDisable::ScopedValidationDisable
ScopedValidationDisable()
Definition: validation.cc:20
impeller::sValidationLogsDisabledCount
static std::atomic_int32_t sValidationLogsDisabledCount
Definition: validation.cc:13
impeller::ImpellerValidationErrorsSetFatal
void ImpellerValidationErrorsSetFatal(bool fatal)
Definition: validation.cc:16
impeller::ImpellerValidationErrorsAreFatal
bool ImpellerValidationErrorsAreFatal()
Definition: validation.cc:63
impeller::ValidationLog::GetStream
std::ostream & GetStream()
Definition: validation.cc:44
impeller
Definition: aiks_blend_unittests.cc:18