diff --git a/Thirdparty/libipc/lib/ipc.lib b/Thirdparty/libipc/lib/ipc.lib index 08b5007..e02ca1e 100644 Binary files a/Thirdparty/libipc/lib/ipc.lib and b/Thirdparty/libipc/lib/ipc.lib differ diff --git a/Thirdparty/libipc/lib/ipc_o.lib b/Thirdparty/libipc/lib/ipc_o.lib deleted file mode 100644 index aaf8557..0000000 Binary files a/Thirdparty/libipc/lib/ipc_o.lib and /dev/null differ diff --git a/Thirdparty/libipc/lib/ipcd.lib b/Thirdparty/libipc/lib/ipcd.lib index 3b74f95..7db619a 100644 Binary files a/Thirdparty/libipc/lib/ipcd.lib and b/Thirdparty/libipc/lib/ipcd.lib differ diff --git a/Thirdparty/libipc/lib/ipcd.pdb b/Thirdparty/libipc/lib/ipcd.pdb index 0b17c10..ae32c7d 100644 Binary files a/Thirdparty/libipc/lib/ipcd.pdb and b/Thirdparty/libipc/lib/ipcd.pdb differ diff --git a/src/Core/Core.h b/src/Core/Core.h index cb4add8..c2ce2bc 100644 --- a/src/Core/Core.h +++ b/src/Core/Core.h @@ -6,8 +6,8 @@ #include "Constant.h" #include "Logger.h" -#include "CriticalSection.h" -#include "ScopeLock.h" +#include "Thread/CriticalSection.h" +#include "Thread/ScopeLock.h" #include "Mesh.h" diff --git a/src/Core/CriticalSection.cpp b/src/Core/Thread/CriticalSection.cpp similarity index 81% rename from src/Core/CriticalSection.cpp rename to src/Core/Thread/CriticalSection.cpp index 8243bd6..3d94cb9 100644 --- a/src/Core/CriticalSection.cpp +++ b/src/Core/Thread/CriticalSection.cpp @@ -1,4 +1,4 @@ -#include "Core/CriticalSection.h" +#include "Core/Thread/CriticalSection.h" CriticalSection::CriticalSection() noexcept { diff --git a/src/Core/CriticalSection.h b/src/Core/Thread/CriticalSection.h similarity index 100% rename from src/Core/CriticalSection.h rename to src/Core/Thread/CriticalSection.h diff --git a/src/Core/ScopeLock.h b/src/Core/Thread/ScopeLock.h similarity index 100% rename from src/Core/ScopeLock.h rename to src/Core/Thread/ScopeLock.h diff --git a/src/Core/SpinLock.h b/src/Core/Thread/SpinLock.h similarity index 100% rename from src/Core/SpinLock.h rename to src/Core/Thread/SpinLock.h diff --git a/src/ImageBuffer.cpp b/src/ImageBuffer.cpp new file mode 100644 index 0000000..42f42d1 --- /dev/null +++ b/src/ImageBuffer.cpp @@ -0,0 +1,24 @@ +#include "ImageBuffer.h" + +#include "Core/Thread/ScopeLock.h" + +void ImageBuffer::PushImage(ImageBuffer::IBType type, std::vector data, + uint32 width, uint32 height, uint32 comp) { + switch (type) { + case ImageBuffer::IBType::Background: + PushBackgroundImage(std::move(data), width, height, comp); + break; + default: + break; + } +} + +void ImageBuffer::PushBackgroundImage(std::vector data, uint32 width, uint32 height, uint32 comp) { + ScopeLock lock(&cs_); + if (background_.size() >= 10) { + background_.pop(); + } + + Image newImage{ std::move(data), width, height, comp }; + background_.push(std::move(newImage)); +} diff --git a/src/ImageBuffer.h b/src/ImageBuffer.h new file mode 100644 index 0000000..ffe88be --- /dev/null +++ b/src/ImageBuffer.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include "Core/Core.h" +#include "Core/Singleton.h" + +class ImageBuffer : public Singleton { +public: + enum class IBType { + Background, + + }; +public: + explicit ImageBuffer() noexcept = default; + ~ImageBuffer() = default; + + ImageBuffer(const ImageBuffer&) = delete; + ImageBuffer& operator=(const ImageBuffer&) = delete; + + void PushImage(IBType type, std::vector data, uint32 width, uint32 height, uint32 comp); + +private: + void PushBackgroundImage(std::vector data, uint32 width, uint32 height, uint32 comp); + +private: + struct Image { + std::vector data; + uint32 width; + uint32 height; + uint32 comp; + }; + CriticalSection cs_; + std::queue background_; + + +}; diff --git a/src/Ipc/Ipc.cpp b/src/Ipc/Ipc.cpp index 2b1927b..a9a0bd7 100644 --- a/src/Ipc/Ipc.cpp +++ b/src/Ipc/Ipc.cpp @@ -1,6 +1,8 @@ #include "Ipc/Ipc.h" #include +#include +#include #include "Ipc/ReadCallback.h" @@ -15,8 +17,8 @@ std::shared_ptr Ipc::create(const char* reader_name, const char* writer_nam Ipc::Ipc(const char* reader_name, const char* writer_name) noexcept : reader_name_(reader_name) , writer_name_(writer_name) { - sender_ = std::make_unique(reader_name_.c_str(), ipc::sender); - printf("%s, %s", reader_name, writer_name); + sender_ = std::make_unique(toUtf8(reader_name_).c_str(), ipc::sender); + fprintf(stderr, "%s, %s\n", reader_name, writer_name); } Ipc::~Ipc() { @@ -101,3 +103,9 @@ void Ipc::onReciveer(const char* buffer, unsigned int size) { read->onRead(buffer, size); } } + +std::string Ipc::toUtf8(const std::string& str) { + std::wstring_convert> converter; + std::wstring wide_str = converter.from_bytes(str); + return converter.to_bytes(wide_str); +} diff --git a/src/Ipc/Ipc.h b/src/Ipc/Ipc.h index 5f54fc1..29242a7 100644 --- a/src/Ipc/Ipc.h +++ b/src/Ipc/Ipc.h @@ -31,6 +31,8 @@ private: void onReciveer(const char* buffer, unsigned int size); + std::string toUtf8(const std::string& str); + private: std::string reader_name_; std::string writer_name_; diff --git a/src/Ipc/IpcMoudle.cpp b/src/Ipc/IpcMoudle.cpp index e767b99..4085aee 100644 --- a/src/Ipc/IpcMoudle.cpp +++ b/src/Ipc/IpcMoudle.cpp @@ -1,10 +1,44 @@ #include "Ipc/IpcMoudle.h" +#include + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include + #include "Core/Core.h" #include "Ipc/ipclib.h" IpcMoudle* Singleton::instance_ = nullptr; +void OnParseImageData(const char* data, size_t size) { + if (size < 13) { // Minimum size check: 1 byte identifier + 4 bytes width + 4 bytes height + 4 bytes bit depth + std::cerr << "Invalid data size" << std::endl; + return; + } + + // Extract identifier + char identifier = data[0]; + + // Extract width + int width; + std::memcpy(&width, data + 1, sizeof(int)); + + // Extract height + int height; + std::memcpy(&height, data + 5, sizeof(int)); + + // Extract bit depth + int bit_depth; + std::memcpy(&bit_depth, data + 9, sizeof(int)); + + // Extract image bytes + const char* img_bytes = data + 13; + size_t img_size = size - 13; + + + // Further processing of img_bytes can be done here +} + bool IpcMoudle::Initialize() { if (!initialize("ipc_sender", "ipc_sender")) { ERRORLOG("ipc initialize failed"); @@ -12,7 +46,8 @@ bool IpcMoudle::Initialize() { } setReaderCallback([](const char* data, unsigned int size) { - INFOLOG("ipc recive data:{}", size); + //INFOLOG("ipc recive data:{}", size); + OnParseImageData(data, size); } ); diff --git a/src/Ipc/ipclib.cpp b/src/Ipc/ipclib.cpp index 5ca6c7d..84d55ae 100644 --- a/src/Ipc/ipclib.cpp +++ b/src/Ipc/ipclib.cpp @@ -11,7 +11,7 @@ public: ReaderCallback() = default; ~ReaderCallback() override = default; void onRead(const char* buffer, unsigned int size) override { - printf("%s", buffer); + //printf("%s", buffer); if (nullptr != m_readerCallbackFunc) { m_readerCallbackFunc(buffer, size); } diff --git a/src/Main.cpp b/src/Main.cpp index 597891f..b72462e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -9,7 +9,6 @@ #include #include "Core/Logger.h" -#include "Core/ScopeLock.h" #include "Ipc/IpcMoudle.h" #include "shader_s.h" diff --git a/src/RHI/RHI.cpp b/src/RHI/RHI.cpp index 6f929eb..96c85f2 100644 --- a/src/RHI/RHI.cpp +++ b/src/RHI/RHI.cpp @@ -1,7 +1,6 @@ #include "RHI/RHI.h" #include "Core/Core.h" -#include "Core/SpinLock.h" #include "OpenGLDrv/GLDrvAPI.h" #include "RHI/RHICommondList.h"