DisplayAnalyzer.h revision 7546c3bf1068951d79db52cc060acb5739026db5
1/*
2 * Copyright © 2012 Intel Corporation
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * Authors:
25 *    Jackie Li <yaodong.li@intel.com>
26 *
27 */
28#ifndef DISPLAY_ANALYZER_H
29#define DISPLAY_ANALYZER_H
30
31#include <utils/threads.h>
32#include <utils/Vector.h>
33
34
35namespace android {
36namespace intel {
37
38
39class DisplayAnalyzer {
40public:
41    DisplayAnalyzer();
42    virtual ~DisplayAnalyzer();
43
44public:
45    bool initialize();
46    void deinitialize();
47    void analyzeContents(size_t numDisplays, hwc_display_contents_1_t** displays);
48    bool isVideoExtModeActive();
49    bool isVideoExtModeEnabled();
50    bool isVideoLayer(hwc_layer_1_t &layer);
51    bool isVideoFullScreen(int device, hwc_layer_1_t &layer);
52    bool isOverlayAllowed();
53    int  getVideoInstances();
54    void postHotplugEvent(bool connected);
55    void postVideoEvent(int instanceID, int state);
56    void postInputEvent(bool active);
57    void postVideoEvent(int instances, int instanceID, bool preparing, bool playing);
58    void postBlankEvent(bool blank);
59    void postIdleEntryEvent();
60    bool isPresentationLayer(hwc_layer_1_t &layer);
61    bool isProtectedLayer(hwc_layer_1_t &layer);
62    int  getFirstVideoInstanceSessionID();
63
64private:
65    enum DisplayEventType {
66        HOTPLUG_EVENT,
67        BLANK_EVENT,
68        VIDEO_EVENT,
69        TIMING_EVENT,
70        INPUT_EVENT,
71        DPMS_EVENT,
72        IDLE_ENTRY_EVENT,
73        IDLE_EXIT_EVENT,
74    };
75
76    struct Event {
77        int type;
78
79        struct VideoEvent {
80            int instanceID;
81            int state;
82        };
83
84        union {
85            bool bValue;
86            int  nValue;
87            VideoEvent videoEvent;
88        };
89    };
90    inline void postEvent(Event& e);
91    inline bool getEvent(Event& e);
92    void handlePendingEvents();
93    void handleHotplugEvent(bool connected);
94    void handleBlankEvent(bool blank);
95    void handleVideoEvent(int instanceID, int state);
96    void handleTimingEvent();
97    void handleInputEvent(bool active);
98    void handleDpmsEvent(int delayCount);
99    void handleIdleEntryEvent(int count);
100    void handleIdleExitEvent();
101
102    void blankSecondaryDevice();
103    void handleVideoExtMode();
104    void checkVideoExtMode();
105    void enterVideoExtMode();
106    void exitVideoExtMode();
107    bool hasProtectedLayer();
108    inline void setCompositionType(hwc_display_contents_1_t *content, int type);
109    inline void setCompositionType(int device, int type, bool reset);
110
111private:
112    // Video playback state, must match defintion in Multi Display Service
113    enum
114    {
115        VIDEO_PLAYBACK_IDLE,
116        VIDEO_PLAYBACK_STARTING,
117        VIDEO_PLAYBACK_STARTED,
118        VIDEO_PLAYBACK_STOPPING,
119        VIDEO_PLAYBACK_STOPPED,
120    };
121
122    enum
123    {
124        // number of idle flips before display can enter idle mode
125        // minimum delay is 1
126        DELAY_BEFORE_IDLE_ENTRY = 2,
127
128        // number of flips before display can be powered off in video extended mode
129        DELAY_BEFORE_DPMS_OFF = 0,
130    };
131
132private:
133    bool mInitialized;
134    bool mVideoExtModeEnabled;
135    bool mVideoExtModeEligible;
136    bool mVideoExtModeActive;
137    bool mBlankDevice;
138    bool mOverlayAllowed;
139    bool mActiveInputState;
140    // map video instance ID to video state
141    KeyedVector<int, int> mVideoStateMap;
142    int mCachedNumDisplays;
143    hwc_display_contents_1_t** mCachedDisplays;
144    Vector<Event> mPendingEvents;
145    Mutex mEventMutex;
146    Condition mEventHandledCondition;
147};
148
149} // namespace intel
150} // namespace android
151
152
153
154#endif /* DISPLAY_ANALYZER_H */
155