1/*
2// Copyright (c) 2014 Intel Corporation 
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#ifndef DISPLAYPLANEMANAGER_H_
17#define DISPLAYPLANEMANAGER_H_
18
19#include <common/utils/Dump.h>
20#include <DisplayPlane.h>
21#include <common/base/HwcLayer.h>
22#include <utils/Vector.h>
23
24namespace android {
25namespace intel {
26
27struct ZOrderLayer
28{
29    ZOrderLayer() {
30        memset(this, 0, sizeof(ZOrderLayer));
31    }
32
33    inline bool operator<(const ZOrderLayer& rhs) const {
34        return zorder < rhs.zorder;
35    }
36
37    int planeType;
38    int zorder;
39    DisplayPlane *plane;
40    HwcLayer *hwcLayer;
41};
42
43class ZOrderConfig : public SortedVector<ZOrderLayer*> {
44public:
45    ZOrderConfig() {}
46
47    int do_compare(const void* lhs, const void* rhs) const {
48        const ZOrderLayer *l = *(ZOrderLayer**)lhs;
49        const ZOrderLayer *r = *(ZOrderLayer**)rhs;
50
51        // sorted from z order 0 to n
52        return l->zorder - r->zorder;
53    }
54};
55
56
57class DisplayPlaneManager {
58public:
59    DisplayPlaneManager();
60    virtual ~DisplayPlaneManager();
61
62public:
63    virtual bool initialize();
64    virtual void deinitialize();
65
66    virtual bool isValidZOrder(int dsp, ZOrderConfig& config) = 0;
67    virtual bool assignPlanes(int dsp, ZOrderConfig& config) = 0;
68    // TODO: remove this API
69    virtual void* getZOrderConfig() const = 0;
70    virtual int getFreePlanes(int dsp, int type);
71    virtual void reclaimPlane(int dsp, DisplayPlane& plane);
72    virtual void disableReclaimedPlanes();
73    virtual bool isOverlayPlanesDisabled();
74    // dump interface
75    virtual void dump(Dump& d);
76
77protected:
78    // plane allocation & free
79    int getPlane(uint32_t& mask);
80    int getPlane(uint32_t& mask, int index);
81    DisplayPlane* getPlane(int type, int index);
82    DisplayPlane* getAnyPlane(int type);
83    void putPlane(int index, uint32_t& mask);
84    void putPlane(int dsp, DisplayPlane& plane);
85    bool isFreePlane(int type, int index);
86    virtual DisplayPlane* allocPlane(int index, int type) = 0;
87
88protected:
89    int mPlaneCount[DisplayPlane::PLANE_MAX];
90    int mTotalPlaneCount;
91    int mPrimaryPlaneCount;
92    int mSpritePlaneCount;
93    int mOverlayPlaneCount;
94    int mCursorPlaneCount;
95
96    Vector<DisplayPlane*> mPlanes[DisplayPlane::PLANE_MAX];
97
98    // Bitmap of free planes. Bit0 - plane A, bit 1 - plane B, etc.
99    uint32_t mFreePlanes[DisplayPlane::PLANE_MAX];
100    uint32_t mReclaimedPlanes[DisplayPlane::PLANE_MAX];
101
102    bool mInitialized;
103
104enum {
105    DEFAULT_PRIMARY_PLANE_COUNT = 3
106};
107};
108
109} // namespace intel
110} // namespace android
111
112#endif /* DISPLAYPLANEMANAGER_H_ */
113