Implement InstanceBase::ConsumedError taking a ResultOrError<T>.

Bug: dawn:810
Change-Id: Id84bb17940d811de1925345924e844a48b04fc18
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95261
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2022-06-30 15:51:42 +00:00 committed by Dawn LUCI CQ
parent fd7390a587
commit eab404cb17
2 changed files with 18 additions and 4 deletions

View File

@ -386,10 +386,7 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB
bool InstanceBase::ConsumedError(MaybeError maybeError) { bool InstanceBase::ConsumedError(MaybeError maybeError) {
if (maybeError.IsError()) { if (maybeError.IsError()) {
std::unique_ptr<ErrorData> error = maybeError.AcquireError(); ConsumeError(maybeError.AcquireError());
ASSERT(error != nullptr);
dawn::ErrorLog() << error->GetFormattedMessage();
return true; return true;
} }
return false; return false;
@ -452,6 +449,11 @@ const std::vector<std::string>& InstanceBase::GetRuntimeSearchPaths() const {
return mRuntimeSearchPaths; return mRuntimeSearchPaths;
} }
void InstanceBase::ConsumeError(std::unique_ptr<ErrorData> error) {
ASSERT(error != nullptr);
dawn::ErrorLog() << error->GetFormattedMessage();
}
const XlibXcbFunctions* InstanceBase::GetOrCreateXlibXcbFunctions() { const XlibXcbFunctions* InstanceBase::GetOrCreateXlibXcbFunctions() {
#if defined(DAWN_USE_X11) #if defined(DAWN_USE_X11)
if (mXlibXcbFunctions == nullptr) { if (mXlibXcbFunctions == nullptr) {

View File

@ -61,6 +61,16 @@ class InstanceBase final : public RefCounted {
// Used to handle error that happen up to device creation. // Used to handle error that happen up to device creation.
bool ConsumedError(MaybeError maybeError); bool ConsumedError(MaybeError maybeError);
template <typename T>
bool ConsumedError(ResultOrError<T> resultOrError, T* result) {
if (resultOrError.IsError()) {
ConsumeError(resultOrError.AcquireError());
return true;
}
*result = resultOrError.AcquireSuccess();
return false;
}
// Used to query the details of a toggle. Return nullptr if toggleName is not a valid name // Used to query the details of a toggle. Return nullptr if toggleName is not a valid name
// of a toggle supported in Dawn. // of a toggle supported in Dawn.
const ToggleInfo* GetToggleInfo(const char* toggleName); const ToggleInfo* GetToggleInfo(const char* toggleName);
@ -112,6 +122,8 @@ class InstanceBase final : public RefCounted {
ResultOrError<Ref<AdapterBase>> RequestAdapterInternal(const RequestAdapterOptions* options); ResultOrError<Ref<AdapterBase>> RequestAdapterInternal(const RequestAdapterOptions* options);
void ConsumeError(std::unique_ptr<ErrorData> error);
std::vector<std::string> mRuntimeSearchPaths; std::vector<std::string> mRuntimeSearchPaths;
BackendsBitset mBackendsConnected; BackendsBitset mBackendsConnected;