Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 1 | #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 | |
| 8 | namespace android { |
| 9 | namespace dvr { |
| 10 | |
| 11 | class DisplayService; |
| 12 | |
| 13 | class 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. |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame^] | 36 | virtual pdx::Status<void> HandleMessage(pdx::Message& message); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 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_ |