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 DISPLAY_ANALYZER_H
17#define DISPLAY_ANALYZER_H
18
19#include <utils/threads.h>
20#include <utils/Vector.h>
21
22
23namespace android {
24namespace intel {
25
26
27class DisplayAnalyzer {
28public:
29    DisplayAnalyzer();
30    virtual ~DisplayAnalyzer();
31
32public:
33    bool initialize();
34    void deinitialize();
35    void analyzeContents(size_t numDisplays, hwc_display_contents_1_t** displays);
36    bool isVideoExtModeActive();
37    bool isVideoExtModeEnabled();
38    bool isVideoLayer(hwc_layer_1_t &layer);
39    bool isVideoFullScreen(int device, hwc_layer_1_t &layer);
40    bool isOverlayAllowed();
41    int  getVideoInstances();
42    void postHotplugEvent(bool connected);
43    void postVideoEvent(int instanceID, int state);
44    void postInputEvent(bool active);
45    void postVideoEvent(int instances, int instanceID, bool preparing, bool playing);
46    void postBlankEvent(bool blank);
47    void postIdleEntryEvent();
48    bool isPresentationLayer(hwc_layer_1_t &layer);
49    bool isProtectedLayer(hwc_layer_1_t &layer);
50    bool ignoreVideoSkipFlag();
51    int  getFirstVideoInstanceSessionID();
52
53private:
54    enum DisplayEventType {
55        HOTPLUG_EVENT,
56        BLANK_EVENT,
57        VIDEO_EVENT,
58        TIMING_EVENT,
59        INPUT_EVENT,
60        DPMS_EVENT,
61        IDLE_ENTRY_EVENT,
62        IDLE_EXIT_EVENT,
63        VIDEO_CHECK_EVENT,
64    };
65
66    struct Event {
67        int type;
68
69        struct VideoEvent {
70            int instanceID;
71            int state;
72        };
73
74        union {
75            bool bValue;
76            int  nValue;
77            VideoEvent videoEvent;
78        };
79    };
80    inline void postEvent(Event& e);
81    inline bool getEvent(Event& e);
82    void handlePendingEvents();
83    void handleHotplugEvent(bool connected);
84    void handleBlankEvent(bool blank);
85    void handleVideoEvent(int instanceID, int state);
86    void handleTimingEvent();
87    void handleInputEvent(bool active);
88    void handleDpmsEvent(int delayCount);
89    void handleIdleEntryEvent(int count);
90    void handleIdleExitEvent();
91    void handleVideoCheckEvent();
92
93    void blankSecondaryDevice();
94    void handleVideoExtMode();
95    void checkVideoExtMode();
96    void enterVideoExtMode();
97    void exitVideoExtMode();
98    bool hasProtectedLayer();
99    inline void setCompositionType(hwc_display_contents_1_t *content, int type);
100    inline void setCompositionType(int device, int type, bool reset);
101
102private:
103    // Video playback state, must match defintion in Multi Display Service
104    enum
105    {
106        VIDEO_PLAYBACK_IDLE,
107        VIDEO_PLAYBACK_STARTING,
108        VIDEO_PLAYBACK_STARTED,
109        VIDEO_PLAYBACK_STOPPING,
110        VIDEO_PLAYBACK_STOPPED,
111    };
112
113    enum
114    {
115        // number of flips before display can be powered off in video extended mode
116        DELAY_BEFORE_DPMS_OFF = 0,
117    };
118
119private:
120    bool mInitialized;
121    bool mVideoExtModeEnabled;
122    bool mVideoExtModeEligible;
123    bool mVideoExtModeActive;
124    bool mBlankDevice;
125    bool mOverlayAllowed;
126    bool mActiveInputState;
127    // workaround HWC_SKIP_LAYER set during rotation for extended video mode
128    // by default if layer has HWC_SKIP_LAYER flag it should not be processed by HWC
129    bool mIgnoreVideoSkipFlag;
130    bool mProtectedVideoSession;
131    // map video instance ID to video state
132    KeyedVector<int, int> mVideoStateMap;
133    int mCachedNumDisplays;
134    hwc_display_contents_1_t** mCachedDisplays;
135    Vector<Event> mPendingEvents;
136    Mutex mEventMutex;
137    Condition mEventHandledCondition;
138};
139
140} // namespace intel
141} // namespace android
142
143
144
145#endif /* DISPLAY_ANALYZER_H */
146