• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "drmhwc"
18 
19 #include "DrmKmsPlan.h"
20 
21 #include "drm/DrmDevice.h"
22 #include "drm/DrmPlane.h"
23 #include "utils/log.h"
24 
25 namespace android {
CreateDrmKmsPlan(DrmDisplayPipeline & pipe,std::vector<LayerData> composition,std::optional<LayerData> cursor_layer)26 auto DrmKmsPlan::CreateDrmKmsPlan(
27     DrmDisplayPipeline &pipe, std::vector<LayerData> composition,
28     std::optional<LayerData> cursor_layer) -> std::unique_ptr<DrmKmsPlan> {
29   auto plan = std::make_unique<DrmKmsPlan>();
30 
31   auto [avail_planes, cursor_plane] = pipe.GetUsablePlanes();
32 
33   int z_pos = 0;
34   if (cursor_layer.has_value()) {
35     if (cursor_plane &&
36         cursor_plane->Get()->IsValidForLayer(&cursor_layer.value())) {
37       plan->plan.emplace_back(
38           LayerToPlaneJoining{.layer = std::move(cursor_layer.value()),
39                               .plane = cursor_plane,
40                               .z_pos = z_pos++});
41     } else {
42       // Cursor layer can't use cursor plane, so let it match normally with
43       // others.
44       composition.push_back(std::move(cursor_layer.value()));
45     }
46   }
47 
48   for (auto &dhl : composition) {
49     std::shared_ptr<BindingOwner<DrmPlane>> plane;
50     /* Skip unsupported planes */
51     do {
52       if (avail_planes.empty()) {
53         return {};
54       }
55 
56       plane = *avail_planes.begin();
57       avail_planes.erase(avail_planes.begin());
58     } while (!plane->Get()->IsValidForLayer(&dhl));
59 
60     LayerToPlaneJoining joining = {
61         .layer = std::move(dhl),
62         .plane = plane,
63         .z_pos = z_pos++,
64     };
65 
66     plan->plan.emplace_back(std::move(joining));
67   }
68 
69   return plan;
70 }
71 
72 }  // namespace android
73