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