diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-16 23:58:57 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-16 23:58:57 +0100 |
commit | 447e6da52c319a012cd877346b936fb109f64527 (patch) | |
tree | ee6ce8720eb8c67b24869cd1c7866b9686f08f87 /Userland | |
parent | 8a61aba1e53d93521319be093eaff6d2e7db83b3 (diff) | |
download | serenity-447e6da52c319a012cd877346b936fb109f64527.zip |
ImageDecoder: Use Core::AnonymousBuffer and Gfx::ShareableBitmap
...instead of sending shbufs back and forth. :^)
Diffstat (limited to 'Userland')
4 files changed, 14 insertions, 58 deletions
diff --git a/Userland/Libraries/LibImageDecoderClient/Client.cpp b/Userland/Libraries/LibImageDecoderClient/Client.cpp index 0a50afc1b4..4b6a7325c9 100644 --- a/Userland/Libraries/LibImageDecoderClient/Client.cpp +++ b/Userland/Libraries/LibImageDecoderClient/Client.cpp @@ -24,7 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <AK/SharedBuffer.h> +#include <LibCore/AnonymousBuffer.h> #include <LibImageDecoderClient/Client.h> namespace ImageDecoderClient { @@ -51,38 +51,15 @@ RefPtr<Gfx::Bitmap> Client::decode_image(const ByteBuffer& encoded_data) if (encoded_data.is_empty()) return nullptr; - auto encoded_buffer = SharedBuffer::create_with_size(encoded_data.size()); - if (!encoded_buffer) { - dbgln("Could not allocate encoded shbuf"); + auto encoded_buffer = Core::AnonymousBuffer::create_with_size(encoded_data.size()); + if (!encoded_buffer.is_valid()) { + dbgln("Could not allocate encoded buffer"); return nullptr; } - memcpy(encoded_buffer->data<void>(), encoded_data.data(), encoded_data.size()); - - encoded_buffer->seal(); - encoded_buffer->share_with(server_pid()); - - auto response = send_sync<Messages::ImageDecoderServer::DecodeImage>(encoded_buffer->shbuf_id(), encoded_data.size()); - auto bitmap_format = (Gfx::BitmapFormat)response->bitmap_format(); - if (bitmap_format == Gfx::BitmapFormat::Invalid) { -#ifdef IMAGE_DECODER_CLIENT_DEBUG - dbgln("Response image was invalid"); -#endif - return nullptr; - } - - if (response->size().is_empty()) { - dbgln("Response image was empty"); - return nullptr; - } - - auto decoded_buffer = SharedBuffer::create_from_shbuf_id(response->decoded_shbuf_id()); - if (!decoded_buffer) { - dbgln("Could not map decoded image shbuf_id={}", response->decoded_shbuf_id()); - return nullptr; - } - - return Gfx::Bitmap::create_with_shared_buffer(bitmap_format, decoded_buffer.release_nonnull(), response->size(), response->palette()); + memcpy(encoded_buffer.data<void>(), encoded_data.data(), encoded_data.size()); + auto response = send_sync<Messages::ImageDecoderServer::DecodeImage>(move(encoded_buffer)); + return response->bitmap().bitmap(); } } diff --git a/Userland/Services/ImageDecoder/ClientConnection.cpp b/Userland/Services/ImageDecoder/ClientConnection.cpp index 1e516ccdb9..c52a221a5f 100644 --- a/Userland/Services/ImageDecoder/ClientConnection.cpp +++ b/Userland/Services/ImageDecoder/ClientConnection.cpp @@ -60,43 +60,25 @@ OwnPtr<Messages::ImageDecoderServer::GreetResponse> ClientConnection::handle(con OwnPtr<Messages::ImageDecoderServer::DecodeImageResponse> ClientConnection::handle(const Messages::ImageDecoderServer::DecodeImage& message) { - auto encoded_buffer = SharedBuffer::create_from_shbuf_id(message.encoded_shbuf_id()); - if (!encoded_buffer) { + auto encoded_buffer = message.data(); + if (!encoded_buffer.is_valid()) { #ifdef IMAGE_DECODER_DEBUG - dbgln("Could not map encoded data buffer"); + dbgln("Encoded data is invalid"); #endif return {}; } - if (message.encoded_size() > (size_t)encoded_buffer->size()) { -#ifdef IMAGE_DECODER_DEBUG - dbgln("Encoded buffer is smaller than encoded size"); -#endif - return {}; - } - -#ifdef IMAGE_DECODER_DEBUG - dbg() << "Trying to decode " << message.encoded_size() << " bytes of image(?) data in shbuf_id=" << message.encoded_shbuf_id() << " (shbuf size: " << encoded_buffer->size() << ")"; -#endif - - auto decoder = Gfx::ImageDecoder::create(encoded_buffer->data<u8>(), message.encoded_size()); + auto decoder = Gfx::ImageDecoder::create(encoded_buffer.data<u8>(), encoded_buffer.size()); auto bitmap = decoder->bitmap(); if (!bitmap) { #ifdef IMAGE_DECODER_DEBUG dbgln("Could not decode image from encoded data"); #endif - return make<Messages::ImageDecoderServer::DecodeImageResponse>(-1, Gfx::IntSize(), (i32)Gfx::BitmapFormat::Invalid, Vector<u32>()); + return make<Messages::ImageDecoderServer::DecodeImageResponse>(Gfx::ShareableBitmap()); } - // FIXME: We should fix ShareableBitmap so you can send it in responses as well as requests.. - m_shareable_bitmap = bitmap->to_bitmap_backed_by_shared_buffer(); - m_shareable_bitmap->shared_buffer()->share_with(client_pid()); - Vector<u32> palette; - if (m_shareable_bitmap->is_indexed()) { - palette = m_shareable_bitmap->palette_to_vector(); - } - return make<Messages::ImageDecoderServer::DecodeImageResponse>(m_shareable_bitmap->shbuf_id(), m_shareable_bitmap->size(), (i32)m_shareable_bitmap->format(), palette); + return make<Messages::ImageDecoderServer::DecodeImageResponse>(bitmap->to_shareable_bitmap()); } } diff --git a/Userland/Services/ImageDecoder/ClientConnection.h b/Userland/Services/ImageDecoder/ClientConnection.h index 1447c3b063..c5e5cfc8ce 100644 --- a/Userland/Services/ImageDecoder/ClientConnection.h +++ b/Userland/Services/ImageDecoder/ClientConnection.h @@ -49,8 +49,6 @@ public: private: virtual OwnPtr<Messages::ImageDecoderServer::GreetResponse> handle(const Messages::ImageDecoderServer::Greet&) override; virtual OwnPtr<Messages::ImageDecoderServer::DecodeImageResponse> handle(const Messages::ImageDecoderServer::DecodeImage&) override; - - RefPtr<Gfx::Bitmap> m_shareable_bitmap; }; } diff --git a/Userland/Services/ImageDecoder/ImageDecoderServer.ipc b/Userland/Services/ImageDecoder/ImageDecoderServer.ipc index 295454282f..fca8e979cd 100644 --- a/Userland/Services/ImageDecoder/ImageDecoderServer.ipc +++ b/Userland/Services/ImageDecoder/ImageDecoderServer.ipc @@ -2,6 +2,5 @@ endpoint ImageDecoderServer = 7001 { Greet(i32 client_pid) => (i32 client_id, i32 server_pid) - DecodeImage(i32 encoded_shbuf_id, u32 encoded_size) => (i32 decoded_shbuf_id, Gfx::IntSize size, i32 bitmap_format, Vector<u32> palette) - + DecodeImage(Core::AnonymousBuffer data) => (Gfx::ShareableBitmap bitmap) } |