dawn-cmake/src/dawn_native/ErrorScope.h
Rafael Cintron 7e8385c183 Move and improve RefCounted
- Move RefCounted to common (from dawn_native) so that we can use
it from additional places.
- Use EXPECT_ macros instead of ASSERT_ in RefCounted tests for
improved logging on failures.
- Add a missing test for Ref::Detach.
- Plug memory leak in RaceOnReferenceRelease

Change-Id: Iaa7b11b5a6fa146e3c322143279a21a4ac027547
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19903
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
2020-04-20 17:36:22 +00:00

68 lines
2.4 KiB
C++

// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DAWNNATIVE_ERRORSCOPE_H_
#define DAWNNATIVE_ERRORSCOPE_H_
#include "dawn_native/dawn_platform.h"
#include "common/RefCounted.h"
#include <string>
namespace dawn_native {
// Errors can be recorded into an ErrorScope by calling |HandleError|.
// Because an error scope should not resolve until contained
// commands are complete, calling the callback is deferred until it is destructed.
// In-flight commands or asynchronous events should hold a reference to the
// ErrorScope for their duration.
//
// Because parent ErrorScopes should not resolve before child ErrorScopes,
// ErrorScopes hold a reference to their parent.
//
// To simplify ErrorHandling, there is a sentinel root error scope which has
// no parent. All uncaptured errors are handled by the root error scope. Its
// callback is called immediately once it encounters an error.
class ErrorScope final : public RefCounted {
public:
ErrorScope(); // Constructor for the root error scope.
ErrorScope(wgpu::ErrorFilter errorFilter, ErrorScope* parent);
void SetCallback(wgpu::ErrorCallback callback, void* userdata);
ErrorScope* GetParent();
void HandleError(wgpu::ErrorType type, const char* message);
void Destroy();
private:
~ErrorScope() override;
bool IsRoot() const;
static void HandleErrorImpl(ErrorScope* scope, wgpu::ErrorType type, const char* message);
wgpu::ErrorFilter mErrorFilter = wgpu::ErrorFilter::None;
Ref<ErrorScope> mParent = nullptr;
wgpu::ErrorCallback mCallback = nullptr;
void* mUserdata = nullptr;
wgpu::ErrorType mErrorType = wgpu::ErrorType::NoError;
std::string mErrorMessage = "";
};
} // namespace dawn_native
#endif // DAWNNATIVE_ERRORSCOPE_H_