DisplayAnalyzer.cpp revision 0594c42af26255fd8d3d7d39c0cb0e2da5b8841b
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
290594c42af26255fd8d3d7d39c0cb0e2da5b8841bThierry Strudel#include <common/utils/HwcTrace.h>
3065efc253a628175c7afa95c431b746ea20052794Andy Qiu#include <IDisplayDevice.h>
3165efc253a628175c7afa95c431b746ea20052794Andy Qiu#include <DisplayQuery.h>
3265efc253a628175c7afa95c431b746ea20052794Andy Qiu#include <BufferManager.h>
3365efc253a628175c7afa95c431b746ea20052794Andy Qiu#include <DisplayPlaneManager.h>
3465efc253a628175c7afa95c431b746ea20052794Andy Qiu#include <Hwcomposer.h>
350594c42af26255fd8d3d7d39c0cb0e2da5b8841bThierry Strudel#include <common/base/DisplayAnalyzer.h>
365490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu#include <cutils/properties.h>
37ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi#include <GraphicBuffer.h>
382413102f33fdefa6bdb80ed2c4f56fae83cd5bd8fu jin#include <ExternalDevice.h>
3965efc253a628175c7afa95c431b746ea20052794Andy Qiu
4065efc253a628175c7afa95c431b746ea20052794Andy Qiunamespace android {
4165efc253a628175c7afa95c431b746ea20052794Andy Qiunamespace intel {
4265efc253a628175c7afa95c431b746ea20052794Andy Qiu
4365efc253a628175c7afa95c431b746ea20052794Andy QiuDisplayAnalyzer::DisplayAnalyzer()
4465efc253a628175c7afa95c431b746ea20052794Andy Qiu    : mInitialized(false),
45177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu      mVideoExtModeEnabled(true),
46177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu      mVideoExtModeEligible(false),
47177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu      mVideoExtModeActive(false),
48d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu      mBlankDevice(false),
49eb726af21649d79ed720bdf329e0849270995c45Andy Qiu      mOverlayAllowed(true),
50177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu      mActiveInputState(true),
510ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu      mIgnoreVideoSkipFlag(false),
52009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang      mProtectedVideoSession(false),
53eb726af21649d79ed720bdf329e0849270995c45Andy Qiu      mCachedNumDisplays(0),
54eb726af21649d79ed720bdf329e0849270995c45Andy Qiu      mCachedDisplays(0),
55eb726af21649d79ed720bdf329e0849270995c45Andy Qiu      mPendingEvents(),
564ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu      mEventMutex(),
574ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu      mEventHandledCondition()
5865efc253a628175c7afa95c431b746ea20052794Andy Qiu{
5965efc253a628175c7afa95c431b746ea20052794Andy Qiu}
6065efc253a628175c7afa95c431b746ea20052794Andy Qiu
6165efc253a628175c7afa95c431b746ea20052794Andy QiuDisplayAnalyzer::~DisplayAnalyzer()
6265efc253a628175c7afa95c431b746ea20052794Andy Qiu{
6365efc253a628175c7afa95c431b746ea20052794Andy Qiu}
6465efc253a628175c7afa95c431b746ea20052794Andy Qiu
6565efc253a628175c7afa95c431b746ea20052794Andy Qiubool DisplayAnalyzer::initialize()
6665efc253a628175c7afa95c431b746ea20052794Andy Qiu{
675490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    // by default video extended mode is enabled
685490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    char prop[PROPERTY_VALUE_MAX];
695490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    if (property_get("hwc.video.extmode.enable", prop, "1") > 0) {
70177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        mVideoExtModeEnabled = atoi(prop) ? true : false;
715490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    }
72177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mVideoExtModeEligible = false;
73177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mVideoExtModeActive = false;
74d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    mBlankDevice = false;
75eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mOverlayAllowed = true;
76177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mActiveInputState = true;
770ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    mIgnoreVideoSkipFlag = false;
78009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang    mProtectedVideoSession = false;
79eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mCachedNumDisplays = 0;
80eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mCachedDisplays = 0;
81eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mPendingEvents.clear();
82b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    mVideoStateMap.clear();
8365efc253a628175c7afa95c431b746ea20052794Andy Qiu    mInitialized = true;
84b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie
8565efc253a628175c7afa95c431b746ea20052794Andy Qiu    return true;
8665efc253a628175c7afa95c431b746ea20052794Andy Qiu}
8765efc253a628175c7afa95c431b746ea20052794Andy Qiu
88e2ad4c047651d4442f6a0e002290016d45e9201afu jinvoid DisplayAnalyzer::deinitialize()
8965efc253a628175c7afa95c431b746ea20052794Andy Qiu{
90eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mPendingEvents.clear();
91b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    mVideoStateMap.clear();
9265efc253a628175c7afa95c431b746ea20052794Andy Qiu    mInitialized = false;
9365efc253a628175c7afa95c431b746ea20052794Andy Qiu}
9465efc253a628175c7afa95c431b746ea20052794Andy Qiu
95770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xievoid DisplayAnalyzer::analyzeContents(
96770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie        size_t numDisplays, hwc_display_contents_1_t** displays)
97770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie{
98eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    // cache and use them only in this context during analysis
99eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mCachedNumDisplays = numDisplays;
100eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mCachedDisplays = displays;
101eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
102eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    handlePendingEvents();
103eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
10447630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    // FIXME: WA for ASUS Face unlock screen flicker issue
10547630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    // If layer count exceeds plane max number, force GLES
10647630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    hwc_display_contents_1_t *content = NULL;
10747630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    for (int i = 0; i < (int)mCachedNumDisplays; i++) {
10847630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        content = mCachedDisplays[i];
10947630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        if (content == NULL) {
11047630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang            continue;
11147630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        }
11247630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
11347630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        if ((content->flags & HWC_GEOMETRY_CHANGED) &&
11447630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang            (content->numHwLayers > 5) &&
11547630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang            !hasVideoLayer(i))
11647630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang            setCompositionType(i, HWC_FORCE_FRAMEBUFFER, true);
11747630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    }
11847630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
119177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (mVideoExtModeEnabled) {
120177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        handleVideoExtMode();
121770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie    }
122b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
123b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (mBlankDevice) {
124b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        // this will make sure device is blanked after geometry changes.
125b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        // blank event is only processed once
126b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        blankSecondaryDevice();
127b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
128770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie}
129770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie
130177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::handleVideoExtMode()
131770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie{
132177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    bool eligible = mVideoExtModeEligible;
133177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    checkVideoExtMode();
134177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (eligible == mVideoExtModeEligible) {
135177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        if (mVideoExtModeActive) {
136177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu            // need to mark all layers
137177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu            setCompositionType(0, HWC_OVERLAY, false);
138770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie        }
139177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
140770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie    }
141770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie
142177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (mVideoExtModeEligible) {
143177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        if (mActiveInputState) {
144177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu            VTRACE("input is active");
145177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        } else {
146177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu            enterVideoExtMode();
147177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        }
148177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    } else {
149177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        exitVideoExtMode();
150770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie    }
151770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie}
152770346b3b6f55e10c54c8a47d4db8f8907035173Lin Xie
153177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::checkVideoExtMode()
15465efc253a628175c7afa95c431b746ea20052794Andy Qiu{
155b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (mVideoStateMap.size() != 1) {
156177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        mVideoExtModeEligible = false;
157eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        return;
158eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    }
159eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
16065efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool geometryChanged = false;
16165efc253a628175c7afa95c431b746ea20052794Andy Qiu    int activeDisplays = 0;
162d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu
16365efc253a628175c7afa95c431b746ea20052794Andy Qiu    hwc_display_contents_1_t *content = NULL;
164eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    for (int i = 0; i < (int)mCachedNumDisplays; i++) {
165eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        content = mCachedDisplays[i];
16665efc253a628175c7afa95c431b746ea20052794Andy Qiu        if (content == NULL) {
16765efc253a628175c7afa95c431b746ea20052794Andy Qiu            continue;
16865efc253a628175c7afa95c431b746ea20052794Andy Qiu        }
16965efc253a628175c7afa95c431b746ea20052794Andy Qiu        activeDisplays++;
17065efc253a628175c7afa95c431b746ea20052794Andy Qiu        if (content->flags & HWC_GEOMETRY_CHANGED) {
17165efc253a628175c7afa95c431b746ea20052794Andy Qiu            geometryChanged = true;
17265efc253a628175c7afa95c431b746ea20052794Andy Qiu        }
17365efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
17465efc253a628175c7afa95c431b746ea20052794Andy Qiu
17565efc253a628175c7afa95c431b746ea20052794Andy Qiu    if (activeDisplays <= 1) {
176177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        mVideoExtModeEligible = false;
17765efc253a628175c7afa95c431b746ea20052794Andy Qiu        return;
17865efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
17965efc253a628175c7afa95c431b746ea20052794Andy Qiu
180177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // video state update event may come later than geometry change event.
181177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // in that case, video extended mode is not detected properly.
182177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu#if 0
18365efc253a628175c7afa95c431b746ea20052794Andy Qiu    if (geometryChanged == false) {
18465efc253a628175c7afa95c431b746ea20052794Andy Qiu        // use previous analysis result
18565efc253a628175c7afa95c431b746ea20052794Andy Qiu        return;
18665efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
187177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu#endif
188177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // reset eligibility of video extended mode
189177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mVideoExtModeEligible = false;
19065efc253a628175c7afa95c431b746ea20052794Andy Qiu
19165efc253a628175c7afa95c431b746ea20052794Andy Qiu    // check if there is video layer in the primary device
192eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    content = mCachedDisplays[0];
19365efc253a628175c7afa95c431b746ea20052794Andy Qiu    if (content == NULL) {
19465efc253a628175c7afa95c431b746ea20052794Andy Qiu        return;
19565efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
19665efc253a628175c7afa95c431b746ea20052794Andy Qiu
197d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    uint32_t videoHandle = 0;
19865efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool videoLayerExist = false;
199319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    bool videoFullScreenOnPrimary = false;
2002f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang    bool isVideoLayerSkipped = false;
2014a3844e0ffd267aae9ffbe5a3266c8e3c0dc7070Zhu,Tianyang
20265efc253a628175c7afa95c431b746ea20052794Andy Qiu    // exclude the frame buffer target layer
20365efc253a628175c7afa95c431b746ea20052794Andy Qiu    for (int j = 0; j < (int)content->numHwLayers - 1; j++) {
20465efc253a628175c7afa95c431b746ea20052794Andy Qiu        videoLayerExist = isVideoLayer(content->hwLayers[j]);
205bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie        if (videoLayerExist) {
2064a3844e0ffd267aae9ffbe5a3266c8e3c0dc7070Zhu,Tianyang            if ((content->hwLayers[j].flags & HWC_SKIP_LAYER)) {
2072f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang                isVideoLayerSkipped = true;
2084a3844e0ffd267aae9ffbe5a3266c8e3c0dc7070Zhu,Tianyang            }
20965efc253a628175c7afa95c431b746ea20052794Andy Qiu            videoHandle = (uint32_t)content->hwLayers[j].handle;
210319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu            videoFullScreenOnPrimary = isVideoFullScreen(0, content->hwLayers[j]);
21165efc253a628175c7afa95c431b746ea20052794Andy Qiu            break;
21265efc253a628175c7afa95c431b746ea20052794Andy Qiu        }
21365efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
21465efc253a628175c7afa95c431b746ea20052794Andy Qiu
21565efc253a628175c7afa95c431b746ea20052794Andy Qiu    if (videoLayerExist == false) {
21665efc253a628175c7afa95c431b746ea20052794Andy Qiu        // no video layer is found in the primary layer
21765efc253a628175c7afa95c431b746ea20052794Andy Qiu        return;
21865efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
21965efc253a628175c7afa95c431b746ea20052794Andy Qiu
22065efc253a628175c7afa95c431b746ea20052794Andy Qiu    // check whether video layer exists in external device or virtual device
22165efc253a628175c7afa95c431b746ea20052794Andy Qiu    // TODO: video may exist in virtual device but no in external device or vice versa
22265efc253a628175c7afa95c431b746ea20052794Andy Qiu    // TODO: multiple video layers are not addressed here
223eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    for (int i = 1; i < (int)mCachedNumDisplays; i++) {
224eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        content = mCachedDisplays[i];
22565efc253a628175c7afa95c431b746ea20052794Andy Qiu        if (content == NULL) {
22665efc253a628175c7afa95c431b746ea20052794Andy Qiu            continue;
22765efc253a628175c7afa95c431b746ea20052794Andy Qiu        }
22865efc253a628175c7afa95c431b746ea20052794Andy Qiu
22965efc253a628175c7afa95c431b746ea20052794Andy Qiu        // exclude the frame buffer target layer
23065efc253a628175c7afa95c431b746ea20052794Andy Qiu        for (int j = 0; j < (int)content->numHwLayers - 1; j++) {
23165efc253a628175c7afa95c431b746ea20052794Andy Qiu            if ((uint32_t)content->hwLayers[j].handle == videoHandle) {
2322f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang                isVideoLayerSkipped |= (content->hwLayers[j].flags & HWC_SKIP_LAYER);
2339332f677fa9b02f55ff910ca08a36eb6f23030d6Andy Qiu                VTRACE("video layer exists in device %d", i);
2342f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang                if (isVideoLayerSkipped || videoFullScreenOnPrimary){
2352f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang                    VTRACE("Video ext mode eligible, %d, %d",
2362f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang                            isVideoLayerSkipped, videoFullScreenOnPrimary);
237319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu                    mVideoExtModeEligible = true;
238319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu                } else {
239319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu                    mVideoExtModeEligible = isVideoFullScreen(i, content->hwLayers[j]);
240319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu                }
24165efc253a628175c7afa95c431b746ea20052794Andy Qiu                return;
24265efc253a628175c7afa95c431b746ea20052794Andy Qiu            }
24365efc253a628175c7afa95c431b746ea20052794Andy Qiu        }
24465efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
24565efc253a628175c7afa95c431b746ea20052794Andy Qiu}
24665efc253a628175c7afa95c431b746ea20052794Andy Qiu
247177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiubool DisplayAnalyzer::isVideoExtModeActive()
24865efc253a628175c7afa95c431b746ea20052794Andy Qiu{
249177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    return mVideoExtModeActive;
25065efc253a628175c7afa95c431b746ea20052794Andy Qiu}
25165efc253a628175c7afa95c431b746ea20052794Andy Qiu
252177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiubool DisplayAnalyzer::isVideoExtModeEnabled()
2535490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu{
2545490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu#if 1
2555490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    // enable it for run-time debugging purpose.
2565490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    char prop[PROPERTY_VALUE_MAX];
2575490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    if (property_get("hwc.video.extmode.enable", prop, "1") > 0) {
258177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        mVideoExtModeEnabled = atoi(prop) ? true : false;
2595490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu    }
260177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    ITRACE("video extended mode enabled: %d", mVideoExtModeEnabled);
2615490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu#endif
2625490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu
263177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    return mVideoExtModeEnabled;
2645490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu}
2655490411cb9330d4e92d59878da3693c33a948ad6Andy Qiu
26665efc253a628175c7afa95c431b746ea20052794Andy Qiubool DisplayAnalyzer::isVideoLayer(hwc_layer_1_t &layer)
26765efc253a628175c7afa95c431b746ea20052794Andy Qiu{
26865efc253a628175c7afa95c431b746ea20052794Andy Qiu    bool ret = false;
26965efc253a628175c7afa95c431b746ea20052794Andy Qiu    BufferManager *bm = Hwcomposer::getInstance().getBufferManager();
270eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    if (!layer.handle) {
271eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        return false;
272eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    }
273eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    DataBuffer *buffer = bm->lockDataBuffer((uint32_t)layer.handle);
27465efc253a628175c7afa95c431b746ea20052794Andy Qiu     if (!buffer) {
27565efc253a628175c7afa95c431b746ea20052794Andy Qiu         ETRACE("failed to get buffer");
27665efc253a628175c7afa95c431b746ea20052794Andy Qiu     } else {
27765efc253a628175c7afa95c431b746ea20052794Andy Qiu        ret = DisplayQuery::isVideoFormat(buffer->getFormat());
278eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        bm->unlockDataBuffer(buffer);
27965efc253a628175c7afa95c431b746ea20052794Andy Qiu    }
28065efc253a628175c7afa95c431b746ea20052794Andy Qiu    return ret;
28165efc253a628175c7afa95c431b746ea20052794Andy Qiu}
28265efc253a628175c7afa95c431b746ea20052794Andy Qiu
2830131f123eba74813aca3eaaf99cd418b6b558416Andy Qiubool DisplayAnalyzer::isVideoFullScreen(int device, hwc_layer_1_t &layer)
284bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie{
2850131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    IDisplayDevice *displayDevice = Hwcomposer::getInstance().getDisplayDevice(device);
2860131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    if (!displayDevice) {
287bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie        return false;
288bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie    }
2890131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    int width = 0, height = 0;
2900131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    if (!displayDevice->getDisplaySize(&width, &height)) {
2910131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu        return false;
2920131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    }
2930131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu
2949332f677fa9b02f55ff910ca08a36eb6f23030d6Andy Qiu    VTRACE("video left %d, right %d, top %d, bottom %d, device width %d, height %d",
2950131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu        layer.displayFrame.left, layer.displayFrame.right,
2960131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu        layer.displayFrame.top, layer.displayFrame.bottom,
2970131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu        width, height);
298bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie
299319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    // full-screen defintion:
300319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    // width of target display frame == width of target device, with 1 pixel of tolerance, or
301319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    // Height of target display frame == height of target device, with 1 pixel of tolerance, or
302319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    // width * height of display frame > 90% of width * height of display device, or
303319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu    // any of above condition is met on either primary display or secondary display
304bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie    int dstW = layer.displayFrame.right - layer.displayFrame.left;
305bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie    int dstH = layer.displayFrame.bottom - layer.displayFrame.top;
30601b4571b91a4ef92f2a00bd98b2797f10538e431lychenx
3072f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang    if (abs(dstW - width) <= 1 &&
3082f6c0128167508e86c3daf83e7b60f3b5f16f7acZhu,Tianyang        abs(dstH - height) <= 1 &&
309319e5478ad0ed4a50df6190a7d529e020051eb50Andy Qiu        dstW * dstH * 10 < width * height * 9) {
3109332f677fa9b02f55ff910ca08a36eb6f23030d6Andy Qiu        VTRACE("video is not full-screen");
3110131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu        return false;
312bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie    }
3130131f123eba74813aca3eaaf99cd418b6b558416Andy Qiu    return true;
314bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie}
315bd5ed146ffeb236f3c5cc20b2ebaf6a850b54007Lin Xie
316eb726af21649d79ed720bdf329e0849270995c45Andy Qiubool DisplayAnalyzer::isOverlayAllowed()
317eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
318eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    return mOverlayAllowed;
319eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
320eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
32135fc4846ba9657d6d2638e68d810618fedec7ecdAshish Singhiint DisplayAnalyzer::getVideoInstances()
32235fc4846ba9657d6d2638e68d810618fedec7ecdAshish Singhi{
323b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    return (int)mVideoStateMap.size();
32435fc4846ba9657d6d2638e68d810618fedec7ecdAshish Singhi}
32535fc4846ba9657d6d2638e68d810618fedec7ecdAshish Singhi
326eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::postHotplugEvent(bool connected)
327eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
328eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    if (!connected) {
329eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        // enable vsync on the primary device immediately
330177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        Hwcomposer::getInstance().getVsyncManager()->enableDynamicVsync(true);
331eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    }
332177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
333177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // handle hotplug event (vsync switch) asynchronously
334177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Event e;
335177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.type = HOTPLUG_EVENT;
336177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.bValue = connected;
337177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    postEvent(e);
338177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Hwcomposer::getInstance().invalidate();
339eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
340eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
341b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpevoid DisplayAnalyzer::postVideoEvent(int instanceID, int state)
342eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
343eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Event e;
344eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    e.type = VIDEO_EVENT;
345b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    e.videoEvent.instanceID = instanceID;
346b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    e.videoEvent.state = state;
347eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    postEvent(e);
348b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
349b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if ((state == VIDEO_PLAYBACK_STARTING) ||
350009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        (state == VIDEO_PLAYBACK_STOPPING && mProtectedVideoSession)) {
3514ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu        Hwcomposer::getInstance().invalidate();
352009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        // wait for up to 100ms until overlay is disabled.
353009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        int loop = 0;
354009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        while (loop++ < 6) {
355009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang            if (Hwcomposer::getInstance().getPlaneManager()->isOverlayPlanesDisabled())
356009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang                break;
357009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang            usleep(16700);
358009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        }
359009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        if (loop == 6) {
360009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang            WTRACE("timeout disabling overlay ");
3614ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu        }
3624ffa9f40b823e4c99cd7a21598373969517d93a8Andy Qiu    }
363eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
364eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
365eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::postBlankEvent(bool blank)
366eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
367eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Event e;
368eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    e.type = BLANK_EVENT;
369b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    e.bValue = blank;
370eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    postEvent(e);
371d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    Hwcomposer::getInstance().invalidate();
372d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu}
373d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu
374177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::postInputEvent(bool active)
375177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
376177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Event e;
377177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.type = INPUT_EVENT;
378177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.bValue = active;
379177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    postEvent(e);
380177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Hwcomposer::getInstance().invalidate();
381177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
382177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
383466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Huvoid DisplayAnalyzer::postIdleEntryEvent(void)
384466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu{
385466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    Event e;
386466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    e.type = IDLE_ENTRY_EVENT;
387466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    e.nValue = 0;
388466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    postEvent(e);
389466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu}
390466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
391eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::postEvent(Event& e)
392d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu{
393eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Mutex::Autolock lock(mEventMutex);
394eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mPendingEvents.add(e);
395eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
396eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
397b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpebool DisplayAnalyzer::getEvent(Event& e)
398eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
399eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    Mutex::Autolock lock(mEventMutex);
400eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    if (mPendingEvents.size() == 0) {
401b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        return false;
402b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
403b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    e = mPendingEvents[0];
404b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    mPendingEvents.removeAt(0);
405b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    return true;
406b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe}
407b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
408b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpevoid DisplayAnalyzer::handlePendingEvents()
409b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe{
410b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    // handle one event per analysis to avoid blocking surface flinger
411b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    // some event may take lengthy time to process
412b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    Event e;
413b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (!getEvent(e)) {
414eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        return;
415eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    }
416eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
417b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    switch (e.type) {
418b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    case HOTPLUG_EVENT:
419b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        handleHotplugEvent(e.bValue);
420b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        break;
421b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    case BLANK_EVENT:
422b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        handleBlankEvent(e.bValue);
423b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        break;
424b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    case VIDEO_EVENT:
425b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        handleVideoEvent(e.videoEvent.instanceID, e.videoEvent.state);
426b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        break;
427b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    case TIMING_EVENT:
428b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        handleTimingEvent();
429b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        break;
430177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    case INPUT_EVENT:
431177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        handleInputEvent(e.bValue);
432177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        break;
433177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    case DPMS_EVENT:
434177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        handleDpmsEvent(e.nValue);
435177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        break;
436466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    case IDLE_ENTRY_EVENT:
437466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        handleIdleEntryEvent(e.nValue);
438466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        break;
439466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    case IDLE_EXIT_EVENT:
440466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        handleIdleExitEvent();
441466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        break;
4420ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    case VIDEO_CHECK_EVENT:
4430ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        handleVideoCheckEvent();
4440ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        break;
445eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    }
446eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
447eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
448eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::handleHotplugEvent(bool connected)
449eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
450466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (connected) {
451466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        Hwcomposer::getInstance().getPowerManager()->disableIdleControl();
452aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang    } else {
453aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang        if (mVideoStateMap.size() == 0) {
454aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang            Hwcomposer::getInstance().getPowerManager()->enableIdleControl();
455aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang        } else if (mVideoStateMap.size() == 1) {
456aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang            // Reset input state if HDMI is plug out to
457aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang            // avoid entering extended mode immediately after HDMI is plug in
458aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang            mActiveInputState = true;
459aa24c338f8cee39de0bc570e224349257bdd7cc3Zhu,Tianyang        }
460466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
461eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
462eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
463eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::handleBlankEvent(bool blank)
464eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
465eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    mBlankDevice = blank;
466eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    // force geometry changed in the secondary device to reset layer composition type
467eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    for (int i = 0; i < (int)mCachedNumDisplays; i++) {
468eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        if (i == IDisplayDevice::DEVICE_PRIMARY) {
469eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            continue;
470eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        }
471eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        if (mCachedDisplays[i]) {
472eb726af21649d79ed720bdf329e0849270995c45Andy Qiu            mCachedDisplays[i]->flags |= HWC_GEOMETRY_CHANGED;
473eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        }
474d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    }
475eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    blankSecondaryDevice();
476eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
477d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu
478b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpevoid DisplayAnalyzer::handleTimingEvent()
479b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie{
480b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    // check whether external device is connected, reset refresh rate to match video frame rate
481b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    // if video is in playing state or reset refresh rate to default preferred one if video is not
482b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    // at playing state
483b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    Hwcomposer *hwc = &Hwcomposer::getInstance();
484b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    ExternalDevice *dev = NULL;
485b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    dev = (ExternalDevice *)hwc->getDisplayDevice(IDisplayDevice::DEVICE_EXTERNAL);
486b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (!dev) {
487b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie        return;
488b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
489b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
490b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (!dev->isConnected()) {
491b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        return;
492b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
493b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie
494f320f1a53d9adba5885304f3589962a58a1b4e67Lin Xie    if (hwc->getMultiDisplayObserver()->isExternalDeviceTimingFixed()) {
495b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        VTRACE("Timing of external device is fixed.");
496f320f1a53d9adba5885304f3589962a58a1b4e67Lin Xie        return;
497f320f1a53d9adba5885304f3589962a58a1b4e67Lin Xie    }
498f320f1a53d9adba5885304f3589962a58a1b4e67Lin Xie
499853b12aa319e4557a300923590538282c88314beAndy Qiu    int hz = 0;
500b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (mVideoStateMap.size() == 1) {
50184e17af0350016243463b4fe7a82e76524e01651Lin Xie        VideoSourceInfo info;
502b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        int instanceID = mVideoStateMap.keyAt(0);
503b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie        status_t err = hwc->getMultiDisplayObserver()->getVideoSourceInfo(
504b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe                instanceID, &info);
50584e17af0350016243463b4fe7a82e76524e01651Lin Xie        if (err == NO_ERROR) {
506853b12aa319e4557a300923590538282c88314beAndy Qiu            hz = info.frameRate;
507b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie        }
508b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    }
5092413102f33fdefa6bdb80ed2c4f56fae83cd5bd8fu jin
510b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    dev->setRefreshRate(hz);
511b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie}
512b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie
513b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpevoid DisplayAnalyzer::handleVideoEvent(int instanceID, int state)
514eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
515b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    mVideoStateMap.removeItem(instanceID);
516b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (state != VIDEO_PLAYBACK_STOPPED) {
517b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        mVideoStateMap.add(instanceID, state);
518b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
519b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
520b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    Hwcomposer *hwc = &Hwcomposer::getInstance();
521b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
522b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    // sanity check
523b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (hwc->getMultiDisplayObserver()->getVideoSessionNumber() !=
524b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        (int)mVideoStateMap.size()) {
525b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        WTRACE("session number does not match!!");
526b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        mVideoStateMap.clear();
527b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        if (state != VIDEO_PLAYBACK_STOPPED) {
528b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe            mVideoStateMap.add(instanceID, state);
529b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        }
530b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
531b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
532f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu    // check if composition type needs to be reset
533f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu    bool reset = false;
534b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if ((state == VIDEO_PLAYBACK_STARTING) ||
535009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        (state == VIDEO_PLAYBACK_STOPPING && mProtectedVideoSession)) {
536b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        // if video is in starting or stopping stage, overlay use is temporarily not allowed to
537b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        // avoid scrambed RGB overlay if video is protected.
538b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        mOverlayAllowed = false;
539f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu        reset = true;
540b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    } else {
541f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu        reset = !mOverlayAllowed;
542b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        mOverlayAllowed = true;
543b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie    }
544b58f29390918c0df3bd6d0731bf98daf57511b9fLin Xie
545f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu    if (reset) {
546f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu        hwc_display_contents_1_t *content = NULL;
547f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu        for (int i = 0; i < (int)mCachedNumDisplays; i++) {
548177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu            setCompositionType(i, HWC_FRAMEBUFFER, true);
549f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu        }
550f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu    }
551f98aecf56f66cd2501eb621a45658e421b3e3a8cAndy Qiu
552c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang    if (mVideoStateMap.size() == 0) {
553c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang        // reset active input state after video playback stops.
554c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang        // MDS should update input state in 5 seconds after video playback starts
555c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang        mActiveInputState = true;
556c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang    }
557466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
558466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (mVideoStateMap.size() > 0) {
559466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        hwc->getPowerManager()->disableIdleControl();
560466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    } else if (!hwc->getDrm()->isConnected(IDisplayDevice::DEVICE_EXTERNAL)) {
561466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu         hwc->getPowerManager()->enableIdleControl();
562466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
563466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
564009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang    mProtectedVideoSession = false;
565009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang    if (state == VIDEO_PLAYBACK_STARTED) {
566009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        VideoSourceInfo info;
567009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        hwc->getMultiDisplayObserver()->getVideoSourceInfo(
568009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang                getFirstVideoInstanceSessionID(), &info);
569009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang        mProtectedVideoSession = info.isProtected;
570009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang    }
571009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang
572ddc8e627fdde22f2b37a0e24c7ca8dcd1206df97Zhu,Tianyang    // Setting timing immediately,
573ddc8e627fdde22f2b37a0e24c7ca8dcd1206df97Zhu,Tianyang    // Don't posthone to next circle
574ddc8e627fdde22f2b37a0e24c7ca8dcd1206df97Zhu,Tianyang    handleTimingEvent();
5750ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
5760ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    handleVideoCheckEvent();
577eb726af21649d79ed720bdf329e0849270995c45Andy Qiu}
578eb726af21649d79ed720bdf329e0849270995c45Andy Qiu
579eb726af21649d79ed720bdf329e0849270995c45Andy Qiuvoid DisplayAnalyzer::blankSecondaryDevice()
580eb726af21649d79ed720bdf329e0849270995c45Andy Qiu{
581d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    hwc_display_contents_1_t *content = NULL;
582d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    hwc_layer_1 *layer = NULL;
583eb726af21649d79ed720bdf329e0849270995c45Andy Qiu    for (int i = 0; i < (int)mCachedNumDisplays; i++) {
584d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        if (i == IDisplayDevice::DEVICE_PRIMARY) {
585d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            continue;
586d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        }
587eb726af21649d79ed720bdf329e0849270995c45Andy Qiu        content = mCachedDisplays[i];
588d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        if (content == NULL) {
589d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            continue;
590d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        }
591d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu
592d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        for (int j = 0; j < (int)content->numHwLayers - 1; j++) {
593d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            layer = &content->hwLayers[j];
594d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            if (!layer) {
595d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                continue;
596d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            }
597d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            if (mBlankDevice) {
598d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                layer->hints |= HWC_HINT_CLEAR_FB;
599d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                layer->flags &= ~HWC_SKIP_LAYER;
600d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                layer->compositionType = HWC_OVERLAY;
601d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            } else {
602d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                layer->hints &= ~HWC_HINT_CLEAR_FB;
603d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu                layer->compositionType = HWC_FRAMEBUFFER;
604d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu            }
605d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu        }
606d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu    }
607d4e9a8ac464ef6fde755c1a8c0902dc02a1270ecAndy Qiu}
60865efc253a628175c7afa95c431b746ea20052794Andy Qiu
609177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::handleInputEvent(bool active)
610177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
611c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang    if (active == mActiveInputState) {
612c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang        WTRACE("same input state: %d", active);
613c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang    }
614177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mActiveInputState = active;
615177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (!mVideoExtModeEligible) {
616177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        ITRACE("not eligible for video extended mode");
617177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
618177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
619177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
620177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (active) {
621177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        exitVideoExtMode();
622177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    } else {
623177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        enterVideoExtMode();
624177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
625177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
626177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
627177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::handleDpmsEvent(int delayCount)
628177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
629177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (mActiveInputState || !mVideoExtModeEligible) {
630177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        ITRACE("aborting display power off in video extended mode");
631177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
632177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
633177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
634177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (delayCount < DELAY_BEFORE_DPMS_OFF) {
635177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        Event e;
636177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        e.type = DPMS_EVENT;
637177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        e.nValue = delayCount + 1;
638177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        postEvent(e);
6395a3b1ac20ca8e3594554e624efcc4b4d88dec392Lei Zhang        Hwcomposer::getInstance().invalidate();
640177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
641177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
642177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
643177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (Hwcomposer::getInstance().getVsyncManager()->getVsyncSource() ==
644177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        IDisplayDevice::DEVICE_PRIMARY) {
6456c061a816e1bb454afc8d294231bc235a771d646Nie Jun            Hwcomposer::getInstance().getDrm()->setDpmsMode(
6466c061a816e1bb454afc8d294231bc235a771d646Nie Jun            IDisplayDevice::DEVICE_PRIMARY,
6476c061a816e1bb454afc8d294231bc235a771d646Nie Jun                IDisplayDevice::DEVICE_DISPLAY_STANDBY);
6486c061a816e1bb454afc8d294231bc235a771d646Nie Jun        ETRACE("primary display is source of vsync, we only dim backlight");
649177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
650177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
651177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
652c0529447ae16f023dfab2978ea2b245f368e893bAndy Qiu    // panel can't be powered off as touch panel shares the power supply with LCD.
653c0529447ae16f023dfab2978ea2b245f368e893bAndy Qiu    DTRACE("primary display coupled with touch on Saltbay, only dim backlight");
6546c061a816e1bb454afc8d294231bc235a771d646Nie Jun    Hwcomposer::getInstance().getDrm()->setDpmsMode(
6556c061a816e1bb454afc8d294231bc235a771d646Nie Jun               IDisplayDevice::DEVICE_PRIMARY,
6566c061a816e1bb454afc8d294231bc235a771d646Nie Jun               IDisplayDevice::DEVICE_DISPLAY_STANDBY);
657c0529447ae16f023dfab2978ea2b245f368e893bAndy Qiu               //IDisplayDevice::DEVICE_DISPLAY_OFF);
6586c061a816e1bb454afc8d294231bc235a771d646Nie Jun    return;
659177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
660177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
661466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
662466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Huvoid DisplayAnalyzer::handleIdleEntryEvent(int count)
663466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu{
664466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    DTRACE("handling idle entry event, count %d", count);
665466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (hasProtectedLayer()) {
666466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        ITRACE("Ignoring idle entry as protected layer exists.");
667466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        setCompositionType(0, HWC_FRAMEBUFFER, true);
668466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        return;
669466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
670466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
671466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    // stop idle entry if external device is connected
672466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (mCachedDisplays && mCachedDisplays[IDisplayDevice::DEVICE_EXTERNAL]) {
673466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        ITRACE("Ignoring idle entry as external device is connected.");
674466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        setCompositionType(0, HWC_FRAMEBUFFER, true);
675466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        return;
676466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
677466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
678466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    // stop idle entry if video playback is active
679466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    // TODO: remove this check for Annidale
680466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (mVideoStateMap.size() > 0) {
681466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        ITRACE("Ignoring idle entry as video session is active.");
682466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        setCompositionType(0, HWC_FRAMEBUFFER, true);
683466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        return;
684466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
685466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
686466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    setCompositionType(0, HWC_FORCE_FRAMEBUFFER, true);
687466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
688466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    IPowerManager *pm = Hwcomposer::getInstance().getPowerManager();
689466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (count == 0) {
690466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        // ready to enter idel mode
691466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        pm->setIdleReady();
692466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
693466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
694466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    if (count >= DELAY_BEFORE_IDLE_ENTRY) {
695466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        pm->enterIdleState();
696466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        // next prepare/set will exit idle state.
697466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        Event e;
698466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        e.type = IDLE_EXIT_EVENT;
699466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        postEvent(e);
700466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    } else {
701466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        // invalidate surface flinger again
702466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        Event e;
703466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        e.type = IDLE_ENTRY_EVENT;
704466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        e.nValue = count + 1;
705466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        postEvent(e);
706466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu        Hwcomposer::getInstance().invalidate();
707466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    }
708466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu}
709466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
710466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Huvoid DisplayAnalyzer::handleIdleExitEvent()
711466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu{
712466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    DTRACE("handling idle exit event");
713466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
714466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    IPowerManager *pm = Hwcomposer::getInstance().getPowerManager();
715466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    pm->exitIdleState();
716466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu    setCompositionType(0, HWC_FRAMEBUFFER, true);
717466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu}
718466748a6f67ce4d1ad8baa944e68a88cf3c86d26Austin Hu
7190ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiuvoid DisplayAnalyzer::handleVideoCheckEvent()
7200ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu{
7210ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // check if the first seen video layer on secondary device (HDMI/WFD) is marked as skipped
7220ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // it is assumed video is always skipped if the first seen video layer is skipped
7230ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // this is to workaround secure video layer transmitted over non secure output
7240ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // and HWC_SKIP_LAYER set during rotation animation.
7250ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    mIgnoreVideoSkipFlag = false;
7260ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
7270ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    if (mVideoStateMap.size() != 1 ||
7280ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        mCachedNumDisplays <= 1) {
7290ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        return;
7300ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    }
7310ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
7320ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    uint32_t videoHandles[mCachedNumDisplays];
7330ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    for (int i = 0; i < (int)mCachedNumDisplays; i++) {
7340ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        videoHandles[i] = 0;
7350ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        hwc_display_contents_1_t *content = mCachedDisplays[i];
7360ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        if (content == NULL) {
7370ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu            continue;
7380ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        }
7390ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        for (int j = 0; j < (int)content->numHwLayers - 1; j++) {
7400ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu            if (isVideoLayer(content->hwLayers[j])) {
7410ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                videoHandles[i] = (uint32_t)content->hwLayers[j].handle;
7420ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                if (i > 0) {
7430ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                    if (videoHandles[i] == videoHandles[0]) {
7440ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                        mIgnoreVideoSkipFlag = !(content->hwLayers[j].flags & HWC_SKIP_LAYER);
7450ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                        ITRACE("Ignoring video HWC_SKIP_LAYER: %d on output %d", mIgnoreVideoSkipFlag, i);
7460ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                    }
7470ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                    return;
7480ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                }
7490ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu                break;
7500ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu            }
7510ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        }
7520ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    }
7530ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
7540ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    if (videoHandles[0]) {
7550ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        WTRACE("Video is on the primary panel only");
7560ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu        return;
7570ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    }
7580ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
7590ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // video state map indicates video session is active and there is secondary
7600ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    // display, need to continue checking as video is not found in the buffers yet
7610ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    Event e;
7620ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    e.type = VIDEO_CHECK_EVENT;
7630ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    postEvent(e);
7640ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu}
7650ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
766177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::enterVideoExtMode()
767177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
768177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (mVideoExtModeActive) {
769177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        WTRACE("already in video extended mode.");
770177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
771177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
772177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
773177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    ITRACE("entering video extended mode...");
774177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mVideoExtModeActive = true;
775177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Hwcomposer::getInstance().getVsyncManager()->resetVsyncSource();
776177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
777177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    setCompositionType(0, HWC_OVERLAY, true);
778177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
779177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // Do not power off primary display immediately as flip is asynchronous
780177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Event e;
781177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.type = DPMS_EVENT;
782177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    e.nValue = 0;
783177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    postEvent(e);
7845a3b1ac20ca8e3594554e624efcc4b4d88dec392Lei Zhang    Hwcomposer::getInstance().invalidate();
785177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
786177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
787177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::exitVideoExtMode()
788177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
789177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (!mVideoExtModeActive) {
790177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        WTRACE("Not in video extended mode");
791177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
792177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
793177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
794c8ed4d7c744a7f59864fa5a7db8ae3d0c05a119fZhu,Tianyang    ITRACE("exiting video extended mode...");
795177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
796177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mVideoExtModeActive = false;
797177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
798177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Hwcomposer::getInstance().getDrm()->setDpmsMode(
799177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        IDisplayDevice::DEVICE_PRIMARY,
800177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        IDisplayDevice::DEVICE_DISPLAY_ON);
801177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
802177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Hwcomposer::getInstance().getVsyncManager()->resetVsyncSource();
803177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
804177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    setCompositionType(0, HWC_FRAMEBUFFER, true);
805177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
806177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
807d248396b4f48861e1e27c5e316c776121ab44938mamatha balguribool DisplayAnalyzer::isPresentationLayer(hwc_layer_1_t &layer)
808d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri{
809177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (layer.handle == NULL) {
810177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return false;
811177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
812d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    if (mCachedDisplays == NULL) {
813d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri        return false;
814d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    }
815d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    // check if the given layer exists in the primary device
816d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    hwc_display_contents_1_t *content = mCachedDisplays[0];
817d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    if (content == NULL) {
818d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri        return false;
819d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    }
820d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    for (size_t i = 0; i < content->numHwLayers - 1; i++) {
821d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri        if ((uint32_t)content->hwLayers[i].handle == (uint32_t)layer.handle) {
822d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri            VTRACE("Layer exists for Primary device");
823d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri            return false;
824d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri        }
825d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    }
826d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri    return true;
827d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri}
828d248396b4f48861e1e27c5e316c776121ab44938mamatha balguri
82947630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhangbool DisplayAnalyzer::hasVideoLayer(int device)
83047630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang{
83147630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    DataBuffer * buffer = NULL;
83247630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    hwc_display_contents_1_t *content = NULL;
83347630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
83447630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    if (mCachedDisplays == NULL) {
83547630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        return false;
83647630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    }
83747630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
83847630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    content = mCachedDisplays[device];
83947630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    if (content == NULL) {
84047630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        return false;
84147630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    }
84247630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
84347630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    for (size_t i = 0; i < content->numHwLayers - 1; i++) {
84447630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang        if (isVideoLayer(content->hwLayers[i]))
84547630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang            return true;
84647630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    }
84747630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
84847630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang    return false;
84947630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang}
85047630ea6b1974d6e282e95f0a4fca9e7acad77a6Lei Zhang
851b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpebool DisplayAnalyzer::hasProtectedLayer()
852b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe{
853b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    DataBuffer * buffer = NULL;
854b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    hwc_display_contents_1_t *content = NULL;
855b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    BufferManager *bm = Hwcomposer::getInstance().getBufferManager();
856b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
857b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (bm == NULL){
858b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        return false;
859b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
860b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
861b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    if (mCachedDisplays == NULL) {
862b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        return false;
863b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
864b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    // check if the given layer exists in the primary device
865b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    for (int index = 0; index < (int)mCachedNumDisplays; index++) {
866b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        content = mCachedDisplays[index];
867b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        if (content == NULL) {
868b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe            continue;
869b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        }
870b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
871b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        for (size_t i = 0; i < content->numHwLayers - 1; i++) {
872b16cf47b6865c4ba53e336558671d11b0325e78bLin Xie            if (isProtectedLayer(content->hwLayers[i]))
873b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe                return true;
874b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe        }
875b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    }
876b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
877b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe    return false;
878b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe}
879b7e04bcc10f0b8aaa698b1ccae40e87664ebef18mahongpe
880ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhibool DisplayAnalyzer::isProtectedLayer(hwc_layer_1_t &layer)
881ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi{
882ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    if (!layer.handle) {
883177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return false;
884ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    }
885177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    bool ret = false;
886177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    BufferManager *bm = Hwcomposer::getInstance().getBufferManager();
887ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    DataBuffer *buffer = bm->lockDataBuffer((uint32_t)layer.handle);
888ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    if (!buffer) {
889ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi        ETRACE("failed to get buffer");
890ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    } else {
891ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi        ret = GraphicBuffer::isProtectedBuffer((GraphicBuffer*)buffer);
892ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi        bm->unlockDataBuffer(buffer);
893ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    }
894ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi    return ret;
895ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi}
896ef111c2d5fb42bfcefca8e774837e12cc1940d80Ashish Singhi
8970ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiubool DisplayAnalyzer::ignoreVideoSkipFlag()
8980ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu{
8990ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu    return mIgnoreVideoSkipFlag;
9000ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu}
9010ab7fc9e013631bad1f404d8a6300137f4bce0cbAndy Qiu
902177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::setCompositionType(hwc_display_contents_1_t *display, int type)
903177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
904177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    for (size_t i = 0; i < display->numHwLayers - 1; i++) {
905177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        hwc_layer_1_t *layer = &display->hwLayers[i];
906177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        if (layer) layer->compositionType = type;
907177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
908177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
909177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
910177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuvoid DisplayAnalyzer::setCompositionType(int device, int type, bool reset)
911177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu{
912177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    hwc_display_contents_1_t *content = mCachedDisplays[device];
913177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (content == NULL) {
914177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        ETRACE("Invalid device %d", device);
915177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        return;
916177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
917177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
918177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    // don't need to set geometry changed if layers are just needed to be marked
919177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    if (reset) {
920177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu        content->flags |= HWC_GEOMETRY_CHANGED;
921177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    }
922177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
923177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    setCompositionType(content, type);
924177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu}
925177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
9261747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyangint DisplayAnalyzer::getFirstVideoInstanceSessionID() {
9271747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang    if (mVideoStateMap.size() >= 1) {
9281747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang        return mVideoStateMap.keyAt(0);
9291747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang    }
9301747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang    return -1;
9311747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang}
9321747c24dc5251a0a062ef5f8a6791c30a715e820Zhu,Tianyang
93365efc253a628175c7afa95c431b746ea20052794Andy Qiu} // namespace intel
93465efc253a628175c7afa95c431b746ea20052794Andy Qiu} // namespace android
93565efc253a628175c7afa95c431b746ea20052794Andy Qiu
936