display_client.h revision 7480c060cb3466d97ec3125d61bbace153f534c8
1#ifndef ANDROID_DVR_DISPLAY_CLIENT_H_ 2#define ANDROID_DVR_DISPLAY_CLIENT_H_ 3 4#include <hardware/hwcomposer.h> 5#include <pdx/client.h> 6#include <pdx/file_handle.h> 7#include <private/dvr/buffer_hub_client.h> 8#include <private/dvr/buffer_hub_queue_client.h> 9#include <private/dvr/display_rpc.h> 10 11namespace android { 12namespace dvr { 13 14struct LateLatchOutput; 15 16// Abstract base class for all surface types maintained in DVR's display 17// service. 18// TODO(jwcai) Explain more, surface is a channel... 19class SurfaceClient : public pdx::Client { 20 public: 21 using LocalChannelHandle = pdx::LocalChannelHandle; 22 SurfaceType type() const { return type_; } 23 24 // Get the shared memory metadata buffer fd for this display surface. If it is 25 // not yet allocated, this will allocate it. 26 int GetMetadataBufferFd(pdx::LocalHandle* out_fd); 27 28 // Allocate the single metadata buffer for providing metadata associated with 29 // posted buffers for this surface. This can be used to provide rendered poses 30 // for EDS, for example. The buffer format is defined by the struct 31 // DisplaySurfaceMetadata. 32 // The first call to this method will allocate the buffer in via IPC to the 33 // display surface. 34 std::shared_ptr<BufferProducer> GetMetadataBuffer(); 35 36 protected: 37 SurfaceClient(LocalChannelHandle channel_handle, SurfaceType type); 38 SurfaceClient(const std::string& endpoint_path, SurfaceType type); 39 40 private: 41 SurfaceType type_; 42 std::shared_ptr<BufferProducer> metadata_buffer_; 43}; 44 45// DisplaySurfaceClient represents the client interface to a displayd display 46// surface. 47class DisplaySurfaceClient 48 : public pdx::ClientBase<DisplaySurfaceClient, SurfaceClient> { 49 public: 50 using LocalHandle = pdx::LocalHandle; 51 52 int width() const { return width_; } 53 int height() const { return height_; } 54 int format() const { return format_; } 55 int usage() const { return usage_; } 56 int flags() const { return flags_; } 57 int z_order() const { return z_order_; } 58 bool visible() const { return visible_; } 59 60 void SetVisible(bool visible); 61 void SetZOrder(int z_order); 62 void SetExcludeFromBlur(bool exclude_from_blur); 63 void SetBlurBehind(bool blur_behind); 64 void SetAttributes(const DisplaySurfaceAttributes& attributes); 65 66 // Get the producer end of the buffer queue that transports graphics buffer 67 // from the application side to the compositor side. 68 std::shared_ptr<ProducerQueue> GetProducerQueue(); 69 70 // Get the shared memory metadata buffer for this display surface. If it is 71 // not yet allocated, this will allocate it. 72 volatile DisplaySurfaceMetadata* GetMetadataBufferPtr(); 73 74 // Create a VideoMeshSurface that is attached to the display sruface. 75 LocalChannelHandle CreateVideoMeshSurface(); 76 77 private: 78 friend BASE; 79 80 DisplaySurfaceClient(int width, int height, int format, int usage, int flags); 81 82 int width_; 83 int height_; 84 int format_; 85 int usage_; 86 int flags_; 87 int z_order_; 88 bool visible_; 89 bool exclude_from_blur_; 90 bool blur_behind_; 91 DisplaySurfaceMetadata* mapped_metadata_buffer_; 92 93 // TODO(jwcai) Add support for multiple queues. 94 std::shared_ptr<ProducerQueue> producer_queue_; 95 96 DisplaySurfaceClient(const DisplaySurfaceClient&) = delete; 97 void operator=(const DisplaySurfaceClient&) = delete; 98}; 99 100class DisplayClient : public pdx::ClientBase<DisplayClient> { 101 public: 102 int GetDisplayMetrics(SystemDisplayMetrics* metrics); 103 pdx::Status<void> SetViewerParams(const ViewerParams& viewer_params); 104 105 // Pull the latest eds pose data from the display service renderer 106 int GetLastFrameEdsTransform(LateLatchOutput* ll_out); 107 108 int EnterVrMode(); 109 int ExitVrMode(); 110 111 std::unique_ptr<DisplaySurfaceClient> CreateDisplaySurface( 112 int width, int height, int format, int usage, int flags); 113 114 private: 115 friend BASE; 116 117 explicit DisplayClient(int* error = nullptr); 118 119 DisplayClient(const DisplayClient&) = delete; 120 void operator=(const DisplayClient&) = delete; 121}; 122 123} // namespace dvr 124} // namespace android 125 126#endif // ANDROID_DVR_DISPLAY_CLIENT_H_ 127