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