DisplayAnalyzer.h revision 177b44e0661a92d06f8f37c51e59af86423f7a95
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    bool isPresentationLayer(hwc_layer_1_t &layer);
60    bool isProtectedLayer(hwc_layer_1_t &layer);
61
62private:
63    enum DisplayEventType {
64        HOTPLUG_EVENT,
65        BLANK_EVENT,
66        VIDEO_EVENT,
67        TIMING_EVENT,
68        INPUT_EVENT,
69        DPMS_EVENT
70    };
71
72    struct Event {
73        int type;
74
75        struct VideoEvent {
76            int instanceID;
77            int state;
78        };
79
80        union {
81            bool bValue;
82            int  nValue;
83            VideoEvent videoEvent;
84        };
85    };
86    inline void postEvent(Event& e);
87    inline bool getEvent(Event& e);
88    void handlePendingEvents();
89    void handleHotplugEvent(bool connected);
90    void handleBlankEvent(bool blank);
91    void handleVideoEvent(int instanceID, int state);
92    void handleTimingEvent();
93    void handleInputEvent(bool active);
94    void handleDpmsEvent(int delayCount);
95
96    void blankSecondaryDevice();
97    void handleVideoExtMode();
98    void checkVideoExtMode();
99    void enterVideoExtMode();
100    void exitVideoExtMode();
101    bool hasProtectedLayer();
102    inline void setCompositionType(hwc_display_contents_1_t *content, int type);
103    inline void setCompositionType(int device, int type, bool reset);
104
105private:
106    // Video playback state, must match defintion in Multi Display Service
107    enum
108    {
109        VIDEO_PLAYBACK_IDLE,
110        VIDEO_PLAYBACK_STARTING,
111        VIDEO_PLAYBACK_STARTED,
112        VIDEO_PLAYBACK_STOPPING,
113        VIDEO_PLAYBACK_STOPPED,
114    };
115
116    enum
117    {
118        // number of flips before display can be powered off in video extended mode
119        DELAY_BEFORE_DPMS_OFF = 10,
120    };
121
122private:
123    bool mInitialized;
124    bool mVideoExtModeEnabled;
125    bool mVideoExtModeEligible;
126    bool mVideoExtModeActive;
127    bool mBlankDevice;
128    bool mOverlayAllowed;
129    bool mActiveInputState;
130    // map video instance ID to video state
131    KeyedVector<int, int> mVideoStateMap;
132    int mCachedNumDisplays;
133    hwc_display_contents_1_t** mCachedDisplays;
134    Vector<Event> mPendingEvents;
135    Mutex mEventMutex;
136    Condition mEventHandledCondition;
137};
138
139} // namespace intel
140} // namespace android
141
142
143
144#endif /* DISPLAY_ANALYZER_H */
145