• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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-platform"
18 
19 #include "platform.h"
20 #include "drmdevice.h"
21 
22 #include <log/log.h>
23 
24 namespace android {
25 
GetUsablePlanes(DrmCrtc * crtc,std::vector<DrmPlane * > * primary_planes,std::vector<DrmPlane * > * overlay_planes)26 std::vector<DrmPlane *> Planner::GetUsablePlanes(
27     DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
28     std::vector<DrmPlane *> *overlay_planes) {
29   std::vector<DrmPlane *> usable_planes;
30   std::copy_if(primary_planes->begin(), primary_planes->end(),
31                std::back_inserter(usable_planes),
32                [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
33   std::copy_if(overlay_planes->begin(), overlay_planes->end(),
34                std::back_inserter(usable_planes),
35                [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
36   return usable_planes;
37 }
38 
ValidatePlane(DrmPlane * plane,DrmHwcLayer * layer)39 int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) {
40   int ret = 0;
41   uint64_t blend;
42 
43   if ((plane->rotation_property().id() == 0) &&
44       layer->transform != DrmHwcTransform::kIdentity) {
45     ALOGE("Rotation is not supported on plane %d", plane->id());
46     return -EINVAL;
47   }
48 
49   if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) {
50     ALOGE("Alpha is not supported on plane %d", plane->id());
51     return -EINVAL;
52   }
53 
54   if (plane->blend_property().id() == 0) {
55     if ((layer->blending != DrmHwcBlending::kNone) &&
56         (layer->blending != DrmHwcBlending::kPreMult)) {
57       ALOGE("Blending is not supported on plane %d", plane->id());
58       return -EINVAL;
59     }
60   } else {
61     switch (layer->blending) {
62       case DrmHwcBlending::kPreMult:
63         std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
64             "Pre-multiplied");
65         break;
66       case DrmHwcBlending::kCoverage:
67         std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
68             "Coverage");
69         break;
70       case DrmHwcBlending::kNone:
71       default:
72         std::tie(blend,
73                  ret) = plane->blend_property().GetEnumValueWithName("None");
74         break;
75     }
76     if (ret)
77       ALOGE("Expected a valid blend mode on plane %d", plane->id());
78   }
79 
80   return ret;
81 }
82 
ProvisionPlanes(std::map<size_t,DrmHwcLayer * > & layers,DrmCrtc * crtc,std::vector<DrmPlane * > * primary_planes,std::vector<DrmPlane * > * overlay_planes)83 std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
84     std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
85     std::vector<DrmPlane *> *primary_planes,
86     std::vector<DrmPlane *> *overlay_planes) {
87   std::vector<DrmCompositionPlane> composition;
88   std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
89                                                    overlay_planes);
90   if (planes.empty()) {
91     ALOGE("Display %d has no usable planes", crtc->display());
92     return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
93   }
94 
95   // Go through the provisioning stages and provision planes
96   for (auto &i : stages_) {
97     int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
98     if (ret) {
99       ALOGE("Failed provision stage with ret %d", ret);
100       return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
101     }
102   }
103 
104   return std::make_tuple(0, std::move(composition));
105 }
106 
ProvisionPlanes(std::vector<DrmCompositionPlane> * composition,std::map<size_t,DrmHwcLayer * > & layers,DrmCrtc * crtc,std::vector<DrmPlane * > * planes)107 int PlanStageProtected::ProvisionPlanes(
108     std::vector<DrmCompositionPlane> *composition,
109     std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
110     std::vector<DrmPlane *> *planes) {
111   int ret;
112   int protected_zorder = -1;
113   for (auto i = layers.begin(); i != layers.end();) {
114     if (!i->second->protected_usage()) {
115       ++i;
116       continue;
117     }
118 
119     ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
120                   std::make_pair(i->first, i->second));
121     if (ret) {
122       ALOGE("Failed to dedicate protected layer! Dropping it.");
123       return ret;
124     }
125 
126     protected_zorder = i->first;
127     i = layers.erase(i);
128   }
129 
130   return 0;
131 }
132 
ProvisionPlanes(std::vector<DrmCompositionPlane> * composition,std::map<size_t,DrmHwcLayer * > & layers,DrmCrtc * crtc,std::vector<DrmPlane * > * planes)133 int PlanStageGreedy::ProvisionPlanes(
134     std::vector<DrmCompositionPlane> *composition,
135     std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
136     std::vector<DrmPlane *> *planes) {
137   // Fill up the remaining planes
138   for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
139     int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
140                       crtc, std::make_pair(i->first, i->second));
141     // We don't have any planes left
142     if (ret == -ENOENT)
143       break;
144     else if (ret) {
145       ALOGE("Failed to emplace layer %zu, dropping it", i->first);
146       return ret;
147     }
148   }
149 
150   return 0;
151 }
152 }  // namespace android
153