2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "hwc-drm-display-composition"
19 #include "DrmDisplayComposition.h"
21 #include <sync/sync.h>
22 #include <xf86drmMode.h>
26 #include <unordered_set>
28 #include "DrmDisplayCompositor.h"
30 #include "drm/DrmDevice.h"
31 #include "utils/log.h"
35 DrmDisplayComposition::DrmDisplayComposition(DrmCrtc *crtc, Planner *planner)
36 : crtc_(crtc), // Can be NULL if we haven't modeset yet
40 int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers) {
41 for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
42 layers_.emplace_back(std::move(layers[layer_index]));
48 int DrmDisplayComposition::AddPlaneComposition(DrmCompositionPlane plane) {
49 composition_planes_.emplace_back(std::move(plane));
53 int DrmDisplayComposition::Plan(std::vector<DrmPlane *> *primary_planes,
54 std::vector<DrmPlane *> *overlay_planes) {
55 std::map<size_t, DrmHwcLayer *> to_composite;
57 for (size_t i = 0; i < layers_.size(); ++i)
58 to_composite.emplace(std::make_pair(i, &layers_[i]));
62 composition_planes_) = planner_->ProvisionPlanes(to_composite, crtc_,
66 ALOGV("Planner failed provisioning planes ret=%d", ret);
70 // Remove the planes we used from the pool before returning. This ensures they
71 // won't be reused by another display in the composition.
72 for (auto &i : composition_planes_) {
76 // make sure that source layers are ordered based on zorder
77 std::sort(i.source_layers().begin(), i.source_layers().end());
79 std::vector<DrmPlane *> *container = nullptr;
80 if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
81 container = primary_planes;
83 container = overlay_planes;
84 for (auto j = container->begin(); j != container->end(); ++j) {
85 if (*j == i.plane()) {
95 } // namespace android