Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 18 | #define LOG_TAG "hwcomposer-drm" |
| 19 | |
Zach Reizner | 7642c92 | 2015-10-29 10:11:16 -0700 | [diff] [blame] | 20 | #include "drmhwcomposer.h" |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 21 | #include "drmeventlistener.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 22 | #include "drmresources.h" |
Sean Paul | 6376996 | 2016-04-21 16:25:06 -0400 | [diff] [blame] | 23 | #include "platform.h" |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 24 | #include "virtualcompositorworker.h" |
Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 25 | #include "vsyncworker.h" |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 26 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 29 | #include <cinttypes> |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 30 | #include <map> |
| 31 | #include <vector> |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 32 | #include <sstream> |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 33 | |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 34 | #include <errno.h> |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 35 | #include <fcntl.h> |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 36 | #include <sys/param.h> |
Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 37 | #include <sys/resource.h> |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 38 | #include <xf86drm.h> |
| 39 | #include <xf86drmMode.h> |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 40 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 41 | #include <cutils/log.h> |
| 42 | #include <cutils/properties.h> |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 43 | #include <hardware/hardware.h> |
| 44 | #include <hardware/hwcomposer.h> |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 45 | #include <sw_sync.h> |
| 46 | #include <sync/sync.h> |
Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 47 | #include <utils/Trace.h> |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 48 | |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 49 | #define UM_PER_INCH 25400 |
| 50 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 51 | namespace android { |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 52 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 53 | class DummySwSyncTimeline { |
| 54 | public: |
| 55 | int Init() { |
| 56 | int ret = timeline_fd_.Set(sw_sync_timeline_create()); |
| 57 | if (ret < 0) |
| 58 | return ret; |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | UniqueFd CreateDummyFence() { |
| 63 | int ret = sw_sync_fence_create(timeline_fd_.get(), "dummy fence", |
| 64 | timeline_pt_ + 1); |
| 65 | if (ret < 0) { |
| 66 | ALOGE("Failed to create dummy fence %d", ret); |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | UniqueFd ret_fd(ret); |
| 71 | |
| 72 | ret = sw_sync_timeline_inc(timeline_fd_.get(), 1); |
| 73 | if (ret) { |
| 74 | ALOGE("Failed to increment dummy sync timeline %d", ret); |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | ++timeline_pt_; |
| 79 | return ret_fd; |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | UniqueFd timeline_fd_; |
| 84 | int timeline_pt_ = 0; |
| 85 | }; |
| 86 | |
| 87 | struct CheckedOutputFd { |
| 88 | CheckedOutputFd(int *fd, const char *description, |
| 89 | DummySwSyncTimeline &timeline) |
| 90 | : fd_(fd), description_(description), timeline_(timeline) { |
| 91 | } |
| 92 | CheckedOutputFd(CheckedOutputFd &&rhs) |
| 93 | : description_(rhs.description_), timeline_(rhs.timeline_) { |
| 94 | std::swap(fd_, rhs.fd_); |
| 95 | } |
| 96 | |
| 97 | CheckedOutputFd &operator=(const CheckedOutputFd &rhs) = delete; |
| 98 | |
| 99 | ~CheckedOutputFd() { |
| 100 | if (fd_ == NULL) |
| 101 | return; |
| 102 | |
| 103 | if (*fd_ >= 0) |
| 104 | return; |
| 105 | |
| 106 | *fd_ = timeline_.CreateDummyFence().Release(); |
| 107 | |
| 108 | if (*fd_ < 0) |
| 109 | ALOGE("Failed to fill %s (%p == %d) before destruction", |
| 110 | description_.c_str(), fd_, *fd_); |
| 111 | } |
| 112 | |
| 113 | private: |
| 114 | int *fd_ = NULL; |
| 115 | std::string description_; |
| 116 | DummySwSyncTimeline &timeline_; |
| 117 | }; |
| 118 | |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 119 | typedef struct hwc_drm_display { |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 120 | struct hwc_context_t *ctx; |
| 121 | int display; |
Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 122 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 123 | std::vector<uint32_t> config_ids; |
Sean Paul | 9aa5ad3 | 2015-01-22 15:47:54 -0500 | [diff] [blame] | 124 | |
Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 125 | VSyncWorker vsync_worker; |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 126 | } hwc_drm_display_t; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 127 | |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 128 | class DrmHotplugHandler : public DrmEventHandler { |
| 129 | public: |
| 130 | void Init(DrmResources *drm, const struct hwc_procs *procs) { |
| 131 | drm_ = drm; |
| 132 | procs_ = procs; |
| 133 | } |
| 134 | |
| 135 | void HandleEvent(uint64_t timestamp_us) { |
| 136 | for (auto &conn : drm_->connectors()) { |
| 137 | drmModeConnection old_state = conn->state(); |
| 138 | |
| 139 | conn->UpdateModes(); |
| 140 | |
| 141 | drmModeConnection cur_state = conn->state(); |
| 142 | |
| 143 | if (cur_state == old_state) |
| 144 | continue; |
| 145 | |
| 146 | ALOGI("%s event @%" PRIu64 " for connector %u\n", |
| 147 | cur_state == DRM_MODE_CONNECTED ? "Plug" : "Unplug", timestamp_us, |
| 148 | conn->id()); |
| 149 | |
| 150 | if (cur_state == DRM_MODE_CONNECTED) { |
| 151 | // Take the first one, then look for the preferred |
| 152 | DrmMode mode = *(conn->modes().begin()); |
| 153 | for (auto &m : conn->modes()) { |
| 154 | if (m.type() & DRM_MODE_TYPE_PREFERRED) { |
| 155 | mode = m; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | ALOGI("Setting mode %dx%d for connector %d\n", mode.h_display(), |
| 160 | mode.v_display(), conn->id()); |
| 161 | int ret = drm_->SetDisplayActiveMode(conn->display(), mode); |
| 162 | if (ret) { |
| 163 | ALOGE("Failed to set active config %d", ret); |
| 164 | return; |
| 165 | } |
| 166 | } else { |
| 167 | int ret = drm_->SetDpmsMode(conn->display(), DRM_MODE_DPMS_OFF); |
| 168 | if (ret) { |
| 169 | ALOGE("Failed to set dpms mode off %d", ret); |
| 170 | return; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | procs_->hotplug(procs_, conn->display(), |
| 175 | cur_state == DRM_MODE_CONNECTED ? 1 : 0); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | private: |
| 180 | DrmResources *drm_ = NULL; |
| 181 | const struct hwc_procs *procs_ = NULL; |
| 182 | }; |
| 183 | |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 184 | struct hwc_context_t { |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 185 | // map of display:hwc_drm_display_t |
| 186 | typedef std::map<int, hwc_drm_display_t> DisplayMap; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 187 | |
| 188 | ~hwc_context_t() { |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 189 | virtual_compositor_worker.Exit(); |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 192 | hwc_composer_device_1_t device; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 193 | hwc_procs_t const *procs = NULL; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 194 | |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 195 | DisplayMap displays; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 196 | DrmResources drm; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 197 | std::unique_ptr<Importer> importer; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 198 | const gralloc_module_t *gralloc; |
| 199 | DummySwSyncTimeline dummy_timeline; |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 200 | VirtualCompositorWorker virtual_compositor_worker; |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 201 | DrmHotplugHandler hotplug_handler; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 202 | }; |
| 203 | |
Adrian Salido | 9cc8393 | 2017-08-21 16:14:57 -0700 | [diff] [blame] | 204 | static native_handle_t *dup_buffer_handle(buffer_handle_t handle) { |
| 205 | native_handle_t *new_handle = |
| 206 | native_handle_create(handle->numFds, handle->numInts); |
| 207 | if (new_handle == NULL) |
| 208 | return NULL; |
| 209 | |
| 210 | const int *old_data = handle->data; |
| 211 | int *new_data = new_handle->data; |
| 212 | for (int i = 0; i < handle->numFds; i++) { |
| 213 | *new_data = dup(*old_data); |
| 214 | old_data++; |
| 215 | new_data++; |
| 216 | } |
| 217 | memcpy(new_data, old_data, sizeof(int) * handle->numInts); |
| 218 | |
| 219 | return new_handle; |
| 220 | } |
| 221 | |
| 222 | static void free_buffer_handle(native_handle_t *handle) { |
| 223 | int ret = native_handle_close(handle); |
| 224 | if (ret) |
| 225 | ALOGE("Failed to close native handle %d", ret); |
| 226 | ret = native_handle_delete(handle); |
| 227 | if (ret) |
| 228 | ALOGE("Failed to delete native handle %d", ret); |
| 229 | } |
| 230 | |
| 231 | const hwc_drm_bo *DrmHwcBuffer::operator->() const { |
| 232 | if (importer_ == NULL) { |
| 233 | ALOGE("Access of non-existent BO"); |
| 234 | exit(1); |
| 235 | return NULL; |
| 236 | } |
| 237 | return &bo_; |
| 238 | } |
| 239 | |
| 240 | void DrmHwcBuffer::Clear() { |
| 241 | if (importer_ != NULL) { |
| 242 | importer_->ReleaseBuffer(&bo_); |
| 243 | importer_ = NULL; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, Importer *importer) { |
| 248 | hwc_drm_bo tmp_bo; |
| 249 | |
| 250 | int ret = importer->ImportBuffer(handle, &tmp_bo); |
| 251 | if (ret) |
| 252 | return ret; |
| 253 | |
| 254 | if (importer_ != NULL) { |
| 255 | importer_->ReleaseBuffer(&bo_); |
Sean Paul | a5df1de | 2016-02-10 10:00:08 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Adrian Salido | 9cc8393 | 2017-08-21 16:14:57 -0700 | [diff] [blame] | 258 | importer_ = importer; |
| 259 | |
| 260 | bo_ = tmp_bo; |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | int DrmHwcNativeHandle::CopyBufferHandle(buffer_handle_t handle, |
| 266 | const gralloc_module_t *gralloc) { |
| 267 | native_handle_t *handle_copy = dup_buffer_handle(handle); |
| 268 | if (handle_copy == NULL) { |
| 269 | ALOGE("Failed to duplicate handle"); |
| 270 | return -ENOMEM; |
Sean Paul | a5df1de | 2016-02-10 10:00:08 -0800 | [diff] [blame] | 271 | } |
Adrian Salido | 9cc8393 | 2017-08-21 16:14:57 -0700 | [diff] [blame] | 272 | |
| 273 | int ret = gralloc->registerBuffer(gralloc, handle_copy); |
| 274 | if (ret) { |
| 275 | ALOGE("Failed to register buffer handle %d", ret); |
| 276 | free_buffer_handle(handle_copy); |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | Clear(); |
| 281 | |
| 282 | gralloc_ = gralloc; |
| 283 | handle_ = handle_copy; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | DrmHwcNativeHandle::~DrmHwcNativeHandle() { |
| 289 | Clear(); |
| 290 | } |
| 291 | |
| 292 | void DrmHwcNativeHandle::Clear() { |
| 293 | if (gralloc_ != NULL && handle_ != NULL) { |
| 294 | gralloc_->unregisterBuffer(gralloc_, handle_); |
| 295 | free_buffer_handle(handle_); |
| 296 | gralloc_ = NULL; |
| 297 | handle_ = NULL; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | int DrmHwcLayer::InitFromHwcLayer(hwc_layer_1_t *sf_layer, Importer *importer, |
| 302 | const gralloc_module_t *gralloc) { |
| 303 | sf_handle = sf_layer->handle; |
| 304 | alpha = sf_layer->planeAlpha; |
| 305 | |
| 306 | source_crop = DrmHwcRect<float>( |
| 307 | sf_layer->sourceCropf.left, sf_layer->sourceCropf.top, |
| 308 | sf_layer->sourceCropf.right, sf_layer->sourceCropf.bottom); |
| 309 | display_frame = DrmHwcRect<int>( |
| 310 | sf_layer->displayFrame.left, sf_layer->displayFrame.top, |
| 311 | sf_layer->displayFrame.right, sf_layer->displayFrame.bottom); |
| 312 | |
| 313 | transform = 0; |
| 314 | // 270* and 180* cannot be combined with flips. More specifically, they |
| 315 | // already contain both horizontal and vertical flips, so those fields are |
| 316 | // redundant in this case. 90* rotation can be combined with either horizontal |
| 317 | // flip or vertical flip, so treat it differently |
| 318 | if (sf_layer->transform == HWC_TRANSFORM_ROT_270) { |
| 319 | transform = DrmHwcTransform::kRotate270; |
| 320 | } else if (sf_layer->transform == HWC_TRANSFORM_ROT_180) { |
| 321 | transform = DrmHwcTransform::kRotate180; |
| 322 | } else { |
| 323 | if (sf_layer->transform & HWC_TRANSFORM_FLIP_H) |
| 324 | transform |= DrmHwcTransform::kFlipH; |
| 325 | if (sf_layer->transform & HWC_TRANSFORM_FLIP_V) |
| 326 | transform |= DrmHwcTransform::kFlipV; |
| 327 | if (sf_layer->transform & HWC_TRANSFORM_ROT_90) |
| 328 | transform |= DrmHwcTransform::kRotate90; |
| 329 | } |
| 330 | |
| 331 | switch (sf_layer->blending) { |
| 332 | case HWC_BLENDING_NONE: |
| 333 | blending = DrmHwcBlending::kNone; |
| 334 | break; |
| 335 | case HWC_BLENDING_PREMULT: |
| 336 | blending = DrmHwcBlending::kPreMult; |
| 337 | break; |
| 338 | case HWC_BLENDING_COVERAGE: |
| 339 | blending = DrmHwcBlending::kCoverage; |
| 340 | break; |
| 341 | default: |
| 342 | ALOGE("Invalid blending in hwc_layer_1_t %d", sf_layer->blending); |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | |
| 346 | int ret = buffer.ImportBuffer(sf_layer->handle, importer); |
| 347 | if (ret) |
| 348 | return ret; |
| 349 | |
| 350 | ret = handle.CopyBufferHandle(sf_layer->handle, gralloc); |
| 351 | if (ret) |
| 352 | return ret; |
| 353 | |
| 354 | ret = gralloc->perform(gralloc, GRALLOC_MODULE_PERFORM_GET_USAGE, |
| 355 | handle.get(), &gralloc_buffer_usage); |
| 356 | if (ret) { |
| 357 | ALOGE("Failed to get usage for buffer %p (%d)", handle.get(), ret); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | } |
Sean Paul | a5df1de | 2016-02-10 10:00:08 -0800 | [diff] [blame] | 363 | |
Zach Reizner | c6520e4 | 2015-08-13 14:32:09 -0700 | [diff] [blame] | 364 | static void hwc_dump(struct hwc_composer_device_1 *dev, char *buff, |
Sean Paul | 9046c64 | 2015-06-10 17:27:47 -0400 | [diff] [blame] | 365 | int buff_len) { |
| 366 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
| 367 | std::ostringstream out; |
| 368 | |
| 369 | ctx->drm.compositor()->Dump(&out); |
| 370 | std::string out_str = out.str(); |
Zach Reizner | fd6dc33 | 2015-10-13 21:12:48 -0700 | [diff] [blame] | 371 | strncpy(buff, out_str.c_str(), |
| 372 | std::min((size_t)buff_len, out_str.length() + 1)); |
| 373 | buff[buff_len - 1] = '\0'; |
Sean Paul | 9046c64 | 2015-06-10 17:27:47 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 376 | static bool hwc_skip_layer(const std::pair<int, int> &indices, int i) { |
| 377 | return indices.first >= 0 && i >= indices.first && i <= indices.second; |
| 378 | } |
| 379 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 380 | static int hwc_prepare(hwc_composer_device_1_t *dev, size_t num_displays, |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 381 | hwc_display_contents_1_t **display_contents) { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 382 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 383 | |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 384 | for (int i = 0; i < (int)num_displays; ++i) { |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 385 | if (!display_contents[i]) |
| 386 | continue; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 387 | |
Sean Paul | 6f82f1d | 2015-10-21 20:05:05 -0400 | [diff] [blame] | 388 | bool use_framebuffer_target = false; |
Sean Paul | b100837 | 2015-11-24 11:52:37 -0500 | [diff] [blame] | 389 | DrmMode mode; |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 390 | if (i == HWC_DISPLAY_VIRTUAL) { |
| 391 | use_framebuffer_target = true; |
| 392 | } else { |
Sean Paul | b100837 | 2015-11-24 11:52:37 -0500 | [diff] [blame] | 393 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(i); |
| 394 | if (!c) { |
| 395 | ALOGE("Failed to get DrmConnector for display %d", i); |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 396 | return -ENODEV; |
| 397 | } |
Sean Paul | b100837 | 2015-11-24 11:52:37 -0500 | [diff] [blame] | 398 | mode = c->active_mode(); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 399 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 400 | |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 401 | // Since we can't composite HWC_SKIP_LAYERs by ourselves, we'll let SF |
| 402 | // handle all layers in between the first and last skip layers. So find the |
| 403 | // outer indices and mark everything in between as HWC_FRAMEBUFFER |
| 404 | std::pair<int, int> skip_layer_indices(-1, -1); |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 405 | int num_layers = display_contents[i]->numHwLayers; |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 406 | for (int j = 0; !use_framebuffer_target && j < num_layers; ++j) { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 407 | hwc_layer_1_t *layer = &display_contents[i]->hwLayers[j]; |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 408 | |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 409 | if (!(layer->flags & HWC_SKIP_LAYER)) |
| 410 | continue; |
| 411 | |
| 412 | if (skip_layer_indices.first == -1) |
| 413 | skip_layer_indices.first = j; |
| 414 | skip_layer_indices.second = j; |
| 415 | } |
| 416 | |
| 417 | for (int j = 0; j < num_layers; ++j) { |
| 418 | hwc_layer_1_t *layer = &display_contents[i]->hwLayers[j]; |
| 419 | |
| 420 | if (!use_framebuffer_target && !hwc_skip_layer(skip_layer_indices, j)) { |
Sean Paul | b100837 | 2015-11-24 11:52:37 -0500 | [diff] [blame] | 421 | // If the layer is off the screen, don't earmark it for an overlay. |
| 422 | // We'll leave it as-is, which effectively just drops it from the frame |
| 423 | const hwc_rect_t *frame = &layer->displayFrame; |
| 424 | if ((frame->right - frame->left) <= 0 || |
| 425 | (frame->bottom - frame->top) <= 0 || |
| 426 | frame->right <= 0 || frame->bottom <= 0 || |
| 427 | frame->left >= (int)mode.h_display() || |
| 428 | frame->top >= (int)mode.v_display()) |
| 429 | continue; |
| 430 | |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 431 | if (layer->compositionType == HWC_FRAMEBUFFER) |
| 432 | layer->compositionType = HWC_OVERLAY; |
| 433 | } else { |
| 434 | switch (layer->compositionType) { |
| 435 | case HWC_OVERLAY: |
| 436 | case HWC_BACKGROUND: |
| 437 | case HWC_SIDEBAND: |
| 438 | case HWC_CURSOR_OVERLAY: |
| 439 | layer->compositionType = HWC_FRAMEBUFFER; |
| 440 | break; |
| 441 | } |
| 442 | } |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 443 | } |
| 444 | } |
Sean Paul | dffca95 | 2015-02-04 10:19:55 -0800 | [diff] [blame] | 445 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 446 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 447 | } |
| 448 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 449 | static void hwc_add_layer_to_retire_fence( |
| 450 | hwc_layer_1_t *layer, hwc_display_contents_1_t *display_contents) { |
Sean Paul | 0420612 | 2015-07-16 15:59:24 -0400 | [diff] [blame] | 451 | if (layer->releaseFenceFd < 0) |
| 452 | return; |
| 453 | |
| 454 | if (display_contents->retireFenceFd >= 0) { |
| 455 | int old_retire_fence = display_contents->retireFenceFd; |
Zach Reizner | c6520e4 | 2015-08-13 14:32:09 -0700 | [diff] [blame] | 456 | display_contents->retireFenceFd = |
| 457 | sync_merge("dc_retire", old_retire_fence, layer->releaseFenceFd); |
Sean Paul | 0420612 | 2015-07-16 15:59:24 -0400 | [diff] [blame] | 458 | close(old_retire_fence); |
| 459 | } else { |
| 460 | display_contents->retireFenceFd = dup(layer->releaseFenceFd); |
| 461 | } |
| 462 | } |
| 463 | |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 464 | static int hwc_set(hwc_composer_device_1_t *dev, size_t num_displays, |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 465 | hwc_display_contents_1_t **sf_display_contents) { |
Stéphane Marchesin | be98c8c | 2015-06-23 16:18:10 -0700 | [diff] [blame] | 466 | ATRACE_CALL(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 467 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 468 | int ret = 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 469 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 470 | std::vector<CheckedOutputFd> checked_output_fences; |
| 471 | std::vector<DrmHwcDisplayContents> displays_contents; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 472 | std::vector<DrmCompositionDisplayLayersMap> layers_map; |
| 473 | std::vector<std::vector<size_t>> layers_indices; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 474 | displays_contents.reserve(num_displays); |
| 475 | // layers_map.reserve(num_displays); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 476 | layers_indices.reserve(num_displays); |
| 477 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 478 | // Phase one does nothing that would cause errors. Only take ownership of FDs. |
| 479 | for (size_t i = 0; i < num_displays; ++i) { |
| 480 | hwc_display_contents_1_t *dc = sf_display_contents[i]; |
| 481 | displays_contents.emplace_back(); |
| 482 | DrmHwcDisplayContents &display_contents = displays_contents.back(); |
Haixia Shi | 7acc59b | 2015-09-30 10:57:54 -0700 | [diff] [blame] | 483 | layers_indices.emplace_back(); |
| 484 | std::vector<size_t> &indices_to_composite = layers_indices.back(); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 485 | |
| 486 | if (!sf_display_contents[i]) |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 487 | continue; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 488 | |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 489 | if (i == HWC_DISPLAY_VIRTUAL) { |
| 490 | ctx->virtual_compositor_worker.QueueComposite(dc); |
| 491 | continue; |
| 492 | } |
| 493 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 494 | std::ostringstream display_index_formatter; |
| 495 | display_index_formatter << "retire fence for display " << i; |
| 496 | std::string display_fence_description(display_index_formatter.str()); |
| 497 | checked_output_fences.emplace_back(&dc->retireFenceFd, |
| 498 | display_fence_description.c_str(), |
| 499 | ctx->dummy_timeline); |
| 500 | display_contents.retire_fence = OutputFd(&dc->retireFenceFd); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 501 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 502 | size_t num_dc_layers = dc->numHwLayers; |
Haixia Shi | 1034bb7 | 2015-09-09 12:08:20 -0700 | [diff] [blame] | 503 | int framebuffer_target_index = -1; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 504 | for (size_t j = 0; j < num_dc_layers; ++j) { |
| 505 | hwc_layer_1_t *sf_layer = &dc->hwLayers[j]; |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 506 | if (sf_layer->compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 507 | framebuffer_target_index = j; |
| 508 | break; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | for (size_t j = 0; j < num_dc_layers; ++j) { |
| 513 | hwc_layer_1_t *sf_layer = &dc->hwLayers[j]; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 514 | |
| 515 | display_contents.layers.emplace_back(); |
| 516 | DrmHwcLayer &layer = display_contents.layers.back(); |
| 517 | |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 518 | // In prepare() we marked all layers FRAMEBUFFER between SKIP_LAYER's. |
| 519 | // This means we should insert the FB_TARGET layer in the composition |
| 520 | // stack at the location of the first skip layer, and ignore the rest. |
| 521 | if (sf_layer->flags & HWC_SKIP_LAYER) { |
| 522 | if (framebuffer_target_index < 0) |
| 523 | continue; |
| 524 | int idx = framebuffer_target_index; |
| 525 | framebuffer_target_index = -1; |
| 526 | hwc_layer_1_t *fbt_layer = &dc->hwLayers[idx]; |
| 527 | if (!fbt_layer->handle || (fbt_layer->flags & HWC_SKIP_LAYER)) { |
| 528 | ALOGE("Invalid HWC_FRAMEBUFFER_TARGET with HWC_SKIP_LAYER present"); |
| 529 | continue; |
| 530 | } |
| 531 | indices_to_composite.push_back(idx); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 532 | continue; |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 533 | } |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 534 | |
Sean Paul | 6f82f1d | 2015-10-21 20:05:05 -0400 | [diff] [blame] | 535 | if (sf_layer->compositionType == HWC_OVERLAY) |
| 536 | indices_to_composite.push_back(j); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 537 | |
| 538 | layer.acquire_fence.Set(sf_layer->acquireFenceFd); |
| 539 | sf_layer->acquireFenceFd = -1; |
| 540 | |
| 541 | std::ostringstream layer_fence_formatter; |
| 542 | layer_fence_formatter << "release fence for layer " << j << " of display " |
| 543 | << i; |
| 544 | std::string layer_fence_description(layer_fence_formatter.str()); |
| 545 | checked_output_fences.emplace_back(&sf_layer->releaseFenceFd, |
| 546 | layer_fence_description.c_str(), |
| 547 | ctx->dummy_timeline); |
| 548 | layer.release_fence = OutputFd(&sf_layer->releaseFenceFd); |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 549 | } |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 550 | |
Sean Paul | bd61c8d | 2015-10-29 15:00:17 -0400 | [diff] [blame] | 551 | // This is a catch-all in case we get a frame without any overlay layers, or |
| 552 | // skip layers, but with a value fb_target layer. This _shouldn't_ happen, |
| 553 | // but it's not ruled out by the hwc specification |
Sean Paul | 6f82f1d | 2015-10-21 20:05:05 -0400 | [diff] [blame] | 554 | if (indices_to_composite.empty() && framebuffer_target_index >= 0) { |
| 555 | hwc_layer_1_t *sf_layer = &dc->hwLayers[framebuffer_target_index]; |
| 556 | if (!sf_layer->handle || (sf_layer->flags & HWC_SKIP_LAYER)) { |
| 557 | ALOGE( |
| 558 | "Expected valid layer with HWC_FRAMEBUFFER_TARGET when all " |
| 559 | "HWC_OVERLAY layers are skipped."); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 560 | ret = -EINVAL; |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 561 | } |
Sean Paul | 6f82f1d | 2015-10-21 20:05:05 -0400 | [diff] [blame] | 562 | indices_to_composite.push_back(framebuffer_target_index); |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 563 | } |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 564 | } |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 565 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 566 | if (ret) |
| 567 | return ret; |
| 568 | |
| 569 | for (size_t i = 0; i < num_displays; ++i) { |
| 570 | hwc_display_contents_1_t *dc = sf_display_contents[i]; |
| 571 | DrmHwcDisplayContents &display_contents = displays_contents[i]; |
Haixia Shi | 2fddd37 | 2015-10-15 16:21:48 -0700 | [diff] [blame] | 572 | if (!sf_display_contents[i] || i == HWC_DISPLAY_VIRTUAL) |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 573 | continue; |
| 574 | |
| 575 | layers_map.emplace_back(); |
| 576 | DrmCompositionDisplayLayersMap &map = layers_map.back(); |
Zach Reizner | acba14b | 2015-10-13 18:19:26 -0700 | [diff] [blame] | 577 | map.display = i; |
Zach Reizner | 5757e82 | 2015-10-16 19:06:31 -0700 | [diff] [blame] | 578 | map.geometry_changed = |
| 579 | (dc->flags & HWC_GEOMETRY_CHANGED) == HWC_GEOMETRY_CHANGED; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 580 | std::vector<size_t> &indices_to_composite = layers_indices[i]; |
| 581 | for (size_t j : indices_to_composite) { |
| 582 | hwc_layer_1_t *sf_layer = &dc->hwLayers[j]; |
| 583 | |
| 584 | DrmHwcLayer &layer = display_contents.layers[j]; |
| 585 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 586 | ret = layer.InitFromHwcLayer(sf_layer, ctx->importer.get(), ctx->gralloc); |
Zach Reizner | 7e88be9 | 2015-10-12 15:20:33 -0700 | [diff] [blame] | 587 | if (ret) { |
| 588 | ALOGE("Failed to init composition from layer %d", ret); |
| 589 | return ret; |
| 590 | } |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 591 | map.layers.emplace_back(std::move(layer)); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | std::unique_ptr<DrmComposition> composition( |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 596 | ctx->drm.compositor()->CreateComposition(ctx->importer.get())); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 597 | if (!composition) { |
| 598 | ALOGE("Drm composition init failed"); |
| 599 | return -EINVAL; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 600 | } |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 601 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 602 | ret = composition->SetLayers(layers_map.size(), layers_map.data()); |
| 603 | if (ret) { |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
Zach Reizner | 45624d3 | 2015-06-10 16:03:01 -0700 | [diff] [blame] | 606 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 607 | ret = ctx->drm.compositor()->QueueComposition(std::move(composition)); |
| 608 | if (ret) { |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 609 | return -EINVAL; |
| 610 | } |
| 611 | |
Zach Reizner | 566da2b | 2015-10-06 15:39:09 -0700 | [diff] [blame] | 612 | for (size_t i = 0; i < num_displays; ++i) { |
| 613 | hwc_display_contents_1_t *dc = sf_display_contents[i]; |
| 614 | if (!dc) |
| 615 | continue; |
| 616 | |
| 617 | size_t num_dc_layers = dc->numHwLayers; |
| 618 | for (size_t j = 0; j < num_dc_layers; ++j) { |
| 619 | hwc_layer_1_t *layer = &dc->hwLayers[j]; |
| 620 | if (layer->flags & HWC_SKIP_LAYER) |
| 621 | continue; |
| 622 | hwc_add_layer_to_retire_fence(layer, dc); |
| 623 | } |
| 624 | } |
| 625 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 626 | composition.reset(NULL); |
| 627 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 628 | return ret; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 629 | } |
| 630 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 631 | static int hwc_event_control(struct hwc_composer_device_1 *dev, int display, |
| 632 | int event, int enabled) { |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 633 | if (event != HWC_EVENT_VSYNC || (enabled != 0 && enabled != 1)) |
| 634 | return -EINVAL; |
Sean Paul | eb9e75c | 2015-01-25 23:31:30 -0500 | [diff] [blame] | 635 | |
Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 636 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
| 637 | hwc_drm_display_t *hd = &ctx->displays[display]; |
Adrian Salido | e5c7565 | 2017-02-16 10:29:46 -0800 | [diff] [blame] | 638 | hd->vsync_worker.VSyncControl(enabled); |
| 639 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 640 | } |
| 641 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 642 | static int hwc_set_power_mode(struct hwc_composer_device_1 *dev, int display, |
| 643 | int mode) { |
| 644 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 645 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 646 | uint64_t dpmsValue = 0; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 647 | switch (mode) { |
| 648 | case HWC_POWER_MODE_OFF: |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 649 | dpmsValue = DRM_MODE_DPMS_OFF; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 650 | break; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 651 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 652 | /* We can't support dozing right now, so go full on */ |
| 653 | case HWC_POWER_MODE_DOZE: |
| 654 | case HWC_POWER_MODE_DOZE_SUSPEND: |
| 655 | case HWC_POWER_MODE_NORMAL: |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 656 | dpmsValue = DRM_MODE_DPMS_ON; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 657 | break; |
| 658 | }; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 659 | return ctx->drm.SetDpmsMode(display, dpmsValue); |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 660 | } |
| 661 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 662 | static int hwc_query(struct hwc_composer_device_1 * /* dev */, int what, |
| 663 | int *value) { |
| 664 | switch (what) { |
| 665 | case HWC_BACKGROUND_LAYER_SUPPORTED: |
| 666 | *value = 0; /* TODO: We should do this */ |
| 667 | break; |
| 668 | case HWC_VSYNC_PERIOD: |
| 669 | ALOGW("Query for deprecated vsync value, returning 60Hz"); |
| 670 | *value = 1000 * 1000 * 1000 / 60; |
| 671 | break; |
| 672 | case HWC_DISPLAY_TYPES_SUPPORTED: |
Haixia Shi | 2fddd37 | 2015-10-15 16:21:48 -0700 | [diff] [blame] | 673 | *value = HWC_DISPLAY_PRIMARY_BIT | HWC_DISPLAY_EXTERNAL_BIT | |
| 674 | HWC_DISPLAY_VIRTUAL_BIT; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 675 | break; |
| 676 | } |
| 677 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 678 | } |
| 679 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 680 | static void hwc_register_procs(struct hwc_composer_device_1 *dev, |
| 681 | hwc_procs_t const *procs) { |
| 682 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 683 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 684 | ctx->procs = procs; |
Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 685 | |
Adrian Salido | 9cc8393 | 2017-08-21 16:14:57 -0700 | [diff] [blame] | 686 | for (std::pair<const int, hwc_drm_display> &display_entry : ctx->displays) |
| 687 | display_entry.second.vsync_worker.SetProcs(procs); |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 688 | |
| 689 | ctx->hotplug_handler.Init(&ctx->drm, procs); |
| 690 | ctx->drm.event_listener()->RegisterHotplugHandler(&ctx->hotplug_handler); |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 691 | } |
| 692 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 693 | static int hwc_get_display_configs(struct hwc_composer_device_1 *dev, |
| 694 | int display, uint32_t *configs, |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 695 | size_t *num_configs) { |
| 696 | if (!*num_configs) |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 697 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 698 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 699 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 700 | hwc_drm_display_t *hd = &ctx->displays[display]; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 701 | hd->config_ids.clear(); |
| 702 | |
| 703 | DrmConnector *connector = ctx->drm.GetConnectorForDisplay(display); |
| 704 | if (!connector) { |
| 705 | ALOGE("Failed to get connector for display %d", display); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 706 | return -ENODEV; |
| 707 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 708 | |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 709 | int ret = connector->UpdateModes(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 710 | if (ret) { |
| 711 | ALOGE("Failed to update display modes %d", ret); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 712 | return ret; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 713 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 714 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 715 | for (const DrmMode &mode : connector->modes()) { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 716 | size_t idx = hd->config_ids.size(); |
| 717 | if (idx == *num_configs) |
| 718 | break; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 719 | hd->config_ids.push_back(mode.id()); |
| 720 | configs[idx] = mode.id(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 721 | } |
| 722 | *num_configs = hd->config_ids.size(); |
| 723 | return *num_configs == 0 ? -1 : 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 724 | } |
| 725 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 726 | static int hwc_get_display_attributes(struct hwc_composer_device_1 *dev, |
| 727 | int display, uint32_t config, |
| 728 | const uint32_t *attributes, |
| 729 | int32_t *values) { |
| 730 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 731 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 732 | if (!c) { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 733 | ALOGE("Failed to get DrmConnector for display %d", display); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 734 | return -ENODEV; |
| 735 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 736 | DrmMode mode; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 737 | for (const DrmMode &conn_mode : c->modes()) { |
| 738 | if (conn_mode.id() == config) { |
| 739 | mode = conn_mode; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 740 | break; |
| 741 | } |
| 742 | } |
| 743 | if (mode.id() == 0) { |
| 744 | ALOGE("Failed to find active mode for display %d", display); |
| 745 | return -ENOENT; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 746 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 747 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 748 | uint32_t mm_width = c->mm_width(); |
| 749 | uint32_t mm_height = c->mm_height(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 750 | for (int i = 0; attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; ++i) { |
| 751 | switch (attributes[i]) { |
| 752 | case HWC_DISPLAY_VSYNC_PERIOD: |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 753 | values[i] = 1000 * 1000 * 1000 / mode.v_refresh(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 754 | break; |
| 755 | case HWC_DISPLAY_WIDTH: |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 756 | values[i] = mode.h_display(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 757 | break; |
| 758 | case HWC_DISPLAY_HEIGHT: |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 759 | values[i] = mode.v_display(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 760 | break; |
| 761 | case HWC_DISPLAY_DPI_X: |
| 762 | /* Dots per 1000 inches */ |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 763 | values[i] = mm_width ? (mode.h_display() * UM_PER_INCH) / mm_width : 0; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 764 | break; |
| 765 | case HWC_DISPLAY_DPI_Y: |
| 766 | /* Dots per 1000 inches */ |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 767 | values[i] = |
| 768 | mm_height ? (mode.v_display() * UM_PER_INCH) / mm_height : 0; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | } |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 772 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 773 | } |
| 774 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 775 | static int hwc_get_active_config(struct hwc_composer_device_1 *dev, |
| 776 | int display) { |
| 777 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 778 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); |
| 779 | if (!c) { |
| 780 | ALOGE("Failed to get DrmConnector for display %d", display); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 781 | return -ENODEV; |
| 782 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 783 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 784 | DrmMode mode = c->active_mode(); |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 785 | hwc_drm_display_t *hd = &ctx->displays[display]; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 786 | for (size_t i = 0; i < hd->config_ids.size(); ++i) { |
| 787 | if (hd->config_ids[i] == mode.id()) |
| 788 | return i; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 789 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 790 | return -1; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 791 | } |
| 792 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 793 | static int hwc_set_active_config(struct hwc_composer_device_1 *dev, int display, |
| 794 | int index) { |
| 795 | struct hwc_context_t *ctx = (struct hwc_context_t *)&dev->common; |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 796 | hwc_drm_display_t *hd = &ctx->displays[display]; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 797 | if (index >= (int)hd->config_ids.size()) { |
| 798 | ALOGE("Invalid config index %d passed in", index); |
| 799 | return -EINVAL; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 800 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 801 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 802 | DrmConnector *c = ctx->drm.GetConnectorForDisplay(display); |
| 803 | if (!c) { |
| 804 | ALOGE("Failed to get connector for display %d", display); |
| 805 | return -ENODEV; |
| 806 | } |
Sean Paul | 3a69f73 | 2015-10-26 15:37:06 -0400 | [diff] [blame] | 807 | |
| 808 | if (c->state() != DRM_MODE_CONNECTED) |
| 809 | return -ENODEV; |
| 810 | |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 811 | DrmMode mode; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 812 | for (const DrmMode &conn_mode : c->modes()) { |
| 813 | if (conn_mode.id() == hd->config_ids[index]) { |
| 814 | mode = conn_mode; |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 815 | break; |
| 816 | } |
| 817 | } |
| 818 | if (mode.id() != hd->config_ids[index]) { |
| 819 | ALOGE("Could not find active mode for %d/%d", index, hd->config_ids[index]); |
| 820 | return -ENOENT; |
| 821 | } |
| 822 | int ret = ctx->drm.SetDisplayActiveMode(display, mode); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 823 | if (ret) { |
Sean Paul | 877be97 | 2015-06-03 14:08:27 -0400 | [diff] [blame] | 824 | ALOGE("Failed to set active config %d", ret); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 825 | return ret; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 826 | } |
Sean Paul | 55584b5 | 2016-03-29 10:51:38 -0400 | [diff] [blame] | 827 | ret = ctx->drm.SetDpmsMode(display, DRM_MODE_DPMS_ON); |
| 828 | if (ret) { |
| 829 | ALOGE("Failed to set dpms mode on %d", ret); |
| 830 | return ret; |
| 831 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 832 | return ret; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 833 | } |
| 834 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 835 | static int hwc_device_close(struct hw_device_t *dev) { |
| 836 | struct hwc_context_t *ctx = (struct hwc_context_t *)dev; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 837 | delete ctx; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 838 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 839 | } |
| 840 | |
Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 841 | /* |
| 842 | * TODO: This function sets the active config to the first one in the list. This |
| 843 | * should be fixed such that it selects the preferred mode for the display, or |
| 844 | * some other, saner, method of choosing the config. |
| 845 | */ |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 846 | static int hwc_set_initial_config(hwc_drm_display_t *hd) { |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 847 | uint32_t config; |
| 848 | size_t num_configs = 1; |
| 849 | int ret = hwc_get_display_configs(&hd->ctx->device, hd->display, &config, |
| 850 | &num_configs); |
| 851 | if (ret || !num_configs) |
| 852 | return 0; |
Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 853 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 854 | ret = hwc_set_active_config(&hd->ctx->device, hd->display, 0); |
| 855 | if (ret) { |
| 856 | ALOGE("Failed to set active config d=%d ret=%d", hd->display, ret); |
| 857 | return ret; |
| 858 | } |
Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 859 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 860 | return ret; |
Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 863 | static int hwc_initialize_display(struct hwc_context_t *ctx, int display) { |
Sean Paul | e42febf | 2015-05-07 11:35:29 -0700 | [diff] [blame] | 864 | hwc_drm_display_t *hd = &ctx->displays[display]; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 865 | hd->ctx = ctx; |
| 866 | hd->display = display; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 867 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 868 | int ret = hwc_set_initial_config(hd); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 869 | if (ret) { |
| 870 | ALOGE("Failed to set initial config for d=%d ret=%d", display, ret); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 871 | return ret; |
| 872 | } |
Sean Paul | 24a26e3 | 2015-02-04 10:34:47 -0800 | [diff] [blame] | 873 | |
Sean Paul | 4057be3 | 2015-05-13 06:23:09 -0700 | [diff] [blame] | 874 | ret = hd->vsync_worker.Init(&ctx->drm, display); |
| 875 | if (ret) { |
| 876 | ALOGE("Failed to create event worker for display %d %d\n", display, ret); |
| 877 | return ret; |
| 878 | } |
| 879 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 880 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 881 | } |
| 882 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 883 | static int hwc_enumerate_displays(struct hwc_context_t *ctx) { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 884 | int ret; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 885 | for (auto &conn : ctx->drm.connectors()) { |
| 886 | ret = hwc_initialize_display(ctx, conn->display()); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 887 | if (ret) { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 888 | ALOGE("Failed to initialize display %d", conn->display()); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 889 | return ret; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 890 | } |
| 891 | } |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 892 | |
Haixia Shi | d21f528 | 2015-10-05 14:35:09 -0700 | [diff] [blame] | 893 | ret = ctx->virtual_compositor_worker.Init(); |
| 894 | if (ret) { |
| 895 | ALOGE("Failed to initialize virtual compositor worker"); |
| 896 | return ret; |
| 897 | } |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 898 | return 0; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 899 | } |
| 900 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 901 | static int hwc_device_open(const struct hw_module_t *module, const char *name, |
| 902 | struct hw_device_t **dev) { |
| 903 | if (strcmp(name, HWC_HARDWARE_COMPOSER)) { |
| 904 | ALOGE("Invalid module name- %s", name); |
| 905 | return -EINVAL; |
| 906 | } |
| 907 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 908 | std::unique_ptr<hwc_context_t> ctx(new hwc_context_t()); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 909 | if (!ctx) { |
| 910 | ALOGE("Failed to allocate hwc context"); |
| 911 | return -ENOMEM; |
| 912 | } |
| 913 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 914 | int ret = ctx->drm.Init(); |
| 915 | if (ret) { |
| 916 | ALOGE("Can't initialize Drm object %d", ret); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 917 | return ret; |
| 918 | } |
| 919 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 920 | ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, |
| 921 | (const hw_module_t **)&ctx->gralloc); |
| 922 | if (ret) { |
| 923 | ALOGE("Failed to open gralloc module %d", ret); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 924 | return ret; |
| 925 | } |
| 926 | |
| 927 | ret = ctx->dummy_timeline.Init(); |
| 928 | if (ret) { |
| 929 | ALOGE("Failed to create dummy sw sync timeline %d", ret); |
| 930 | return ret; |
| 931 | } |
| 932 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 933 | ctx->importer.reset(Importer::CreateInstance(&ctx->drm)); |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 934 | if (!ctx->importer) { |
| 935 | ALOGE("Failed to create importer instance"); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 936 | return ret; |
| 937 | } |
| 938 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 939 | ret = hwc_enumerate_displays(ctx.get()); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 940 | if (ret) { |
| 941 | ALOGE("Failed to enumerate displays: %s", strerror(ret)); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 942 | return ret; |
| 943 | } |
| 944 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 945 | ctx->device.common.tag = HARDWARE_DEVICE_TAG; |
| 946 | ctx->device.common.version = HWC_DEVICE_API_VERSION_1_4; |
| 947 | ctx->device.common.module = const_cast<hw_module_t *>(module); |
| 948 | ctx->device.common.close = hwc_device_close; |
| 949 | |
Sean Paul | 9046c64 | 2015-06-10 17:27:47 -0400 | [diff] [blame] | 950 | ctx->device.dump = hwc_dump; |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 951 | ctx->device.prepare = hwc_prepare; |
| 952 | ctx->device.set = hwc_set; |
| 953 | ctx->device.eventControl = hwc_event_control; |
| 954 | ctx->device.setPowerMode = hwc_set_power_mode; |
| 955 | ctx->device.query = hwc_query; |
| 956 | ctx->device.registerProcs = hwc_register_procs; |
| 957 | ctx->device.getDisplayConfigs = hwc_get_display_configs; |
| 958 | ctx->device.getDisplayAttributes = hwc_get_display_attributes; |
| 959 | ctx->device.getActiveConfig = hwc_get_active_config; |
| 960 | ctx->device.setActiveConfig = hwc_set_active_config; |
| 961 | ctx->device.setCursorPositionAsync = NULL; /* TODO: Add cursor */ |
| 962 | |
| 963 | *dev = &ctx->device.common; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 964 | ctx.release(); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 965 | |
| 966 | return 0; |
| 967 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 968 | } |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 969 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 970 | static struct hw_module_methods_t hwc_module_methods = { |
Sean Paul | 5325e10 | 2016-03-29 13:55:35 -0400 | [diff] [blame] | 971 | .open = android::hwc_device_open |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 972 | }; |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 973 | |
| 974 | hwc_module_t HAL_MODULE_INFO_SYM = { |
Sean Paul | 5325e10 | 2016-03-29 13:55:35 -0400 | [diff] [blame] | 975 | .common = { |
| 976 | .tag = HARDWARE_MODULE_TAG, |
| 977 | .version_major = 1, |
| 978 | .version_minor = 0, |
| 979 | .id = HWC_HARDWARE_MODULE_ID, |
| 980 | .name = "DRM hwcomposer module", |
| 981 | .author = "The Android Open Source Project", |
| 982 | .methods = &hwc_module_methods, |
| 983 | .dso = NULL, |
| 984 | .reserved = {0}, |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 985 | } |
Sean Paul | e0c4c3d | 2015-01-20 16:56:04 -0500 | [diff] [blame] | 986 | }; |