OSDN Git Service

drm_hwcomposer: Modify source_layers_ to be integer instead of array
[android-x86/external-drm_hwcomposer.git] / compositor / DrmDisplayComposition.cpp
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-display-composition"
18
19 #include "DrmDisplayComposition.h"
20
21 #include <sync/sync.h>
22 #include <xf86drmMode.h>
23
24 #include <algorithm>
25 #include <cstdlib>
26 #include <unordered_set>
27
28 #include "DrmDisplayCompositor.h"
29 #include "Planner.h"
30 #include "drm/DrmDevice.h"
31 #include "utils/log.h"
32
33 namespace android {
34
35 DrmDisplayComposition::DrmDisplayComposition(DrmCrtc *crtc, Planner *planner)
36     : crtc_(crtc),  // Can be NULL if we haven't modeset yet
37       planner_(planner) {
38 }
39
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]));
43   }
44
45   return 0;
46 }
47
48 int DrmDisplayComposition::AddPlaneComposition(DrmCompositionPlane plane) {
49   composition_planes_.emplace_back(std::move(plane));
50   return 0;
51 }
52
53 int DrmDisplayComposition::Plan(std::vector<DrmPlane *> *primary_planes,
54                                 std::vector<DrmPlane *> *overlay_planes) {
55   std::map<size_t, DrmHwcLayer *> to_composite;
56
57   for (size_t i = 0; i < layers_.size(); ++i)
58     to_composite.emplace(std::make_pair(i, &layers_[i]));
59
60   int ret = 0;
61   std::tie(ret,
62            composition_planes_) = planner_->ProvisionPlanes(to_composite, crtc_,
63                                                             primary_planes,
64                                                             overlay_planes);
65   if (ret) {
66     ALOGV("Planner failed provisioning planes ret=%d", ret);
67     return ret;
68   }
69
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_) {
73     if (!i.plane())
74       continue;
75
76     std::vector<DrmPlane *> *container = nullptr;
77     if (i.plane()->type() == DRM_PLANE_TYPE_PRIMARY)
78       container = primary_planes;
79     else
80       container = overlay_planes;
81     for (auto j = container->begin(); j != container->end(); ++j) {
82       if (*j == i.plane()) {
83         container->erase(j);
84         break;
85       }
86     }
87   }
88
89   return 0;
90 }
91
92 }  // namespace android