Home | History | Annotate | Download | only in libdisplay
      1 #include "include/private/dvr/display_manager_client.h"
      2 
      3 #include <pdx/default_transport/client_channel_factory.h>
      4 #include <private/dvr/buffer_hub_client.h>
      5 #include <private/dvr/buffer_hub_queue_client.h>
      6 #include <private/dvr/display_protocol.h>
      7 #include <utils/Log.h>
      8 
      9 using android::pdx::ErrorStatus;
     10 using android::pdx::LocalChannelHandle;
     11 using android::pdx::Transaction;
     12 
     13 namespace android {
     14 namespace dvr {
     15 namespace display {
     16 
     17 DisplayManagerClient::DisplayManagerClient()
     18     : BASE(pdx::default_transport::ClientChannelFactory::Create(
     19           DisplayManagerProtocol::kClientPath)) {}
     20 
     21 DisplayManagerClient::~DisplayManagerClient() {}
     22 
     23 pdx::Status<std::vector<display::SurfaceState>>
     24 DisplayManagerClient::GetSurfaceState() {
     25   auto status = InvokeRemoteMethod<DisplayManagerProtocol::GetSurfaceState>();
     26   if (!status) {
     27     ALOGE(
     28         "DisplayManagerClient::GetSurfaceState: Failed to get surface info: %s",
     29         status.GetErrorMessage().c_str());
     30   }
     31 
     32   return status;
     33 }
     34 
     35 pdx::Status<std::unique_ptr<IonBuffer>> DisplayManagerClient::SetupNamedBuffer(
     36     const std::string& name, size_t size, uint64_t usage) {
     37   auto status = InvokeRemoteMethod<DisplayManagerProtocol::SetupNamedBuffer>(
     38       name, size, usage);
     39   if (!status) {
     40     ALOGE(
     41         "DisplayManagerClient::SetupPoseBuffer: Failed to create the named "
     42         "buffer %s",
     43         status.GetErrorMessage().c_str());
     44     return status.error_status();
     45   }
     46 
     47   auto ion_buffer = std::make_unique<IonBuffer>();
     48   auto native_buffer_handle = status.take();
     49   const int ret = native_buffer_handle.Import(ion_buffer.get());
     50   if (ret < 0) {
     51     ALOGE(
     52         "DisplayClient::GetNamedBuffer: Failed to import named buffer: "
     53         "name=%s; error=%s",
     54         name.c_str(), strerror(-ret));
     55     return ErrorStatus(-ret);
     56   }
     57 
     58   return {std::move(ion_buffer)};
     59 }
     60 
     61 pdx::Status<std::unique_ptr<ConsumerQueue>>
     62 DisplayManagerClient::GetSurfaceQueue(int surface_id, int queue_id) {
     63   auto status = InvokeRemoteMethod<DisplayManagerProtocol::GetSurfaceQueue>(
     64       surface_id, queue_id);
     65   if (!status) {
     66     ALOGE(
     67         "DisplayManagerClient::GetSurfaceQueue: Failed to get queue for "
     68         "surface_id=%d queue_id=%d: %s",
     69         surface_id, queue_id, status.GetErrorMessage().c_str());
     70     return status.error_status();
     71   }
     72 
     73   return {ConsumerQueue::Import(status.take())};
     74 }
     75 
     76 }  // namespace display
     77 }  // namespace dvr
     78 }  // namespace android
     79