OSDN Git Service

drm_hwcomposer: Free resources in HookDevClose()
[android-x86/external-drm_hwcomposer.git] / compositor / Planner.h
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 #ifndef ANDROID_DRM_PLATFORM_H_
18 #define ANDROID_DRM_PLATFORM_H_
19
20 #include <hardware/hardware.h>
21 #include <hardware/hwcomposer.h>
22
23 #include <map>
24 #include <memory>
25 #include <vector>
26
27 #include "compositor/DrmDisplayComposition.h"
28 #include "drmhwcomposer.h"
29
30 namespace android {
31
32 class DrmDevice;
33
34 class Planner {
35  private:
36   // Removes and returns the next available plane from planes
37   static DrmPlane *PopPlane(std::vector<DrmPlane *> *planes) {
38     if (planes->empty())
39       return NULL;
40     DrmPlane *plane = planes->front();
41     planes->erase(planes->begin());
42     return plane;
43   }
44
45   // Inserts the given layer:plane in the composition at the back
46   static int Emplace(std::vector<DrmCompositionPlane> *composition,
47                      std::vector<DrmPlane *> *planes,
48                      std::pair<size_t, DrmHwcLayer *> layer) {
49     DrmPlane *plane = PopPlane(planes);
50     std::vector<DrmPlane *> unused_planes;
51     int ret = -ENOENT;
52     while (plane) {
53       ret = plane->IsValidForLayer(layer.second) ? 0 : -EINVAL;
54       if (!ret)
55         break;
56       if (!plane->zpos_property().is_immutable())
57         unused_planes.push_back(plane);
58       plane = PopPlane(planes);
59     }
60
61     if (!ret) {
62       composition->emplace_back(plane, layer.first);
63       planes->insert(planes->begin(), unused_planes.begin(),
64                      unused_planes.end());
65     }
66
67     return ret;
68   }
69
70   int ProvisionPlanesInternal(std::vector<DrmCompositionPlane> *composition,
71                               std::map<size_t, DrmHwcLayer *> &layers,
72                               std::vector<DrmPlane *> *planes);
73
74  public:
75   // Creates a planner instance
76   static std::unique_ptr<Planner> CreateInstance(DrmDevice *drm);
77
78   // Takes a stack of layers and provisions hardware planes for them. If the
79   // entire stack can't fit in hardware, FIXME
80   //
81   // @layers: a map of index:layer of layers to composite
82   // @primary_planes: a vector of primary planes available for this frame
83   // @overlay_planes: a vector of overlay planes available for this frame
84   //
85   // Returns: A tuple with the status of the operation (0 for success) and
86   //          a vector of the resulting plan (ie: layer->plane mapping).
87   std::tuple<int, std::vector<DrmCompositionPlane>> ProvisionPlanes(
88       std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
89       std::vector<DrmPlane *> *primary_planes,
90       std::vector<DrmPlane *> *overlay_planes);
91
92  private:
93   std::vector<DrmPlane *> GetUsablePlanes(
94       DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
95       std::vector<DrmPlane *> *overlay_planes);
96 };
97 }  // namespace android
98 #endif