blob: 870e1a4f303ee4084eaf7988477e61beaf39339b [file] [log] [blame]
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08001#ifndef ANDROID_DVR_SERVICES_DISPLAYD_SURFACE_CHANNEL_H_
2#define ANDROID_DVR_SERVICES_DISPLAYD_SURFACE_CHANNEL_H_
3
4#include <pdx/service.h>
5#include <private/dvr/buffer_hub_client.h>
6#include <private/dvr/display_rpc.h>
7
8namespace android {
9namespace dvr {
10
11class DisplayService;
12
13class SurfaceChannel : public pdx::Channel {
14 public:
15 SurfaceChannel(DisplayService* service, int channel_id, SurfaceType type,
16 size_t metadata_size)
17 : service_(service),
18 surface_id_(channel_id),
19 type_(type),
20 metadata_size_(metadata_size) {}
21
22 ~SurfaceChannel() override = default;
23
24 DisplayService* service() const { return service_; }
25 int surface_id() const { return surface_id_; }
26 SurfaceType type() const { return type_; }
27 size_t metadata_size() const { return metadata_size_; }
28
29 pdx::LocalHandle GetMetadataBufferFd() {
30 return EnsureMetadataBuffer() ? metadata_buffer_->GetBlobFd()
31 : pdx::LocalHandle{};
32 }
33
34 // Dispatches surface channel messages to the appropriate handlers. This
35 // handler runs on the displayd message dispatch thread.
36 virtual int HandleMessage(pdx::Message& message);
37
38 protected:
39 // Contains the surface metadata.
40 std::shared_ptr<BufferProducer> metadata_buffer_;
41
42 // Returns the metadata buffer for this surface. The first call allocates the
43 // buffer, while subsequent calls return the same buffer.
44 pdx::BorrowedChannelHandle OnGetMetadataBuffer(pdx::Message& message);
45
46 // Allocates the single metadata buffer for this surface unless it is already
47 // allocated. Idempotent when called multiple times.
48 bool EnsureMetadataBuffer();
49
50 private:
51 DisplayService* service_;
52 int surface_id_;
53 SurfaceType type_;
54 size_t metadata_size_;
55
56 SurfaceChannel(const SurfaceChannel&) = delete;
57 void operator=(const SurfaceChannel&) = delete;
58};
59
60} // namespace dvr
61} // namespace android
62
63#endif // ANDROID_DVR_SERVICES_DISPLAYD_SURFACE_CHANNEL_H_