1 #ifndef ANDROID_DVR_BUFFERHUBD_DETACHED_BUFFER_CHANNEL_H_ 2 #define ANDROID_DVR_BUFFERHUBD_DETACHED_BUFFER_CHANNEL_H_ 3 4 #include "buffer_hub.h" 5 6 #include <pdx/channel_handle.h> 7 #include <pdx/file_handle.h> 8 9 namespace android { 10 namespace dvr { 11 12 class DetachedBufferChannel : public BufferHubChannel { 13 public: 14 ~DetachedBufferChannel() override; 15 16 template <typename... Args> Create(Args &&...args)17 static std::unique_ptr<DetachedBufferChannel> Create(Args&&... args) { 18 auto buffer = std::unique_ptr<DetachedBufferChannel>( 19 new DetachedBufferChannel(std::forward<Args>(args)...)); 20 return buffer->IsValid() ? std::move(buffer) : nullptr; 21 } 22 23 // Returns whether the object holds a valid graphic buffer. IsValid()24 bool IsValid() const { 25 return buffer_.IsValid() && metadata_buffer_.IsValid(); 26 } 27 user_metadata_size()28 size_t user_metadata_size() const { return user_metadata_size_; } 29 30 // Captures buffer info for use by BufferHubService::DumpState(). 31 BufferInfo GetBufferInfo() const override; 32 33 bool HandleMessage(pdx::Message& message) override; 34 void HandleImpulse(pdx::Message& message) override; 35 36 private: 37 // Creates a detached buffer from existing IonBuffers. 38 DetachedBufferChannel(BufferHubService* service, int buffer_id, 39 int channel_id, IonBuffer buffer, 40 IonBuffer metadata_buffer, size_t user_metadata_size); 41 42 // Allocates a new detached buffer. 43 DetachedBufferChannel(BufferHubService* service, int buffer_id, 44 uint32_t width, uint32_t height, uint32_t layer_count, 45 uint32_t format, uint64_t usage, 46 size_t user_metadata_size); 47 48 pdx::Status<BufferDescription<pdx::BorrowedHandle>> OnImport( 49 pdx::Message& message); 50 pdx::Status<pdx::RemoteChannelHandle> OnPromote(pdx::Message& message); 51 52 // Gralloc buffer handles. 53 IonBuffer buffer_; 54 IonBuffer metadata_buffer_; 55 56 // Size of user requested metadata. 57 const size_t user_metadata_size_; 58 }; 59 60 } // namespace dvr 61 } // namespace android 62 63 #endif // ANDROID_DVR_BUFFERHUBD_DETACHED_BUFFER_CHANNEL_H_ 64