Skip to content

Commit

Permalink
Add ostream operator for ExternalImageHandle (#8416)
Browse files Browse the repository at this point in the history
Without it, DEBUG_COMMAND_STREAM does not compile.
  • Loading branch information
poweifeng authored Feb 5, 2025
1 parent ea5d7d4 commit 8de56a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions filament/backend/include/backend/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class UTILS_PUBLIC Platform {

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&;
Expand Down
23 changes: 16 additions & 7 deletions filament/backend/src/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8de56a2

Please sign in to comment.