Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [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 | |
| 17 | #define LOG_TAG "hwc-drm-composition" |
| 18 | |
| 19 | #include "drmcomposition.h" |
| 20 | #include "drmcrtc.h" |
| 21 | #include "drmplane.h" |
| 22 | #include "drmresources.h" |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | |
| 26 | #include <cutils/log.h> |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 28 | #include <sw_sync.h> |
| 29 | #include <sync/sync.h> |
| 30 | |
| 31 | namespace android { |
| 32 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 33 | DrmComposition::DrmComposition(DrmResources *drm, Importer *importer) |
| 34 | : drm_(drm), importer_(importer) { |
Zach Reizner | 1946fa7 | 2015-08-14 11:14:38 -0700 | [diff] [blame] | 35 | char use_overlay_planes_prop[PROPERTY_VALUE_MAX]; |
| 36 | property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1"); |
| 37 | bool use_overlay_planes = atoi(use_overlay_planes_prop); |
| 38 | |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame^] | 39 | for (auto &plane : drm->planes()) { |
| 40 | if (plane->type() == DRM_PLANE_TYPE_PRIMARY) |
| 41 | primary_planes_.push_back(plane.get()); |
| 42 | else if (use_overlay_planes && plane->type() == DRM_PLANE_TYPE_OVERLAY) |
| 43 | overlay_planes_.push_back(plane.get()); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Sean Paul | bdc67bf | 2015-09-21 10:04:02 -0400 | [diff] [blame] | 47 | int DrmComposition::Init(uint64_t frame_no) { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame^] | 48 | for (auto &conn : drm_->connectors()) { |
| 49 | int display = conn->display(); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 50 | composition_map_[display].reset(new DrmDisplayComposition()); |
| 51 | if (!composition_map_[display]) { |
| 52 | ALOGE("Failed to allocate new display composition\n"); |
| 53 | return -ENOMEM; |
| 54 | } |
Sean Paul | 2143d3b | 2015-09-04 01:33:06 -0400 | [diff] [blame] | 55 | |
| 56 | // If the display hasn't been modeset yet, this will be NULL |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 57 | DrmCrtc *crtc = drm_->GetCrtcForDisplay(display); |
Sean Paul | 2143d3b | 2015-09-04 01:33:06 -0400 | [diff] [blame] | 58 | |
Zach Reizner | 7e88be9 | 2015-10-12 15:20:33 -0700 | [diff] [blame] | 59 | int ret = composition_map_[display]->Init(drm_, crtc, importer_, frame_no); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 60 | if (ret) { |
Zach Reizner | 7e88be9 | 2015-10-12 15:20:33 -0700 | [diff] [blame] | 61 | ALOGE("Failed to init display composition for %d", display); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 62 | return ret; |
| 63 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 64 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 68 | int DrmComposition::SetLayers(size_t num_displays, |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 69 | DrmCompositionDisplayLayersMap *maps) { |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 70 | int ret = 0; |
| 71 | for (size_t display_index = 0; display_index < num_displays; |
| 72 | display_index++) { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 73 | DrmCompositionDisplayLayersMap &map = maps[display_index]; |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 74 | int display = map.display; |
| 75 | |
Sean Paul | c0b3548 | 2015-10-21 19:11:58 -0400 | [diff] [blame] | 76 | if (!drm_->GetConnectorForDisplay(display)) { |
| 77 | ALOGE("Invalid display given to SetLayers %d", display); |
| 78 | continue; |
| 79 | } |
| 80 | |
Zach Reizner | 5757e82 | 2015-10-16 19:06:31 -0700 | [diff] [blame] | 81 | ret = composition_map_[display]->SetLayers( |
| 82 | map.layers.data(), map.layers.size(), map.geometry_changed); |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 83 | if (ret) |
| 84 | return ret; |
| 85 | } |
| 86 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 87 | return 0; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame] | 90 | int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) { |
| 91 | return composition_map_[display]->SetDpmsMode(dpms_mode); |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 94 | int DrmComposition::SetDisplayMode(int display, const DrmMode &display_mode) { |
| 95 | return composition_map_[display]->SetDisplayMode(display_mode); |
| 96 | } |
| 97 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 98 | std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition( |
| 99 | int display) { |
| 100 | return std::move(composition_map_[display]); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 101 | } |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 102 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 103 | int DrmComposition::Plan(std::map<int, DrmDisplayCompositor> &compositor_map) { |
| 104 | int ret = 0; |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame^] | 105 | for (auto &conn : drm_->connectors()) { |
| 106 | int display = conn->display(); |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 107 | DrmDisplayComposition *comp = GetDisplayComposition(display); |
| 108 | ret = comp->Plan(compositor_map[display].squash_state(), &primary_planes_, |
| 109 | &overlay_planes_); |
| 110 | if (ret) { |
| 111 | ALOGE("Failed to plan composition for dislay %d", display); |
| 112 | return ret; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 119 | int DrmComposition::DisableUnusedPlanes() { |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame^] | 120 | for (auto &conn : drm_->connectors()) { |
| 121 | int display = conn->display(); |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 122 | DrmDisplayComposition *comp = GetDisplayComposition(display); |
| 123 | |
| 124 | /* |
| 125 | * Leave empty compositions alone |
| 126 | * TODO: re-visit this and potentially disable leftover planes after the |
| 127 | * active compositions have gobbled up all they can |
| 128 | */ |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 129 | if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY || |
| 130 | comp->type() == DRM_COMPOSITION_TYPE_MODESET) |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 131 | continue; |
| 132 | |
| 133 | DrmCrtc *crtc = drm_->GetCrtcForDisplay(display); |
| 134 | if (!crtc) { |
| 135 | ALOGE("Failed to find crtc for display %d", display); |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin(); |
| 140 | iter != primary_planes_.end(); ++iter) { |
| 141 | if ((*iter)->GetCrtcSupported(*crtc)) { |
| 142 | comp->AddPlaneDisable(*iter); |
| 143 | primary_planes_.erase(iter); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin(); |
| 148 | iter != overlay_planes_.end();) { |
| 149 | if ((*iter)->GetCrtcSupported(*crtc)) { |
| 150 | comp->AddPlaneDisable(*iter); |
| 151 | iter = overlay_planes_.erase(iter); |
| 152 | } else { |
| 153 | iter++; |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) { |
| 161 | return composition_map_[display].get(); |
| 162 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 163 | } |