ConnectionFromClient.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashMap.h>
  8. #include <ImageDecoder/Forward.h>
  9. #include <ImageDecoder/ImageDecoderClientEndpoint.h>
  10. #include <ImageDecoder/ImageDecoderServerEndpoint.h>
  11. #include <LibIPC/ConnectionFromClient.h>
  12. #include <LibThreading/BackgroundAction.h>
  13. namespace ImageDecoder {
  14. class ConnectionFromClient final
  15. : public IPC::ConnectionFromClient<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint> {
  16. C_OBJECT(ConnectionFromClient);
  17. public:
  18. ~ConnectionFromClient() override = default;
  19. virtual void die() override;
  20. struct DecodeResult {
  21. bool is_animated = false;
  22. u32 loop_count = 0;
  23. Gfx::FloatPoint scale { 1, 1 };
  24. Vector<Gfx::ShareableBitmap> bitmaps;
  25. Vector<u32> durations;
  26. };
  27. private:
  28. using Job = Threading::BackgroundAction<DecodeResult>;
  29. explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>);
  30. virtual Messages::ImageDecoderServer::DecodeImageResponse decode_image(Core::AnonymousBuffer const&, Optional<Gfx::IntSize> const& ideal_size, Optional<ByteString> const& mime_type) override;
  31. virtual void cancel_decoding(i64 image_id) override;
  32. NonnullRefPtr<Job> make_decode_image_job(i64 image_id, Core::AnonymousBuffer, Optional<Gfx::IntSize> ideal_size, Optional<ByteString> mime_type);
  33. i64 m_next_image_id { 0 };
  34. HashMap<i64, NonnullRefPtr<Job>> m_pending_jobs;
  35. };
  36. }