mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-15 03:41:34 +00:00
- Adds Prepend function to LinkedList to avoid directly using the insert functions on the LinkNodes. (And tests for this as well.) - Adds ApiObjectList class for tracking lists of objects for destruction. - Renames and virtualizes some tracking interfaces so that they can be overriden for the TextureView/Texture cases. - Removes explicit destroying of TextureViews from Device since destroying Textures will destroy TextureViews now. Fixed: dawn:1355 Change-Id: I3522383ea7724d6e41ac0c805793a6c34d9bec27 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101762 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
116 lines
3.0 KiB
C++
116 lines
3.0 KiB
C++
// Copyright 2018 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.
|
|
|
|
#include <mutex>
|
|
|
|
#include "dawn/native/Device.h"
|
|
#include "dawn/native/ObjectBase.h"
|
|
|
|
namespace dawn::native {
|
|
|
|
static constexpr uint64_t kErrorPayload = 0;
|
|
static constexpr uint64_t kNotErrorPayload = 1;
|
|
|
|
ErrorMonad::ErrorMonad() : RefCounted(kNotErrorPayload) {}
|
|
ErrorMonad::ErrorMonad(ErrorTag) : RefCounted(kErrorPayload) {}
|
|
|
|
bool ErrorMonad::IsError() const {
|
|
return GetRefCountPayload() == kErrorPayload;
|
|
}
|
|
|
|
ObjectBase::ObjectBase(DeviceBase* device) : ErrorMonad(), mDevice(device) {}
|
|
|
|
ObjectBase::ObjectBase(DeviceBase* device, ErrorTag) : ErrorMonad(kError), mDevice(device) {}
|
|
|
|
DeviceBase* ObjectBase::GetDevice() const {
|
|
return mDevice.Get();
|
|
}
|
|
|
|
void ApiObjectList::Track(ApiObjectBase* object) {
|
|
if (mMarkedDestroyed) {
|
|
object->DestroyImpl();
|
|
return;
|
|
}
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
mObjects.Prepend(object);
|
|
}
|
|
|
|
bool ApiObjectList::Untrack(ApiObjectBase* object) {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
return object->RemoveFromList();
|
|
}
|
|
|
|
void ApiObjectList::Destroy() {
|
|
std::lock_guard<std::mutex> lock(mMutex);
|
|
mMarkedDestroyed = true;
|
|
while (!mObjects.empty()) {
|
|
auto* head = mObjects.head();
|
|
bool removed = head->RemoveFromList();
|
|
ASSERT(removed);
|
|
head->value()->DestroyImpl();
|
|
}
|
|
}
|
|
|
|
ApiObjectBase::ApiObjectBase(DeviceBase* device, const char* label) : ObjectBase(device) {
|
|
if (label) {
|
|
mLabel = label;
|
|
}
|
|
}
|
|
|
|
ApiObjectBase::ApiObjectBase(DeviceBase* device, ErrorTag tag) : ObjectBase(device, tag) {}
|
|
|
|
ApiObjectBase::ApiObjectBase(DeviceBase* device, LabelNotImplementedTag tag) : ObjectBase(device) {}
|
|
|
|
ApiObjectBase::~ApiObjectBase() {
|
|
ASSERT(!IsAlive());
|
|
}
|
|
|
|
void ApiObjectBase::APISetLabel(const char* label) {
|
|
mLabel = label;
|
|
SetLabelImpl();
|
|
}
|
|
|
|
const std::string& ApiObjectBase::GetLabel() const {
|
|
return mLabel;
|
|
}
|
|
|
|
void ApiObjectBase::SetLabelImpl() {}
|
|
|
|
bool ApiObjectBase::IsAlive() const {
|
|
return IsInList();
|
|
}
|
|
|
|
void ApiObjectBase::DeleteThis() {
|
|
Destroy();
|
|
RefCounted::DeleteThis();
|
|
}
|
|
|
|
ApiObjectList* ApiObjectBase::GetObjectTrackingList() {
|
|
ASSERT(GetDevice() != nullptr);
|
|
return GetDevice()->GetObjectTrackingList(GetType());
|
|
}
|
|
|
|
void ApiObjectBase::Destroy() {
|
|
if (!IsAlive()) {
|
|
return;
|
|
}
|
|
ApiObjectList* list = GetObjectTrackingList();
|
|
ASSERT(list != nullptr);
|
|
if (list->Untrack(this)) {
|
|
DestroyImpl();
|
|
}
|
|
}
|
|
|
|
} // namespace dawn::native
|