DisplayAnalyzer.h revision ef111c2d5fb42bfcefca8e774837e12cc1940d80
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 checkVideoExtendedMode();
49    bool isVideoExtendedModeEnabled();
50    bool isVideoLayer(hwc_layer_1_t &layer);
51    bool isVideoFullScreen(int device, hwc_layer_1_t &layer);
52    bool isVideoPlaying();
53    bool isOverlayAllowed();
54    void postHotplugEvent(bool connected);
55    void postVideoEvent(int instances, int instanceID, bool preparing, bool playing);
56    void postBlankEvent(bool blank);
57    bool isPresentationLayer(hwc_layer_1_t &layer);
58    bool isProtectedLayer(hwc_layer_1_t &layer);
59
60private:
61    enum DisplayEventType {
62        HOTPLUG_EVENT,
63        BLANK_EVENT,
64        VIDEO_EVENT,
65    };
66
67    struct Event {
68        int type;
69
70        struct VideoEvent {
71            int instances;
72            int instanceID;
73            bool preparing;
74            bool playing;
75        };
76
77        union {
78            bool connected;
79            bool blank;
80            VideoEvent videoEvent;
81        };
82    };
83    inline void postEvent(Event& e);
84    void handlePendingEvents();
85    void handleHotplugEvent(bool connected);
86    void handleBlankEvent(bool blank);
87    void handleVideoEvent(int instances, int instanceID, bool preparing, bool playing);
88
89    void blankSecondaryDevice();
90    void detectVideoExtendedMode();
91    void detectTrickMode(hwc_display_contents_1_t *list);
92    void handleModeSwitch();
93    inline void resetCompositionType(hwc_display_contents_1_t *content);
94
95private:
96    bool mInitialized;
97    bool mEnableVideoExtendedMode;
98    bool mVideoExtendedMode;
99    bool mForceCloneMode;
100    bool mBlankDevice;
101    bool mVideoPlaying;
102    bool mVideoPreparing;
103    bool mVideoStateChanged;
104    bool mOverlayAllowed;
105    int mVideoInstances;
106    int mVideoInstanceId;
107    int mCachedNumDisplays;
108    hwc_display_contents_1_t** mCachedDisplays;
109    Vector<Event> mPendingEvents;
110    Mutex mEventMutex;
111    Condition mEventHandledCondition;
112};
113
114} // namespace intel
115} // namespace android
116
117
118
119#endif /* DISPLAY_ANALYZER_H */
120