From 8de56a2bbc0a3e9565c8b45804c1dafda427d3be Mon Sep 17 00:00:00 2001 From: Powei Feng Date: Wed, 5 Feb 2025 15:52:05 -0800 Subject: [PATCH] Add ostream operator for ExternalImageHandle (#8416) Without it, DEBUG_COMMAND_STREAM does not compile. --- filament/backend/include/backend/Platform.h | 4 ++++ filament/backend/src/Platform.cpp | 23 ++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/filament/backend/include/backend/Platform.h b/filament/backend/include/backend/Platform.h index 9fea71deeb..e017cb4edb 100644 --- a/filament/backend/include/backend/Platform.h +++ b/filament/backend/include/backend/Platform.h @@ -79,6 +79,10 @@ public: void clear() noexcept; void reset(ExternalImage* UTILS_NULLABLE p) noexcept; + + private: + friend utils::io::ostream& operator<<(utils::io::ostream& out, + ExternalImageHandle const& handle); }; using ExternalImageHandleRef = ExternalImageHandle const&; diff --git a/filament/backend/src/Platform.cpp b/filament/backend/src/Platform.cpp index b603155923..5618ed6367 100644 --- a/filament/backend/src/Platform.cpp +++ b/filament/backend/src/Platform.cpp @@ -35,12 +35,13 @@ void Platform::ExternalImageHandle::incref(ExternalImage* p) noexcept { void Platform::ExternalImageHandle::decref(ExternalImage* p) noexcept { if (p) { - // When decrementing the ref-count, unless it reaches zero, there is no need to acquire data; we need to - // release all previous writes though so they can be visible to the thread that will actually delete the - // object. + // When decrementing the ref-count, unless it reaches zero, there is no need to acquire + // data; we need to release all previous writes though so they can be visible to the thread + // that will actually delete the object. if (p->mRefCount.fetch_sub(1, std::memory_order_release) == 1) { - // if we reach zero, we're about to delete the object, we need to acquire all previous writes from other - // threads (i.e.: the memory from other threads prior to the decref() need to be visible now. + // if we reach zero, we're about to delete the object, we need to acquire all previous + // writes from other threads (i.e.: the memory from other threads prior to the decref() + // need to be visible now. std::atomic_thread_fence(std::memory_order_acquire); delete p; } @@ -68,7 +69,8 @@ Platform::ExternalImageHandle::ExternalImageHandle(ExternalImageHandle&& rhs) no rhs.mTarget = nullptr; } -Platform::ExternalImageHandle& Platform::ExternalImageHandle::operator=(ExternalImageHandle const& rhs) noexcept { +Platform::ExternalImageHandle& Platform::ExternalImageHandle::operator=( + ExternalImageHandle const& rhs) noexcept { if (UTILS_LIKELY(this != &rhs)) { incref(rhs.mTarget); decref(mTarget); @@ -77,7 +79,8 @@ Platform::ExternalImageHandle& Platform::ExternalImageHandle::operator=(External return *this; } -Platform::ExternalImageHandle& Platform::ExternalImageHandle::operator=(ExternalImageHandle&& rhs) noexcept { +Platform::ExternalImageHandle& Platform::ExternalImageHandle::operator=( + ExternalImageHandle&& rhs) noexcept { if (UTILS_LIKELY(this != &rhs)) { decref(mTarget); mTarget = rhs.mTarget; @@ -97,6 +100,12 @@ void Platform::ExternalImageHandle::reset(ExternalImage* p) noexcept { mTarget = p; } +utils::io::ostream& operator<<(utils::io::ostream& out, + Platform::ExternalImageHandle const& handle) { + out << "ExternalImageHandle{" << handle.mTarget << "}"; + return out; +} + // -------------------------------------------------------------------------------------------------------------------- Platform::ExternalImage::~ExternalImage() noexcept = default;