DisplayAnalyzer.h revision ab1610b6b232267dd2971ee05dd9dda2cfe2a6a1
165efc253a628175c7afa95c431b746ea20052794Andy Qiu/*
265efc253a628175c7afa95c431b746ea20052794Andy Qiu * Copyright © 2012 Intel Corporation
365efc253a628175c7afa95c431b746ea20052794Andy Qiu * All rights reserved.
465efc253a628175c7afa95c431b746ea20052794Andy Qiu *
565efc253a628175c7afa95c431b746ea20052794Andy Qiu * Permission is hereby granted, free of charge, to any person obtaining a
665efc253a628175c7afa95c431b746ea20052794Andy Qiu * copy of this software and associated documentation files (the "Software"),
765efc253a628175c7afa95c431b746ea20052794Andy Qiu * to deal in the Software without restriction, including without limitation
865efc253a628175c7afa95c431b746ea20052794Andy Qiu * the rights to use, copy, modify, merge, publish, distribute, sublicense,
965efc253a628175c7afa95c431b746ea20052794Andy Qiu * and/or sell copies of the Software, and to permit persons to whom the
1065efc253a628175c7afa95c431b746ea20052794Andy Qiu * Software is furnished to do so, subject to the following conditions:
1165efc253a628175c7afa95c431b746ea20052794Andy Qiu *
1265efc253a628175c7afa95c431b746ea20052794Andy Qiu * The above copyright notice and this permission notice (including the next
1365efc253a628175c7afa95c431b746ea20052794Andy Qiu * paragraph) shall be included in all copies or substantial portions of the
1465efc253a628175c7afa95c431b746ea20052794Andy Qiu * Software.
1565efc253a628175c7afa95c431b746ea20052794Andy Qiu *
1665efc253a628175c7afa95c431b746ea20052794Andy Qiu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1765efc253a628175c7afa95c431b746ea20052794Andy Qiu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1865efc253a628175c7afa95c431b746ea20052794Andy Qiu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1965efc253a628175c7afa95c431b746ea20052794Andy Qiu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2065efc253a628175c7afa95c431b746ea20052794Andy Qiu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2165efc253a628175c7afa95c431b746ea20052794Andy Qiu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2265efc253a628175c7afa95c431b746ea20052794Andy Qiu * IN THE SOFTWARE.
2365efc253a628175c7afa95c431b746ea20052794Andy Qiu *
2465efc253a628175c7afa95c431b746ea20052794Andy Qiu * Authors:
2565efc253a628175c7afa95c431b746ea20052794Andy Qiu *    Jackie Li <yaodong.li@intel.com>
2665efc253a628175c7afa95c431b746ea20052794Andy Qiu *
2765efc253a628175c7afa95c431b746ea20052794Andy Qiu */
2865efc253a628175c7afa95c431b746ea20052794Andy Qiu#ifndef DISPLAY_ANALYZER_H
2965efc253a628175c7afa95c431b746ea20052794Andy Qiu#define DISPLAY_ANALYZER_H
3065efc253a628175c7afa95c431b746ea20052794Andy Qiu
31d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu#include <utils/threads.h>
32eb726af21649d79ed720bdf329e0849270995c45Andy Qiu#include <utils/Vector.h>
3365efc253a628175c7afa95c431b746ea20052794Andy Qiu
3465efc253a628175c7afa95c431b746ea20052794Andy Qiu
3565efc253a628175c7afa95c431b746ea20052794Andy Qiunamespace android {
3665efc253a628175c7afa95c431b746ea20052794Andy Qiunamespace intel {
3765efc253a628175c7afa95c431b746ea20052794Andy Qiu
3865efc253a628175c7afa95c431b746ea20052794Andy Qiu
3965efc253a628175c7afa95c431b746ea20052794Andy Qiuclass DisplayAnalyzer {
4065efc253a628175c7afa95c431b746ea20052794Andy Qiupublic:
4165efc253a628175c7afa95c431b746ea20052794Andy Qiu    DisplayAnalyzer();
4265efc253a628175c7afa95c431b746ea20052794Andy Qiu    virtual ~DisplayAnalyzer();
4365efc253a628175c7afa95c431b746ea20052794Andy Qiu
4465efc253a628175c7afa95c431b746ea20052794Andy Qiupublic:
4565efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool initialize();
46e2ad4c047651d4442f6a0e002290016d45e9201afu jin    void deinitialize();
4765efc253a628175c7afa95c431b746ea20052794Andy Qiu    void analyzeContents(size_t numDisplays, hwc_display_contents_1_t** displays);
4865efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool checkVideoExtendedMode();
495490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    bool isVideoExtendedModeEnabled();
5065efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool isVideoLayer(hwc_layer_1_t &layer);
510131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    bool isVideoFullScreen(int device, hwc_layer_1_t &layer);
52eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    bool isVideoPlaying();
53eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    bool isOverlayAllowed();
54eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void postHotplugEvent(bool connected);
55b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    void postVideoEvent(int instances, int instanceID, bool preparing, bool playing);
56eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void postBlankEvent(bool blank);
57d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    bool isPresentationLayer(hwc_layer_1_t &layer);
5865efc253a628175c7afa95c431b746ea20052794Andy Qiu
5965efc253a628175c7afa95c431b746ea20052794Andy Qiuprivate:
60eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    enum DisplayEventType {
61eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        HOTPLUG_EVENT,
62eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        BLANK_EVENT,
63eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        VIDEO_EVENT,
64eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    };
65eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
66eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    struct Event {
67eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        int type;
68eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
69eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        struct VideoEvent {
70b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie            int instances;
71b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie            int instanceID;
72eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            bool preparing;
73eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            bool playing;
74eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        };
75eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
76eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        union {
77eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            bool connected;
78eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            bool blank;
79eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            VideoEvent videoEvent;
80eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        };
81eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    };
82eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    inline void postEvent(Event& e);
83eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void handlePendingEvents();
84eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void handleHotplugEvent(bool connected);
85eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void handleBlankEvent(bool blank);
86b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    void handleVideoEvent(int instances, int instanceID, bool preparing, bool playing);
87eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
88eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void blankSecondaryDevice();
89eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    void detectVideoExtendedMode();
90770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie    void detectTrickMode(hwc_display_contents_1_t *list);
91b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    void handleModeSwitch();
92ab1610b6b232267dd2971ee05dd9dda2cfe2a6a1Lin Xie    inline void resetCompositionType(hwc_display_contents_1_t *content);
93770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie
94eb726af21649d79ed720bdf329e0849270995c45Andy Qiuprivate:
9565efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool mInitialized;
965490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    bool mEnableVideoExtendedMode;
9765efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool mVideoExtendedMode;
98770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie    bool mForceCloneMode;
99d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    bool mBlankDevice;
100eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    bool mVideoPlaying;
101eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    bool mVideoPreparing;
102b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    bool mVideoStateChanged;
103eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    bool mOverlayAllowed;
104b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    int mVideoInstances;
105b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    int mVideoInstanceId;
106eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    int mCachedNumDisplays;
107eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    hwc_display_contents_1_t** mCachedDisplays;
108eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Vector<Event> mPendingEvents;
109eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Mutex mEventMutex;
1104ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu    Condition mEventHandledCondition;
11165efc253a628175c7afa95c431b746ea20052794Andy Qiu};
11265efc253a628175c7afa95c431b746ea20052794Andy Qiu
11365efc253a628175c7afa95c431b746ea20052794Andy Qiu} // namespace intel
11465efc253a628175c7afa95c431b746ea20052794Andy Qiu} // namespace android
11565efc253a628175c7afa95c431b746ea20052794Andy Qiu
11665efc253a628175c7afa95c431b746ea20052794Andy Qiu
11765efc253a628175c7afa95c431b746ea20052794Andy Qiu
11865efc253a628175c7afa95c431b746ea20052794Andy Qiu#endif /* DISPLAY_ANALYZER_H */
119