DisplayAnalyzer.h revision 0ab7fc9e013631bad1f404d8a6300137f4bce0cb
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 bool ignoreVideoSkipFlag(); 63 int getFirstVideoInstanceSessionID(); 64 65private: 66 enum DisplayEventType { 67 HOTPLUG_EVENT, 68 BLANK_EVENT, 69 VIDEO_EVENT, 70 TIMING_EVENT, 71 INPUT_EVENT, 72 DPMS_EVENT, 73 IDLE_ENTRY_EVENT, 74 IDLE_EXIT_EVENT, 75 VIDEO_CHECK_EVENT, 76 }; 77 78 struct Event { 79 int type; 80 81 struct VideoEvent { 82 int instanceID; 83 int state; 84 }; 85 86 union { 87 bool bValue; 88 int nValue; 89 VideoEvent videoEvent; 90 }; 91 }; 92 inline void postEvent(Event& e); 93 inline bool getEvent(Event& e); 94 void handlePendingEvents(); 95 void handleHotplugEvent(bool connected); 96 void handleBlankEvent(bool blank); 97 void handleVideoEvent(int instanceID, int state); 98 void handleTimingEvent(); 99 void handleInputEvent(bool active); 100 void handleDpmsEvent(int delayCount); 101 void handleIdleEntryEvent(int count); 102 void handleIdleExitEvent(); 103 void handleVideoCheckEvent(); 104 105 void blankSecondaryDevice(); 106 void handleVideoExtMode(); 107 void checkVideoExtMode(); 108 void enterVideoExtMode(); 109 void exitVideoExtMode(); 110 bool hasProtectedLayer(); 111 inline void setCompositionType(hwc_display_contents_1_t *content, int type); 112 inline void setCompositionType(int device, int type, bool reset); 113 114private: 115 // Video playback state, must match defintion in Multi Display Service 116 enum 117 { 118 VIDEO_PLAYBACK_IDLE, 119 VIDEO_PLAYBACK_STARTING, 120 VIDEO_PLAYBACK_STARTED, 121 VIDEO_PLAYBACK_STOPPING, 122 VIDEO_PLAYBACK_STOPPED, 123 }; 124 125 enum 126 { 127 // number of idle flips before display can enter idle mode 128 // we can set maxfifo even with more than one plane is active, 129 // display controller will check whether condition is met to 130 // enter into maxfifo, so no need to delay. 131 DELAY_BEFORE_IDLE_ENTRY = 0, 132 133 // number of flips before display can be powered off in video extended mode 134 DELAY_BEFORE_DPMS_OFF = 0, 135 }; 136 137private: 138 bool mInitialized; 139 bool mVideoExtModeEnabled; 140 bool mVideoExtModeEligible; 141 bool mVideoExtModeActive; 142 bool mBlankDevice; 143 bool mOverlayAllowed; 144 bool mActiveInputState; 145 // workaround HWC_SKIP_LAYER set during rotation for extended video mode 146 // by default if layer has HWC_SKIP_LAYER flag it should not be processed by HWC 147 bool mIgnoreVideoSkipFlag; 148 // map video instance ID to video state 149 KeyedVector<int, int> mVideoStateMap; 150 int mCachedNumDisplays; 151 hwc_display_contents_1_t** mCachedDisplays; 152 Vector<Event> mPendingEvents; 153 Mutex mEventMutex; 154 Condition mEventHandledCondition; 155}; 156 157} // namespace intel 158} // namespace android 159 160 161 162#endif /* DISPLAY_ANALYZER_H */ 163