fix [Pixel]BufferDescriptor functor callbacks
and attempt to make functor<->callback code less confusing.
This commit is contained in:
committed by
Mathias Agopian
parent
e8bed52b3f
commit
1a0b5ddc14
@@ -113,7 +113,7 @@ public:
|
||||
/**
|
||||
* Helper to create a BufferDescriptor that uses a KNOWN method pointer w/ object passed
|
||||
* by pointer as the callback. e.g.:
|
||||
* auto bd = BufferDescriptor::make(buffer, size, &Foo::method, foo);
|
||||
* auto bd = BufferDescriptor::make<Foo, &Foo::method>(buffer, size, foo);
|
||||
*
|
||||
* @param buffer Memory address of the CPU buffer to reference
|
||||
* @param size Size of the CPU buffer in bytes
|
||||
@@ -121,12 +121,12 @@ public:
|
||||
* @return a new BufferDescriptor
|
||||
*/
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
static BufferDescriptor make(
|
||||
void const* buffer, size_t size, T* data, CallbackHandler* handler = nullptr) noexcept {
|
||||
static BufferDescriptor make(void const* buffer, size_t size, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return {
|
||||
buffer, size,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
(*static_cast<T**>(u)->*method)(b, s);
|
||||
(static_cast<T*>(u)->*method)(b, s);
|
||||
}, data
|
||||
};
|
||||
}
|
||||
@@ -145,14 +145,14 @@ public:
|
||||
* @return a new BufferDescriptor
|
||||
*/
|
||||
template<typename T>
|
||||
static BufferDescriptor make(
|
||||
void const* buffer, size_t size, T&& functor, CallbackHandler* handler = nullptr) noexcept {
|
||||
static BufferDescriptor make(void const* buffer, size_t size, T&& functor,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return {
|
||||
buffer, size,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T& that = *static_cast<T*>(u);
|
||||
that(b, s);
|
||||
delete &that;
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
},
|
||||
new T(std::forward<T>(functor))
|
||||
};
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
return mUser;
|
||||
}
|
||||
|
||||
//! CPU mempry-buffer virtual address
|
||||
//! CPU memory-buffer virtual address
|
||||
void* buffer = nullptr;
|
||||
|
||||
//! CPU memory-buffer size in bytes
|
||||
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, alignment, left, top, stride,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
(*static_cast<T**>(u)->*method)(b, s); }, data };
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data };
|
||||
}
|
||||
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
PixelDataFormat format, PixelDataType type, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, handler, [](void* b, size_t s, void* u) {
|
||||
(*static_cast<T**>(u)->*method)(b, s); }, data };
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data };
|
||||
}
|
||||
|
||||
template<typename T, void(T::*method)(void const*, size_t)>
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
backend::CompressedPixelDataType format, uint32_t imageSize, T* data,
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, imageSize, handler, [](void* b, size_t s, void* u) {
|
||||
(*static_cast<T**>(u)->*method)(b, s); }, data
|
||||
(static_cast<T*>(u)->*method)(b, s); }, data
|
||||
};
|
||||
}
|
||||
|
||||
@@ -168,9 +168,9 @@ public:
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type, alignment, left, top, stride,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T& that = *static_cast<T*>(u);
|
||||
that(b, s);
|
||||
delete &that;
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
@@ -181,9 +181,9 @@ public:
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, type,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T& that = *static_cast<T*>(u);
|
||||
that(b, s);
|
||||
delete &that;
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
@@ -194,9 +194,9 @@ public:
|
||||
CallbackHandler* handler = nullptr) noexcept {
|
||||
return { buffer, size, format, imageSize,
|
||||
handler, [](void* b, size_t s, void* u) {
|
||||
T& that = *static_cast<T*>(u);
|
||||
that(b, s);
|
||||
delete &that;
|
||||
T* const that = static_cast<T*>(u);
|
||||
that->operator()(b, s);
|
||||
delete that;
|
||||
}, new T(std::forward<T>(functor))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -742,10 +742,10 @@ public:
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler.
|
||||
*/
|
||||
template<typename T, void(T::*method)(PickingQueryResult const&)>
|
||||
void pick(uint32_t x, uint32_t y, T* instance, backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
void pick(uint32_t x, uint32_t y, T* instance,
|
||||
backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
PickingQuery& query = pick(x, y, [](PickingQueryResult const& result, PickingQuery* pq) {
|
||||
void* user = pq->storage;
|
||||
(*static_cast<T**>(user)->*method)(result);
|
||||
(static_cast<T*>(pq->storage[0])->*method)(result);
|
||||
}, handler);
|
||||
query.storage[0] = instance;
|
||||
}
|
||||
@@ -762,11 +762,11 @@ public:
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler.
|
||||
*/
|
||||
template<typename T, void(T::*method)(PickingQueryResult const&)>
|
||||
void pick(uint32_t x, uint32_t y, T instance, backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
void pick(uint32_t x, uint32_t y, T instance,
|
||||
backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
static_assert(sizeof(instance) <= sizeof(PickingQuery::storage), "user data too large");
|
||||
PickingQuery& query = pick(x, y, [](PickingQueryResult const& result, PickingQuery* pq) {
|
||||
void* user = pq->storage;
|
||||
T* that = static_cast<T*>(user);
|
||||
T* const that = static_cast<T*>(reinterpret_cast<void*>(pq->storage));
|
||||
(that->*method)(result);
|
||||
that->~T();
|
||||
}, handler);
|
||||
@@ -783,15 +783,15 @@ public:
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler.
|
||||
*/
|
||||
template<typename T>
|
||||
void pick(uint32_t x, uint32_t y, T functor, backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
void pick(uint32_t x, uint32_t y, T functor,
|
||||
backend::CallbackHandler* handler = nullptr) noexcept {
|
||||
static_assert(sizeof(functor) <= sizeof(PickingQuery::storage), "functor too large");
|
||||
PickingQuery& query = pick(x, y, handler,
|
||||
(PickingQueryResultCallback)[](PickingQueryResult const& result, PickingQuery* pq) {
|
||||
void* user = pq->storage;
|
||||
T& that = *static_cast<T*>(user);
|
||||
that(result);
|
||||
that.~T();
|
||||
});
|
||||
T* const that = static_cast<T*>(reinterpret_cast<void*>(pq->storage));
|
||||
that->operator()(result);
|
||||
that->~T();
|
||||
});
|
||||
new(query.storage) T(std::move(functor));
|
||||
}
|
||||
|
||||
|
||||
@@ -169,8 +169,9 @@ public:
|
||||
// the caller must ensure the object will outlive the Job
|
||||
template<typename T, void(T::*method)(JobSystem&, Job*)>
|
||||
Job* createJob(Job* parent, T* data) noexcept {
|
||||
Job* job = create(parent, [](void* user, JobSystem& js, Job* job) {
|
||||
(*static_cast<T**>(user)->*method)(js, job);
|
||||
Job* job = create(parent, +[](void* storage, JobSystem& js, Job* job) {
|
||||
T* const that = static_cast<T*>(reinterpret_cast<void**>(storage)[0]);
|
||||
(that->*method)(js, job);
|
||||
});
|
||||
if (job) {
|
||||
job->storage[0] = data;
|
||||
@@ -182,8 +183,8 @@ public:
|
||||
template<typename T, void(T::*method)(JobSystem&, Job*)>
|
||||
Job* createJob(Job* parent, T data) noexcept {
|
||||
static_assert(sizeof(data) <= sizeof(Job::storage), "user data too large");
|
||||
Job* job = create(parent, [](void* user, JobSystem& js, Job* job) {
|
||||
T* that = static_cast<T*>(user);
|
||||
Job* job = create(parent, [](void* storage, JobSystem& js, Job* job) {
|
||||
T* const that = static_cast<T*>(storage);
|
||||
(that->*method)(js, job);
|
||||
that->~T();
|
||||
});
|
||||
@@ -197,10 +198,10 @@ public:
|
||||
template<typename T>
|
||||
Job* createJob(Job* parent, T functor) noexcept {
|
||||
static_assert(sizeof(functor) <= sizeof(Job::storage), "functor too large");
|
||||
Job* job = create(parent, [](void* user, JobSystem& js, Job* job){
|
||||
T& that = *static_cast<T*>(user);
|
||||
that(js, job);
|
||||
that.~T();
|
||||
Job* job = create(parent, [](void* storage, JobSystem& js, Job* job){
|
||||
T* const that = static_cast<T*>(storage);
|
||||
that->operator()(js, job);
|
||||
that->~T();
|
||||
});
|
||||
if (job) {
|
||||
new(job->storage) T(std::move(functor));
|
||||
@@ -252,7 +253,7 @@ public:
|
||||
void signal() noexcept;
|
||||
|
||||
/*
|
||||
* Add job to this thread's execution queue and and keep a reference to it.
|
||||
* Add job to this thread's execution queue and keep a reference to it.
|
||||
* Current thread must be owned by JobSystem's thread pool. See adopt().
|
||||
*
|
||||
* This job MUST BE waited on with wait(), or released with release().
|
||||
|
||||
Reference in New Issue
Block a user