Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 1 | #include "display_service.h" |
| 2 | |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 3 | #include <unistd.h> |
Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 4 | |
| 5 | #include <algorithm> |
| 6 | #include <sstream> |
| 7 | #include <string> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 10 | #include <android-base/file.h> |
| 11 | #include <android-base/properties.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 12 | #include <dvr/dvr_display_types.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 13 | #include <pdx/default_transport/service_endpoint.h> |
| 14 | #include <pdx/rpc/remote_method.h> |
Corey Tabaka | 99c2d73 | 2017-06-07 17:54:33 -0700 | [diff] [blame] | 15 | #include <private/android_filesystem_config.h> |
Corey Tabaka | 3f82d31 | 2017-04-20 14:42:08 -0700 | [diff] [blame] | 16 | #include <private/dvr/display_protocol.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 17 | #include <private/dvr/numeric.h> |
Corey Tabaka | 99c2d73 | 2017-06-07 17:54:33 -0700 | [diff] [blame] | 18 | #include <private/dvr/trusted_uids.h> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 19 | #include <private/dvr/types.h> |
| 20 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 21 | using android::dvr::display::DisplayProtocol; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 22 | using android::pdx::Channel; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 23 | using android::pdx::ErrorStatus; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 24 | using android::pdx::Message; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 25 | using android::pdx::Status; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 26 | using android::pdx::default_transport::Endpoint; |
| 27 | using android::pdx::rpc::DispatchRemoteMethod; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 28 | |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | const char kDvrLensMetricsProperty[] = "ro.dvr.lens_metrics"; |
| 32 | const char kDvrDeviceMetricsProperty[] = "ro.dvr.device_metrics"; |
| 33 | const char kDvrDeviceConfigProperty[] = "ro.dvr.device_configuration"; |
| 34 | |
| 35 | } // namespace |
| 36 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | namespace dvr { |
| 39 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 40 | DisplayService::DisplayService(Hwc2::Composer* hidl, |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 41 | hwc2_display_t primary_display_id, |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 42 | RequestDisplayCallback request_display_callback) |
| 43 | : BASE("DisplayService", |
Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 44 | Endpoint::Create(display::DisplayProtocol::kClientPath)) { |
Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 45 | hardware_composer_.Initialize( |
| 46 | hidl, primary_display_id, request_display_callback); |
mamik | a08194b | 2019-07-25 13:07:21 -0700 | [diff] [blame] | 47 | |
| 48 | uint8_t port; |
| 49 | const auto error = hidl->getDisplayIdentificationData( |
| 50 | primary_display_id, &port, &display_identification_data_); |
| 51 | if (error != android::hardware::graphics::composer::V2_1::Error::NONE) { |
| 52 | if (error != |
| 53 | android::hardware::graphics::composer::V2_1::Error::UNSUPPORTED) { |
| 54 | ALOGI("DisplayService: identification data error\n"); |
| 55 | } else { |
| 56 | ALOGI("DisplayService: identification data unsupported\n"); |
| 57 | } |
| 58 | } |
Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bool DisplayService::IsInitialized() const { |
| 62 | return BASE::IsInitialized() && hardware_composer_.IsInitialized(); |
| 63 | } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 64 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 65 | std::string DisplayService::DumpState(size_t /*max_length*/) { |
Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 66 | std::ostringstream stream; |
| 67 | |
| 68 | auto surfaces = GetDisplaySurfaces(); |
| 69 | std::sort(surfaces.begin(), surfaces.end(), [](const auto& a, const auto& b) { |
| 70 | return a->surface_id() < b->surface_id(); |
| 71 | }); |
| 72 | |
| 73 | stream << "Application Surfaces:" << std::endl; |
| 74 | |
| 75 | size_t count = 0; |
| 76 | for (const auto& surface : surfaces) { |
| 77 | if (surface->surface_type() == SurfaceType::Application) { |
| 78 | stream << "Surface " << count++ << ":"; |
| 79 | stream << " surface_id=" << surface->surface_id() |
| 80 | << " process_id=" << surface->process_id() |
| 81 | << " user_id=" << surface->user_id() |
| 82 | << " visible=" << surface->visible() |
| 83 | << " z_order=" << surface->z_order(); |
| 84 | |
| 85 | stream << " queue_ids="; |
| 86 | auto queue_ids = surface->GetQueueIds(); |
| 87 | std::sort(queue_ids.begin(), queue_ids.end()); |
| 88 | for (int32_t id : queue_ids) { |
| 89 | if (id != queue_ids[0]) |
| 90 | stream << ","; |
| 91 | stream << id; |
| 92 | } |
| 93 | stream << std::endl; |
| 94 | } |
| 95 | } |
| 96 | stream << std::endl; |
| 97 | |
| 98 | stream << "Direct Surfaces:" << std::endl; |
| 99 | |
| 100 | count = 0; |
| 101 | for (const auto& surface : surfaces) { |
| 102 | if (surface->surface_type() == SurfaceType::Direct) { |
| 103 | stream << "Surface " << count++ << ":"; |
| 104 | stream << " surface_id=" << surface->surface_id() |
| 105 | << " process_id=" << surface->process_id() |
| 106 | << " user_id=" << surface->user_id() |
| 107 | << " visible=" << surface->visible() |
| 108 | << " z_order=" << surface->z_order(); |
| 109 | |
| 110 | stream << " queue_ids="; |
| 111 | auto queue_ids = surface->GetQueueIds(); |
| 112 | std::sort(queue_ids.begin(), queue_ids.end()); |
| 113 | for (int32_t id : queue_ids) { |
| 114 | if (id != queue_ids[0]) |
| 115 | stream << ","; |
| 116 | stream << id; |
| 117 | } |
| 118 | stream << std::endl; |
| 119 | } |
| 120 | } |
| 121 | stream << std::endl; |
| 122 | |
| 123 | stream << hardware_composer_.Dump(); |
| 124 | return stream.str(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 127 | void DisplayService::OnChannelClose(pdx::Message& message, |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 128 | const std::shared_ptr<Channel>& channel) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 129 | if (auto surface = std::static_pointer_cast<DisplaySurface>(channel)) { |
| 130 | surface->OnSetAttributes(message, |
| 131 | {{display::SurfaceAttribute::Visible, |
| 132 | display::SurfaceAttributeValue{false}}}); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 133 | } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | // First-level dispatch for display service messages. Directly handles messages |
| 137 | // that are independent of the display surface (metrics, creation) and routes |
| 138 | // surface-specific messages to the per-instance handlers. |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 139 | Status<void> DisplayService::HandleMessage(pdx::Message& message) { |
| 140 | ALOGD_IF(TRACE, "DisplayService::HandleMessage: opcode=%d", message.GetOp()); |
Corey Tabaka | b3732f0 | 2017-09-16 00:58:54 -0700 | [diff] [blame] | 141 | ATRACE_NAME("DisplayService::HandleMessage"); |
| 142 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 143 | switch (message.GetOp()) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 144 | case DisplayProtocol::GetMetrics::Opcode: |
| 145 | DispatchRemoteMethod<DisplayProtocol::GetMetrics>( |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 146 | *this, &DisplayService::OnGetMetrics, message); |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 147 | return {}; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 148 | |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 149 | case DisplayProtocol::GetConfigurationData::Opcode: |
| 150 | DispatchRemoteMethod<DisplayProtocol::GetConfigurationData>( |
| 151 | *this, &DisplayService::OnGetConfigurationData, message); |
| 152 | return {}; |
| 153 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 154 | case DisplayProtocol::CreateSurface::Opcode: |
| 155 | DispatchRemoteMethod<DisplayProtocol::CreateSurface>( |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 156 | *this, &DisplayService::OnCreateSurface, message); |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 157 | return {}; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 158 | |
Corey Tabaka | 99c2d73 | 2017-06-07 17:54:33 -0700 | [diff] [blame] | 159 | case DisplayProtocol::SetupGlobalBuffer::Opcode: |
| 160 | DispatchRemoteMethod<DisplayProtocol::SetupGlobalBuffer>( |
| 161 | *this, &DisplayService::OnSetupGlobalBuffer, message); |
| 162 | return {}; |
| 163 | |
| 164 | case DisplayProtocol::DeleteGlobalBuffer::Opcode: |
| 165 | DispatchRemoteMethod<DisplayProtocol::DeleteGlobalBuffer>( |
| 166 | *this, &DisplayService::OnDeleteGlobalBuffer, message); |
| 167 | return {}; |
| 168 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 169 | case DisplayProtocol::GetGlobalBuffer::Opcode: |
| 170 | DispatchRemoteMethod<DisplayProtocol::GetGlobalBuffer>( |
| 171 | *this, &DisplayService::OnGetGlobalBuffer, message); |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 172 | return {}; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 173 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 174 | case DisplayProtocol::IsVrAppRunning::Opcode: |
| 175 | DispatchRemoteMethod<DisplayProtocol::IsVrAppRunning>( |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 176 | *this, &DisplayService::IsVrAppRunning, message); |
Alex Vakulenko | f0a7bd0 | 2017-03-31 18:06:19 -0700 | [diff] [blame] | 177 | return {}; |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 178 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 179 | // Direct the surface specific messages to the surface instance. |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 180 | case DisplayProtocol::SetAttributes::Opcode: |
| 181 | case DisplayProtocol::CreateQueue::Opcode: |
| 182 | case DisplayProtocol::GetSurfaceInfo::Opcode: |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 183 | return HandleSurfaceMessage(message); |
| 184 | |
| 185 | default: |
| 186 | return Service::HandleMessage(message); |
| 187 | } |
| 188 | } |
| 189 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 190 | Status<display::Metrics> DisplayService::OnGetMetrics( |
| 191 | pdx::Message& /*message*/) { |
Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 192 | const auto& params = hardware_composer_.GetPrimaryDisplayParams(); |
| 193 | return {{static_cast<uint32_t>(params.width), |
| 194 | static_cast<uint32_t>(params.height), |
| 195 | static_cast<uint32_t>(params.dpi.x), |
| 196 | static_cast<uint32_t>(params.dpi.y), |
| 197 | static_cast<uint32_t>(params.vsync_period_ns), |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 198 | 0, |
| 199 | 0, |
| 200 | 0, |
| 201 | 0.0, |
| 202 | {}, |
| 203 | {}}}; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 206 | pdx::Status<std::string> DisplayService::OnGetConfigurationData( |
| 207 | pdx::Message& /*message*/, display::ConfigFileType config_type) { |
| 208 | std::string property_name; |
| 209 | switch (config_type) { |
| 210 | case display::ConfigFileType::kLensMetrics: |
| 211 | property_name = kDvrLensMetricsProperty; |
| 212 | break; |
| 213 | case display::ConfigFileType::kDeviceMetrics: |
| 214 | property_name = kDvrDeviceMetricsProperty; |
| 215 | break; |
| 216 | case display::ConfigFileType::kDeviceConfiguration: |
| 217 | property_name = kDvrDeviceConfigProperty; |
| 218 | break; |
mamik | a08194b | 2019-07-25 13:07:21 -0700 | [diff] [blame] | 219 | case display::ConfigFileType::kDeviceEdid: |
| 220 | if (display_identification_data_.size() == 0) { |
| 221 | return ErrorStatus(ENOENT); |
| 222 | } |
| 223 | return std::string(display_identification_data_.begin(), |
| 224 | display_identification_data_.end()); |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 225 | default: |
| 226 | return ErrorStatus(EINVAL); |
| 227 | } |
| 228 | std::string file_path = base::GetProperty(property_name, ""); |
| 229 | if (file_path.empty()) { |
| 230 | return ErrorStatus(ENOENT); |
| 231 | } |
| 232 | |
| 233 | std::string data; |
| 234 | if (!base::ReadFileToString(file_path, &data)) { |
| 235 | return ErrorStatus(errno); |
| 236 | } |
| 237 | |
| 238 | return std::move(data); |
| 239 | } |
| 240 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 241 | // Creates a new DisplaySurface and associates it with this channel. This may |
| 242 | // only be done once per channel. |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 243 | Status<display::SurfaceInfo> DisplayService::OnCreateSurface( |
| 244 | pdx::Message& message, const display::SurfaceAttributes& attributes) { |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 245 | // A surface may only be created once per channel. |
| 246 | if (message.GetChannel()) |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 247 | return ErrorStatus(EINVAL); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 248 | |
| 249 | ALOGI_IF(TRACE, "DisplayService::OnCreateSurface: cid=%d", |
| 250 | message.GetChannelId()); |
| 251 | |
| 252 | // Use the channel id as the unique surface id. |
| 253 | const int surface_id = message.GetChannelId(); |
| 254 | const int process_id = message.GetProcessId(); |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 255 | const int user_id = message.GetEffectiveUserId(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 256 | |
| 257 | ALOGI_IF(TRACE, |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 258 | "DisplayService::OnCreateSurface: surface_id=%d process_id=%d", |
| 259 | surface_id, process_id); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 260 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 261 | auto surface_status = |
| 262 | DisplaySurface::Create(this, surface_id, process_id, user_id, attributes); |
| 263 | if (!surface_status) { |
| 264 | ALOGE("DisplayService::OnCreateSurface: Failed to create surface: %s", |
| 265 | surface_status.GetErrorMessage().c_str()); |
| 266 | return ErrorStatus(surface_status.error()); |
| 267 | } |
Corey Tabaka | 00d9bb3 | 2017-08-16 19:59:48 -0700 | [diff] [blame] | 268 | auto surface = surface_status.take(); |
| 269 | message.SetChannel(surface); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 270 | |
Corey Tabaka | 00d9bb3 | 2017-08-16 19:59:48 -0700 | [diff] [blame] | 271 | // Update the surface with the attributes supplied with the create call. For |
| 272 | // application surfaces this has the side effect of notifying the display |
| 273 | // manager of the new surface. For direct surfaces, this may trigger a mode |
| 274 | // change, depending on the value of the visible attribute. |
| 275 | surface->OnSetAttributes(message, attributes); |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 276 | |
Corey Tabaka | 00d9bb3 | 2017-08-16 19:59:48 -0700 | [diff] [blame] | 277 | return {{surface->surface_id(), surface->visible(), surface->z_order()}}; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 280 | void DisplayService::SurfaceUpdated(SurfaceType surface_type, |
| 281 | display::SurfaceUpdateFlags update_flags) { |
| 282 | ALOGD_IF(TRACE, "DisplayService::SurfaceUpdated: update_flags=%x", |
| 283 | update_flags.value()); |
| 284 | if (update_flags.value() != 0) { |
| 285 | if (surface_type == SurfaceType::Application) |
| 286 | NotifyDisplayConfigurationUpdate(); |
| 287 | else |
| 288 | UpdateActiveDisplaySurfaces(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 289 | } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Corey Tabaka | 99c2d73 | 2017-06-07 17:54:33 -0700 | [diff] [blame] | 292 | pdx::Status<BorrowedNativeBufferHandle> DisplayService::OnSetupGlobalBuffer( |
| 293 | pdx::Message& message, DvrGlobalBufferKey key, size_t size, |
| 294 | uint64_t usage) { |
| 295 | const int user_id = message.GetEffectiveUserId(); |
| 296 | const bool trusted = user_id == AID_ROOT || IsTrustedUid(user_id); |
| 297 | |
| 298 | if (!trusted) { |
| 299 | ALOGE( |
| 300 | "DisplayService::OnSetupGlobalBuffer: Permission denied for user_id=%d", |
| 301 | user_id); |
| 302 | return ErrorStatus(EPERM); |
| 303 | } |
| 304 | return SetupGlobalBuffer(key, size, usage); |
| 305 | } |
| 306 | |
| 307 | pdx::Status<void> DisplayService::OnDeleteGlobalBuffer(pdx::Message& message, |
| 308 | DvrGlobalBufferKey key) { |
| 309 | const int user_id = message.GetEffectiveUserId(); |
| 310 | const bool trusted = (user_id == AID_ROOT) || IsTrustedUid(user_id); |
| 311 | |
| 312 | if (!trusted) { |
| 313 | ALOGE( |
| 314 | "DisplayService::OnDeleteGlobalBuffer: Permission denied for " |
| 315 | "user_id=%d", |
| 316 | user_id); |
| 317 | return ErrorStatus(EPERM); |
| 318 | } |
| 319 | return DeleteGlobalBuffer(key); |
| 320 | } |
| 321 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 322 | pdx::Status<BorrowedNativeBufferHandle> DisplayService::OnGetGlobalBuffer( |
| 323 | pdx::Message& /* message */, DvrGlobalBufferKey key) { |
| 324 | ALOGD_IF(TRACE, "DisplayService::OnGetGlobalBuffer: key=%d", key); |
| 325 | auto global_buffer = global_buffers_.find(key); |
| 326 | if (global_buffer != global_buffers_.end()) |
| 327 | return {BorrowedNativeBufferHandle(*global_buffer->second, 0)}; |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 328 | else |
| 329 | return pdx::ErrorStatus(EINVAL); |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 332 | // Calls the message handler for the DisplaySurface associated with this |
| 333 | // channel. |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 334 | Status<void> DisplayService::HandleSurfaceMessage(pdx::Message& message) { |
| 335 | auto surface = std::static_pointer_cast<DisplaySurface>(message.GetChannel()); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 336 | ALOGW_IF(!surface, |
| 337 | "DisplayService::HandleSurfaceMessage: surface is nullptr!"); |
| 338 | |
| 339 | if (surface) |
| 340 | return surface->HandleMessage(message); |
| 341 | else |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 342 | return ErrorStatus(EINVAL); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | std::shared_ptr<DisplaySurface> DisplayService::GetDisplaySurface( |
| 346 | int surface_id) const { |
| 347 | return std::static_pointer_cast<DisplaySurface>(GetChannel(surface_id)); |
| 348 | } |
| 349 | |
| 350 | std::vector<std::shared_ptr<DisplaySurface>> |
| 351 | DisplayService::GetDisplaySurfaces() const { |
| 352 | return GetChannels<DisplaySurface>(); |
| 353 | } |
| 354 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 355 | std::vector<std::shared_ptr<DirectDisplaySurface>> |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 356 | DisplayService::GetVisibleDisplaySurfaces() const { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 357 | std::vector<std::shared_ptr<DirectDisplaySurface>> visible_surfaces; |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 358 | |
| 359 | ForEachDisplaySurface( |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 360 | SurfaceType::Direct, |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 361 | [&](const std::shared_ptr<DisplaySurface>& surface) mutable { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 362 | if (surface->visible()) { |
| 363 | visible_surfaces.push_back( |
| 364 | std::static_pointer_cast<DirectDisplaySurface>(surface)); |
| 365 | surface->ClearUpdate(); |
| 366 | } |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 367 | }); |
| 368 | |
| 369 | return visible_surfaces; |
| 370 | } |
| 371 | |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 372 | void DisplayService::UpdateActiveDisplaySurfaces() { |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 373 | auto visible_surfaces = GetVisibleDisplaySurfaces(); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 374 | ALOGD_IF(TRACE, |
| 375 | "DisplayService::UpdateActiveDisplaySurfaces: %zd visible surfaces", |
| 376 | visible_surfaces.size()); |
Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 377 | hardware_composer_.SetDisplaySurfaces(std::move(visible_surfaces)); |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 380 | pdx::Status<BorrowedNativeBufferHandle> DisplayService::SetupGlobalBuffer( |
| 381 | DvrGlobalBufferKey key, size_t size, uint64_t usage) { |
| 382 | auto global_buffer = global_buffers_.find(key); |
| 383 | if (global_buffer == global_buffers_.end()) { |
Jiwen 'Steve' Cai | 0057fdd | 2017-05-02 11:21:18 -0700 | [diff] [blame] | 384 | auto ion_buffer = std::make_unique<IonBuffer>(static_cast<int>(size), 1, |
| 385 | HAL_PIXEL_FORMAT_BLOB, usage); |
John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 386 | |
| 387 | // Some buffers are used internally. If they were configured with an |
| 388 | // invalid size or format, this will fail. |
| 389 | int result = hardware_composer_.OnNewGlobalBuffer(key, *ion_buffer.get()); |
| 390 | if (result < 0) |
| 391 | return ErrorStatus(result); |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 392 | global_buffer = |
| 393 | global_buffers_.insert(std::make_pair(key, std::move(ion_buffer))) |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 394 | .first; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Okan Arikan | 36d2380 | 2017-05-15 15:20:39 -0700 | [diff] [blame] | 397 | return {BorrowedNativeBufferHandle(*global_buffer->second, 0)}; |
Hendrik Wagenaar | 10e68eb | 2017-03-15 13:29:02 -0700 | [diff] [blame] | 398 | } |
| 399 | |
John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 400 | pdx::Status<void> DisplayService::DeleteGlobalBuffer(DvrGlobalBufferKey key) { |
| 401 | auto global_buffer = global_buffers_.find(key); |
| 402 | if (global_buffer != global_buffers_.end()) { |
| 403 | // Some buffers are used internally. |
| 404 | hardware_composer_.OnDeletedGlobalBuffer(key); |
| 405 | global_buffers_.erase(global_buffer); |
| 406 | } |
| 407 | |
| 408 | return {0}; |
| 409 | } |
| 410 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 411 | void DisplayService::SetDisplayConfigurationUpdateNotifier( |
| 412 | DisplayConfigurationUpdateNotifier update_notifier) { |
| 413 | update_notifier_ = update_notifier; |
| 414 | } |
| 415 | |
| 416 | void DisplayService::NotifyDisplayConfigurationUpdate() { |
| 417 | if (update_notifier_) |
| 418 | update_notifier_(); |
| 419 | } |
| 420 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 421 | Status<bool> DisplayService::IsVrAppRunning(pdx::Message& /*message*/) { |
Albert Chaulk | 356bc37 | 2017-04-05 18:01:58 -0400 | [diff] [blame] | 422 | bool visible = false; |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 423 | ForEachDisplaySurface( |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 424 | SurfaceType::Application, |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 425 | [&visible](const std::shared_ptr<DisplaySurface>& surface) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 426 | if (surface->visible()) |
Hendrik Wagenaar | eaa5522 | 2017-04-06 10:56:23 -0700 | [diff] [blame] | 427 | visible = true; |
| 428 | }); |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 429 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 430 | return {visible}; |
Albert Chaulk | b7c8a4b | 2017-03-20 13:03:39 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 433 | } // namespace dvr |
| 434 | } // namespace android |