1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_ERRORSCOPE_H_ 16 #define DAWNNATIVE_ERRORSCOPE_H_ 17 18 #include "dawn_native/dawn_platform.h" 19 20 #include <string> 21 #include <vector> 22 23 namespace dawn_native { 24 25 class ErrorScope { 26 public: 27 wgpu::ErrorType GetErrorType() const; 28 const char* GetErrorMessage() const; 29 30 private: 31 friend class ErrorScopeStack; 32 explicit ErrorScope(wgpu::ErrorFilter errorFilter); 33 34 wgpu::ErrorType mMatchedErrorType; 35 wgpu::ErrorType mCapturedError = wgpu::ErrorType::NoError; 36 std::string mErrorMessage = ""; 37 }; 38 39 class ErrorScopeStack { 40 public: 41 void Push(wgpu::ErrorFilter errorFilter); 42 ErrorScope Pop(); 43 44 bool Empty() const; 45 46 // Pass an error to the scopes in the stack. Returns true if one of the scopes 47 // captured the error. Returns false if the error should be forwarded to the 48 // uncaptured error callback. 49 bool HandleError(wgpu::ErrorType type, const char* message); 50 51 private: 52 std::vector<ErrorScope> mScopes; 53 }; 54 55 } // namespace dawn_native 56 57 #endif // DAWNNATIVE_ERRORSCOPE_H_ 58