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> |
| 27 | #include <sw_sync.h> |
| 28 | #include <sync/sync.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
Sean Paul | c51b0c5 | 2015-06-10 14:32:51 -0400 | [diff] [blame] | 32 | static const bool kUseOverlayPlanes = true; |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 33 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 34 | DrmComposition::DrmComposition(DrmResources *drm, Importer *importer) |
| 35 | : drm_(drm), importer_(importer) { |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 36 | for (DrmResources::PlaneIter iter = drm_->begin_planes(); |
| 37 | iter != drm_->end_planes(); ++iter) { |
| 38 | if ((*iter)->type() == DRM_PLANE_TYPE_PRIMARY) |
| 39 | primary_planes_.push_back(*iter); |
| 40 | else if (kUseOverlayPlanes && (*iter)->type() == DRM_PLANE_TYPE_OVERLAY) |
| 41 | overlay_planes_.push_back(*iter); |
| 42 | } |
| 43 | } |
| 44 | |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 45 | int DrmComposition::Init() { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 46 | for (DrmResources::ConnectorIter iter = drm_->begin_connectors(); |
| 47 | iter != drm_->end_connectors(); ++iter) { |
| 48 | int display = (*iter)->display(); |
| 49 | composition_map_[display].reset(new DrmDisplayComposition()); |
| 50 | if (!composition_map_[display]) { |
| 51 | ALOGE("Failed to allocate new display composition\n"); |
| 52 | return -ENOMEM; |
| 53 | } |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame^] | 54 | DrmCrtc *crtc = drm_->GetCrtcForDisplay(display); |
| 55 | if (!crtc) { |
| 56 | ALOGE("Failed to find crtc for display %d", display); |
| 57 | return -ENODEV; |
| 58 | } |
| 59 | int ret = composition_map_[(*iter)->display()]->Init(drm_, crtc, importer_); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 60 | if (ret) { |
| 61 | ALOGE("Failed to init display composition for %d", (*iter)->display()); |
| 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, |
| 69 | const DrmCompositionDisplayLayersMap *maps) { |
| 70 | int ret = 0; |
| 71 | for (size_t display_index = 0; display_index < num_displays; |
| 72 | display_index++) { |
| 73 | const DrmCompositionDisplayLayersMap &map = maps[display_index]; |
| 74 | int display = map.display; |
| 75 | |
| 76 | ret = composition_map_[display]->SetLayers( |
| 77 | map.layers, map.num_layers, map.layer_indices, &primary_planes_, |
| 78 | &overlay_planes_); |
| 79 | if (ret) |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | return DisableUnusedPlanes(); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Zach Reizner | 0980705 | 2015-08-13 14:53:41 -0700 | [diff] [blame^] | 86 | int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) { |
| 87 | return composition_map_[display]->SetDpmsMode(dpms_mode); |
Sean Paul | db7a17d | 2015-06-24 18:46:05 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 90 | std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition( |
| 91 | int display) { |
| 92 | return std::move(composition_map_[display]); |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 93 | } |
Sean Paul | 2e46fbd | 2015-07-09 17:22:22 -0400 | [diff] [blame] | 94 | |
| 95 | int DrmComposition::DisableUnusedPlanes() { |
| 96 | for (DrmResources::ConnectorIter iter = drm_->begin_connectors(); |
| 97 | iter != drm_->end_connectors(); ++iter) { |
| 98 | int display = (*iter)->display(); |
| 99 | DrmDisplayComposition *comp = GetDisplayComposition(display); |
| 100 | |
| 101 | /* |
| 102 | * Leave empty compositions alone |
| 103 | * TODO: re-visit this and potentially disable leftover planes after the |
| 104 | * active compositions have gobbled up all they can |
| 105 | */ |
| 106 | if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY) |
| 107 | continue; |
| 108 | |
| 109 | DrmCrtc *crtc = drm_->GetCrtcForDisplay(display); |
| 110 | if (!crtc) { |
| 111 | ALOGE("Failed to find crtc for display %d", display); |
| 112 | continue; |
| 113 | } |
| 114 | |
| 115 | for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin(); |
| 116 | iter != primary_planes_.end(); ++iter) { |
| 117 | if ((*iter)->GetCrtcSupported(*crtc)) { |
| 118 | comp->AddPlaneDisable(*iter); |
| 119 | primary_planes_.erase(iter); |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin(); |
| 124 | iter != overlay_planes_.end();) { |
| 125 | if ((*iter)->GetCrtcSupported(*crtc)) { |
| 126 | comp->AddPlaneDisable(*iter); |
| 127 | iter = overlay_planes_.erase(iter); |
| 128 | } else { |
| 129 | iter++; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) { |
| 137 | return composition_map_[display].get(); |
| 138 | } |
Sean Paul | b386f1b | 2015-05-13 06:33:23 -0700 | [diff] [blame] | 139 | } |