Use Ref<TextureBase> instead of TextureBase* in more places

To avoid accidental memory leaks on account of using raw pointers,
use Ref<TextureBase> as method return type except at Dawn interface
boundaries.

Change-Id: I6459062ee28984de2cb1d5a2059bc70cf82b2faf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19580
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
This commit is contained in:
Rafael Cintron
2020-04-23 19:47:12 +00:00
committed by Commit Bot service account
parent c9e28b1463
commit 0e9320b5b5
19 changed files with 114 additions and 60 deletions

View File

@@ -177,11 +177,14 @@ class DAWN_NO_DISCARD Result<Ref<T>, E> {
static_assert(alignof_if_defined_else_default<E, 4> >= 4,
"Result<Ref<T>, E> reserves two bits for tagging pointers");
Result(Ref<T>&& success);
template <typename U>
Result(Ref<U>&& success);
Result(std::unique_ptr<E> error);
Result(Result<Ref<T>, E>&& other);
Result<Ref<T>, E>& operator=(Result<Ref<T>, E>&& other);
template <typename U>
Result(Result<Ref<U>, E>&& other);
template <typename U>
Result<Ref<U>, E>& operator=(Result<Ref<U>, E>&& other);
~Result();
@@ -192,6 +195,9 @@ class DAWN_NO_DISCARD Result<Ref<T>, E> {
std::unique_ptr<E> AcquireError();
private:
template <typename T2, typename E2>
friend class Result;
intptr_t mPayload = detail::kEmptyPayload;
};
@@ -399,8 +405,10 @@ std::unique_ptr<E> Result<const T*, E>::AcquireError() {
// Implementation of Result<Ref<T>, E>
template <typename T, typename E>
Result<Ref<T>, E>::Result(Ref<T>&& success)
template <typename U>
Result<Ref<T>, E>::Result(Ref<U>&& success)
: mPayload(detail::MakePayload(success.Detach(), detail::Success)) {
static_assert(std::is_convertible<U*, T*>::value, "");
}
template <typename T, typename E>
@@ -409,12 +417,16 @@ Result<Ref<T>, E>::Result(std::unique_ptr<E> error)
}
template <typename T, typename E>
Result<Ref<T>, E>::Result(Result<Ref<T>, E>&& other) : mPayload(other.mPayload) {
template <typename U>
Result<Ref<T>, E>::Result(Result<Ref<U>, E>&& other) : mPayload(other.mPayload) {
static_assert(std::is_convertible<U*, T*>::value, "");
other.mPayload = detail::kEmptyPayload;
}
template <typename T, typename E>
Result<Ref<T>, E>& Result<Ref<T>, E>::operator=(Result<Ref<T>, E>&& other) {
template <typename U>
Result<Ref<U>, E>& Result<Ref<T>, E>::operator=(Result<Ref<U>, E>&& other) {
static_assert(std::is_convertible<U*, T*>::value, "");
ASSERT(mPayload == detail::kEmptyPayload);
mPayload = other.mPayload;
other.mPayload = detail::kEmptyPayload;