HWComposer.cpp revision 5a8f9012ee8bb9dc1ad14432b96a821f08802ee3
1a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian/* 2a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Copyright (C) 2010 The Android Open Source Project 3a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 4a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * you may not use this file except in compliance with the License. 6a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * You may obtain a copy of the License at 7a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 8a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 10a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * See the License for the specific language governing permissions and 14a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * limitations under the License. 15a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian */ 16a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 172965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#define ATRACE_TAG ATRACE_TAG_GRAPHICS 182965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 195880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// Uncomment this to remove support for HWC_DEVICE_API_VERSION_0_3 and older 2030bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian#define HWC_REMOVE_DEPRECATED_VERSIONS 1 215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 22a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <stdint.h> 23f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdio.h> 24f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdlib.h> 25f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <string.h> 26a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <sys/types.h> 27a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 28a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <utils/Errors.h> 29da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian#include <utils/misc.h> 308372785879d329f592f6883620b5a32d80d74691Mathias Agopian#include <utils/String8.h> 313eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <utils/Thread.h> 322965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#include <utils/Trace.h> 3322da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h> 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 35921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <ui/GraphicBuffer.h> 36921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian 37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h> 383eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <hardware/hwcomposer.h> 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 40a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h> 41e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian#include <cutils/properties.h> 42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 43921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include "Layer.h" // needed only for debugging 4422da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 46c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 47da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian#include <utils/CallStack.h> 48a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 49a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 519eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall#define MIN_HWC_HEADER_VERSION 0 529eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 539eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) { 549eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t hwcVersion = hwc->common.version; 559eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (MIN_HWC_HEADER_VERSION == 0 && 569eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK) == 0) { 579eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall // legacy version encoding 589eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcVersion <<= 16; 599eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 609eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK; 619eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall} 629eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 639eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic uint32_t hwcHeaderVersion(const hwc_composer_device_1_t* hwc) { 649eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t hwcVersion = hwc->common.version; 659eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (MIN_HWC_HEADER_VERSION == 0 && 669eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK) == 0) { 679eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall // legacy version encoding 689eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcVersion <<= 16; 699eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 709eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcVersion & HARDWARE_API_VERSION_2_HEADER_MASK; 719eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall} 729eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 739eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic bool hwcHasApiVersion(const hwc_composer_device_1_t* hwc, 749eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t version) { 759eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcApiVersion(hwc) >= (version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK); 76bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall} 77bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall 78a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 79a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianstruct HWComposer::cb_context { 813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian struct callbacks : public hwc_procs_t { 823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // these are here to facilitate the transition when adding 833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // new callbacks (an implementation can check for NULL before 843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // calling a new callback). 853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian void (*zero[4])(void); 863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian }; 873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian callbacks procs; 883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWComposer* hwc; 893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian// --------------------------------------------------------------------------- 923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 933eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias AgopianHWComposer::HWComposer( 943eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const sp<SurfaceFlinger>& flinger, 95b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden EventHandler& handler) 96c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 97b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mFbDev(0), mHwc(0), mNumDisplays(1), 983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext(new cb_context), 99e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mEventHandler(handler), 100e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mVSyncCount(0), mDebugForceFakeVSync(false) 101a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 102e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian for (size_t i =0 ; i<MAX_DISPLAYS ; i++) { 103e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mLists[i] = 0; 104e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 105b685c542836b93c99cd85053e07696406ea37adbJesse Hall 106e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian char value[PROPERTY_VALUE_MAX]; 107e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian property_get("debug.sf.no_hw_vsync", value, "0"); 108e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync = atoi(value); 109e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian 110028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian bool needVSyncThread = true; 1115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 112b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // Note: some devices may insist that the FB HAL be opened before HWC. 113b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden loadFbHalModule(); 114b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden loadHwcModule(); 115bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall 116da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (mFbDev && mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 117da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // close FB HAL if we don't needed it. 118da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // FIXME: this is temporary until we're not forced to open FB HAL 119da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // before HWC. 120da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian framebuffer_close(mFbDev); 121da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian mFbDev = NULL; 122da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 123da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 124babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden // If we have no HWC, or a pre-1.1 HWC, an FB dev is mandatory. 125babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden if ((!mHwc || !hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) 126babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden && !mFbDev) { 12743601a2dc320a271ff8c3765ff61414a07221635Andy McFadden ALOGE("ERROR: failed to open framebuffer, aborting"); 12843601a2dc320a271ff8c3765ff61414a07221635Andy McFadden abort(); 12943601a2dc320a271ff8c3765ff61414a07221635Andy McFadden } 13043601a2dc320a271ff8c3765ff61414a07221635Andy McFadden 131b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (mHwc) { 132b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGI("Using %s version %u.%u", HWC_HARDWARE_COMPOSER, 133b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden (hwcApiVersion(mHwc) >> 24) & 0xff, 134b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden (hwcApiVersion(mHwc) >> 16) & 0xff); 135b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (mHwc->registerProcs) { 136b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mCBContext->hwc = this; 137b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mCBContext->procs.invalidate = &hook_invalidate; 138b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mCBContext->procs.vsync = &hook_vsync; 139b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) 140b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mCBContext->procs.hotplug = &hook_hotplug; 141b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden else 142b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mCBContext->procs.hotplug = NULL; 143b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); 144b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mHwc->registerProcs(mHwc, &mCBContext->procs); 145b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 146b685c542836b93c99cd85053e07696406ea37adbJesse Hall 147b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // don't need a vsync thread if we have a hardware composer 148b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden needVSyncThread = false; 149b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // always turn vsync off when we start 15081cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian eventControl(HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, 0); 1518f971ff6661c875e7adb3f14731e1579c3c80c62Jesse Hall 152b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // these IDs are always reserved 153b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden for (size_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) { 154b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mAllocatedDisplayIDs.markBit(i); 155b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 156b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 157b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // the number of displays we actually have depends on the 158b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // hw composer version 159b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_2)) { 160b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // 1.2 adds support for virtual displays 161b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mNumDisplays = MAX_DISPLAYS; 162b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 163b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // 1.1 adds support for multiple displays 164b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mNumDisplays = HWC_NUM_DISPLAY_TYPES; 165b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } else { 166b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mNumDisplays = 1; 167c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 1683a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 1693a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 170b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (mFbDev) { 1711bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ALOG_ASSERT(!(mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)), 1721bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall "should only have fbdev if no hwc or hwc is 1.0"); 1731bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 174f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[HWC_DISPLAY_PRIMARY]); 17538e623bc5c2d7224ebd5b82efaea401bc8e5367aMathias Agopian disp.connected = true; 176db27621e22559a1b16414f890677ef04242fbc3bJesse Hall disp.width = mFbDev->width; 177db27621e22559a1b16414f890677ef04242fbc3bJesse Hall disp.height = mFbDev->height; 178b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden disp.format = mFbDev->format; 179b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden disp.xdpi = mFbDev->xdpi; 180b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden disp.ydpi = mFbDev->ydpi; 181f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.refresh == 0) { 182b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden disp.refresh = nsecs_t(1e9 / mFbDev->fps); 183f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian ALOGW("getting VSYNC period from fb HAL: %lld", disp.refresh); 184f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 185f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.refresh == 0) { 186f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.refresh = nsecs_t(1e9 / 60.0); 1871bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ALOGW("getting VSYNC period from thin air: %lld", 1881bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[HWC_DISPLAY_PRIMARY].refresh); 189888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian } 1901bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } else if (mHwc) { 1911604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian // here we're guaranteed to have at least HWC 1.1 1921604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian for (size_t i =0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) { 1931604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian queryDisplayProperties(i); 1941604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian } 195888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian } 196888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian 1973a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (needVSyncThread) { 1983a77871383bc1a03cc866686d81628493d14de7cMathias Agopian // we don't have VSYNC support, we need to fake it 1993a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread = new VSyncThread(*this); 200a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 201a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 202a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 203a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 204babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden if (mHwc) { 20581cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian eventControl(HWC_DISPLAY_PRIMARY, HWC_EVENT_VSYNC, 0); 206babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden } 2073eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mVSyncThread != NULL) { 2083eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mVSyncThread->requestExitAndWait(); 2093eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 210a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 2115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 212a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 213b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (mFbDev) { 214b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden framebuffer_close(mFbDev); 215b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 2163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian delete mCBContext; 217a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 218a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 219b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden// Load and prepare the hardware composer module. Sets mHwc. 220b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid HWComposer::loadHwcModule() 221b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden{ 222b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden hw_module_t const* module; 223b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 224b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (hw_get_module(HWC_HARDWARE_MODULE_ID, &module) != 0) { 225b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGE("%s module not found", HWC_HARDWARE_MODULE_ID); 226b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 227b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 228b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 229b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden int err = hwc_open_1(module, &mHwc); 230b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (err) { 231b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGE("%s device failed to initialize (%s)", 232b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden HWC_HARDWARE_COMPOSER, strerror(-err)); 233b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 234b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 235b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 236b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_0) || 237b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden hwcHeaderVersion(mHwc) < MIN_HWC_HEADER_VERSION || 238b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden hwcHeaderVersion(mHwc) > HWC_HEADER_VERSION) { 239b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGE("%s device version %#x unsupported, will not be used", 240b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden HWC_HARDWARE_COMPOSER, mHwc->common.version); 241b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden hwc_close_1(mHwc); 242b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mHwc = NULL; 243b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 244b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 245b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 246b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 247b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden// Load and prepare the FB HAL, which uses the gralloc module. Sets mFbDev. 248b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid HWComposer::loadFbHalModule() 249b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden{ 250b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden hw_module_t const* module; 251b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 252b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) != 0) { 253b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGE("%s module not found", GRALLOC_HARDWARE_MODULE_ID); 254b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 255b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 256b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 257b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden int err = framebuffer_open(module, &mFbDev); 258b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (err) { 259b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ALOGE("framebuffer_open failed (%s)", strerror(-err)); 260b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 261b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 262b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 263b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 264a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 265a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 266a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 267a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 268bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hallvoid HWComposer::hook_invalidate(const struct hwc_procs* procs) { 269bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall cb_context* ctx = reinterpret_cast<cb_context*>( 270bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall const_cast<hwc_procs_t*>(procs)); 271bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall ctx->hwc->invalidate(); 272c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 273c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 2741bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hallvoid HWComposer::hook_vsync(const struct hwc_procs* procs, int disp, 275bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall int64_t timestamp) { 276bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall cb_context* ctx = reinterpret_cast<cb_context*>( 277bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall const_cast<hwc_procs_t*>(procs)); 2781bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ctx->hwc->vsync(disp, timestamp); 2791bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall} 2801bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 2811bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hallvoid HWComposer::hook_hotplug(const struct hwc_procs* procs, int disp, 2821bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall int connected) { 2831bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall cb_context* ctx = reinterpret_cast<cb_context*>( 2841bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall const_cast<hwc_procs_t*>(procs)); 2851bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ctx->hwc->hotplug(disp, connected); 28631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 28731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 288c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 289e2c2f9213f936f98db604dc9c126ff22f725a824Mathias Agopian mFlinger->repaintEverything(); 290c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 291c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 2921bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hallvoid HWComposer::vsync(int disp, int64_t timestamp) { 2932965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian ATRACE_INT("VSYNC", ++mVSyncCount&1); 2941bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mEventHandler.onVSyncReceived(disp, timestamp); 295d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian Mutex::Autolock _l(mLock); 296d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian mLastHwVSync = timestamp; 297d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian} 298d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian 2991bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hallvoid HWComposer::hotplug(int disp, int connected) { 3001bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall if (disp == HWC_DISPLAY_PRIMARY || disp >= HWC_NUM_DISPLAY_TYPES) { 3011bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ALOGE("hotplug event received for invalid display: disp=%d connected=%d", 3021bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall disp, connected); 3031bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall return; 3041bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 305f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian queryDisplayProperties(disp); 306148994e5f33ce240ff24ceb5bc0500b7f2001959Mathias Agopian mEventHandler.onHotplugReceived(disp, bool(connected)); 3071bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall} 3081bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 3091bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hallstatic const uint32_t DISPLAY_ATTRIBUTES[] = { 3101bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall HWC_DISPLAY_VSYNC_PERIOD, 311db27621e22559a1b16414f890677ef04242fbc3bJesse Hall HWC_DISPLAY_WIDTH, 312db27621e22559a1b16414f890677ef04242fbc3bJesse Hall HWC_DISPLAY_HEIGHT, 3131bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall HWC_DISPLAY_DPI_X, 3141bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall HWC_DISPLAY_DPI_Y, 3151bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall HWC_DISPLAY_NO_ATTRIBUTE, 3161bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall}; 3171bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall#define NUM_DISPLAY_ATTRIBUTES (sizeof(DISPLAY_ATTRIBUTES) / sizeof(DISPLAY_ATTRIBUTES)[0]) 3181bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 3191bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall// http://developer.android.com/reference/android/util/DisplayMetrics.html 3201bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall#define ANDROID_DENSITY_TV 213 3211bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall#define ANDROID_DENSITY_XHIGH 320 3221bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 3231604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopianstatus_t HWComposer::queryDisplayProperties(int disp) { 3241604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian 325da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian LOG_ALWAYS_FATAL_IF(!mHwc || !hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)); 3261bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 327b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden // use zero as default value for unspecified attributes 3281bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall int32_t values[NUM_DISPLAY_ATTRIBUTES - 1]; 3291bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall memset(values, 0, sizeof(values)); 3301bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 3311bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall uint32_t config; 3321bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall size_t numConfigs = 1; 3331bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall status_t err = mHwc->getDisplayConfigs(mHwc, disp, &config, &numConfigs); 3341604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian if (err != NO_ERROR) { 3351604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian // this can happen if an unpluggable display is not connected 336f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian mDisplayData[disp].connected = false; 3371604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian return err; 3381bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 3391bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 3409e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian err = mHwc->getDisplayAttributes(mHwc, disp, config, DISPLAY_ATTRIBUTES, values); 3419e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian if (err != NO_ERROR) { 3429e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian // we can't get this display's info. turn it off. 3439e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian mDisplayData[disp].connected = false; 3449e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian return err; 3459e2463e71796964cfaa06bf09a880875ac3537bcMathias Agopian } 3461604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian 3471bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall int32_t w = 0, h = 0; 3481bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall for (size_t i = 0; i < NUM_DISPLAY_ATTRIBUTES - 1; i++) { 3491bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall switch (DISPLAY_ATTRIBUTES[i]) { 3501bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall case HWC_DISPLAY_VSYNC_PERIOD: 3511bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].refresh = nsecs_t(values[i]); 3521bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 353db27621e22559a1b16414f890677ef04242fbc3bJesse Hall case HWC_DISPLAY_WIDTH: 354db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mDisplayData[disp].width = values[i]; 3551bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 356db27621e22559a1b16414f890677ef04242fbc3bJesse Hall case HWC_DISPLAY_HEIGHT: 357db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mDisplayData[disp].height = values[i]; 3581bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 3591bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall case HWC_DISPLAY_DPI_X: 3601bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].xdpi = values[i] / 1000.0f; 3611bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 3621bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall case HWC_DISPLAY_DPI_Y: 3631bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].ydpi = values[i] / 1000.0f; 3641bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 3651bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall default: 366da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian ALOG_ASSERT(false, "unknown display attribute[%d] %#x", 367da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian i, DISPLAY_ATTRIBUTES[i]); 3681bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall break; 3691bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 3701bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 3711bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 372f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian // FIXME: what should we set the format to? 373f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian mDisplayData[disp].format = HAL_PIXEL_FORMAT_RGBA_8888; 374f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian mDisplayData[disp].connected = true; 3751bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall if (mDisplayData[disp].xdpi == 0.0f || mDisplayData[disp].ydpi == 0.0f) { 3761bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall // is there anything smarter we can do? 3771bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall if (h >= 1080) { 3781bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].xdpi = ANDROID_DENSITY_XHIGH; 3791bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].ydpi = ANDROID_DENSITY_XHIGH; 3801bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } else { 3811bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].xdpi = ANDROID_DENSITY_TV; 3821bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall mDisplayData[disp].ydpi = ANDROID_DENSITY_TV; 3831bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 3841bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall } 3851604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian return NO_ERROR; 3861bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall} 3871bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 388e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianint32_t HWComposer::allocateDisplayId() { 389f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (mAllocatedDisplayIDs.count() >= mNumDisplays) { 390e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return NO_MEMORY; 391e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 392f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int32_t id = mAllocatedDisplayIDs.firstUnmarkedBit(); 393f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mAllocatedDisplayIDs.markBit(id); 394e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return id; 395e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 396e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian 397e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianstatus_t HWComposer::freeDisplayId(int32_t id) { 398f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (id < HWC_NUM_DISPLAY_TYPES) { 399f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // cannot free the reserved IDs 400e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return BAD_VALUE; 401e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 402f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 403e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return BAD_INDEX; 404e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 405f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mAllocatedDisplayIDs.clearBit(id); 406e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return NO_ERROR; 407e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 408e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian 409b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddennsecs_t HWComposer::getRefreshPeriod(int disp) const { 410b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return mDisplayData[disp].refresh; 411888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian} 412888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian 413b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddennsecs_t HWComposer::getRefreshTimestamp(int disp) const { 414d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // this returns the last refresh timestamp. 415d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // if the last one is not available, we estimate it based on 416d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // the refresh period and whatever closest timestamp we have. 417d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian Mutex::Autolock _l(mLock); 418d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian nsecs_t now = systemTime(CLOCK_MONOTONIC); 419b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return now - ((now - mLastHwVSync) % mDisplayData[disp].refresh); 420b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 421b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 422db27621e22559a1b16414f890677ef04242fbc3bJesse Halluint32_t HWComposer::getWidth(int disp) const { 423db27621e22559a1b16414f890677ef04242fbc3bJesse Hall return mDisplayData[disp].width; 424b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 425b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 426db27621e22559a1b16414f890677ef04242fbc3bJesse Halluint32_t HWComposer::getHeight(int disp) const { 427db27621e22559a1b16414f890677ef04242fbc3bJesse Hall return mDisplayData[disp].height; 428b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 429b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 430b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenuint32_t HWComposer::getFormat(int disp) const { 431b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return mDisplayData[disp].format; 4323eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian} 4333eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 434b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenfloat HWComposer::getDpiX(int disp) const { 435b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return mDisplayData[disp].xdpi; 4368b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian} 4378b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian 438b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenfloat HWComposer::getDpiY(int disp) const { 439b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return mDisplayData[disp].ydpi; 4408b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian} 4418b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian 442f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopianbool HWComposer::isConnected(int disp) const { 443f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian return mDisplayData[disp].connected; 444f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian} 445f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian 44681cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopianvoid HWComposer::eventControl(int disp, int event, int enabled) { 44781cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian if (uint32_t(disp)>31 || !mAllocatedDisplayIDs.hasBit(disp)) { 44881cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian return; 44981cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian } 4503eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t err = NO_ERROR; 45181cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian if (mHwc && !mDebugForceFakeVSync) { 45281cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // NOTE: we use our own internal lock here because we have to call 45381cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // into the HWC with the lock held, and we want to make sure 45481cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // that even if HWC blocks (which it shouldn't), it won't 45581cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // affect other threads. 45681cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian Mutex::Autolock _l(mEventControlLock); 45781cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian const int32_t eventBit = 1UL << event; 45881cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian const int32_t newValue = enabled ? eventBit : 0; 45981cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian const int32_t oldValue = mDisplayData[disp].events & eventBit; 46081cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian if (newValue != oldValue) { 46181cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian ATRACE_CALL(); 46281cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian err = mHwc->eventControl(mHwc, disp, event, enabled); 46381cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian if (!err) { 46481cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian int32_t& events(mDisplayData[disp].events); 46581cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian events = (events & ~eventBit) | newValue; 46681cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian } 467e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 46881cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // error here should not happen -- not sure what we should 46981cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian // do if it does. 47081cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian ALOGE_IF(err, "eventControl(%d, %d) failed %s", 47181cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian event, enabled, strerror(-err)); 4723eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 4733a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 4743a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (err == NO_ERROR && mVSyncThread != NULL) { 4753a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread->setEnabled(enabled); 4763a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 47731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 47831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 4795f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopianstatus_t HWComposer::createWorkList(int32_t id, size_t numLayers) { 480f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 4811e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian return BAD_INDEX; 482e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 4831e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian 48445721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 485f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[id]); 486da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 487da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // we need space for the HWC_FRAMEBUFFER_TARGET 488da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian numLayers++; 489da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 49013a082e160c2d1d8006b93a555a57035213d568bAndy McFadden if (disp.capacity < numLayers || disp.list == NULL) { 491da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian size_t size = sizeof(hwc_display_contents_1_t) 492f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian + numLayers * sizeof(hwc_layer_1_t); 493f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian free(disp.list); 494f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list = (hwc_display_contents_1_t*)malloc(size); 495f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.capacity = numLayers; 49645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 497da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 498da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget = &disp.list->hwLayers[numLayers - 1]; 499da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian memset(disp.framebufferTarget, 0, sizeof(hwc_layer_1_t)); 500da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const hwc_rect_t r = { 0, 0, disp.width, disp.height }; 501da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->compositionType = HWC_FRAMEBUFFER_TARGET; 502da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->hints = 0; 503da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->flags = 0; 504da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->handle = disp.fbTargetHandle; 505da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->transform = 0; 506da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->blending = HWC_BLENDING_PREMULT; 507da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->sourceCrop = r; 508da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->displayFrame = r; 509da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->visibleRegionScreen.numRects = 1; 510da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->visibleRegionScreen.rects = 511da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian &disp.framebufferTarget->displayFrame; 512da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->acquireFenceFd = -1; 513da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->releaseFenceFd = -1; 514da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 515db27621e22559a1b16414f890677ef04242fbc3bJesse Hall disp.list->retireFenceFd = -1; 516f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flags = HWC_GEOMETRY_CHANGED; 517f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->numHwLayers = numLayers; 518a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 519a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 520a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 521a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 522da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianstatus_t HWComposer::setFramebufferTarget(int32_t id, 523da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf) { 524da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 525da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return BAD_INDEX; 526da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 527da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian DisplayData& disp(mDisplayData[id]); 528da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (!disp.framebufferTarget) { 529da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // this should never happen, but apparently eglCreateWindowSurface() 530da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // triggers a SurfaceTextureClient::queueBuffer() on some 531da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // devices (!?) -- log and ignore. 532da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian ALOGE("HWComposer: framebufferTarget is null"); 533f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian// CallStack stack; 534f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian// stack.update(); 535f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian// stack.dump(""); 536da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return NO_ERROR; 537da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 538da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 539da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian int acquireFenceFd = -1; 540da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (acquireFence != NULL) { 541da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian acquireFenceFd = acquireFence->dup(); 542da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 543da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 544da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // ALOGD("fbPost: handle=%p, fence=%d", buf->handle, acquireFenceFd); 545da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.fbTargetHandle = buf->handle; 546da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->handle = disp.fbTargetHandle; 547da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->acquireFenceFd = acquireFenceFd; 548da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return NO_ERROR; 549da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian} 550da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 551e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianstatus_t HWComposer::prepare() { 552f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 553da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian DisplayData& disp(mDisplayData[i]); 554da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (disp.framebufferTarget) { 555da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // make sure to reset the type to HWC_FRAMEBUFFER_TARGET 556da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // DO NOT reset the handle field to NULL, because it's possible 557da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // that we have nothing to redraw (eg: eglSwapBuffers() not called) 558da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // in which case, we should continue to use the same buffer. 55927ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden LOG_FATAL_IF(disp.list == NULL); 560da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->compositionType = HWC_FRAMEBUFFER_TARGET; 561da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 56227ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden if (!disp.connected && disp.list != NULL) { 56327ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden ALOGW("WARNING: disp %d: connected, non-null list, layers=%d", 56427ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden i, disp.list->numHwLayers); 56527ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden } 566da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian mLists[i] = disp.list; 567f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (mLists[i]) { 568db27621e22559a1b16414f890677ef04242fbc3bJesse Hall if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_2)) { 569db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->outbuf = NULL; 570db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->outbufAcquireFenceFd = -1; 571db27621e22559a1b16414f890677ef04242fbc3bJesse Hall } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 572db27621e22559a1b16414f890677ef04242fbc3bJesse Hall // garbage data to catch improper use 573db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->dpy = (hwc_display_t)0xDEADBEEF; 574db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->sur = (hwc_surface_t)0xDEADBEEF; 575db27621e22559a1b16414f890677ef04242fbc3bJesse Hall } else { 576db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->dpy = EGL_NO_DISPLAY; 577db27621e22559a1b16414f890677ef04242fbc3bJesse Hall mLists[i]->sur = EGL_NO_SURFACE; 578db27621e22559a1b16414f890677ef04242fbc3bJesse Hall } 579f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 580f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 581db27621e22559a1b16414f890677ef04242fbc3bJesse Hall 582f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int err = mHwc->prepare(mHwc, mNumDisplays, mLists); 583da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian ALOGE_IF(err, "HWComposer: prepare failed (%s)", strerror(-err)); 584da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 5859c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 5865f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // here we're just making sure that "skip" layers are set 5875f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // to HWC_FRAMEBUFFER and we're also counting how many layers 5885f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // we have of each type. 589f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 590f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[i]); 591f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasFbComp = false; 592f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasOvComp = false; 593f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list) { 594f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { 595f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian hwc_layer_1_t& l = disp.list->hwLayers[i]; 596da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 597da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian //ALOGD("prepare: %d, type=%d, handle=%p", 598da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // i, l.compositionType, l.handle); 599da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 600f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.flags & HWC_SKIP_LAYER) { 601f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.compositionType = HWC_FRAMEBUFFER; 602f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 603f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.compositionType == HWC_FRAMEBUFFER) { 604f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasFbComp = true; 605f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 606f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.compositionType == HWC_OVERLAY) { 607f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasOvComp = true; 608f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 609f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 6109c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 6119c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 6129c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 613a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 614a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 615a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 616e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianbool HWComposer::hasHwcComposition(int32_t id) const { 617f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) 618e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return false; 619e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[id].hasOvComp; 620e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 6215f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian 622e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianbool HWComposer::hasGlesComposition(int32_t id) const { 623f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) 624e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return false; 625e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[id].hasFbComp; 6269c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 6279c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 628da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianint HWComposer::getAndResetReleaseFenceFd(int32_t id) { 629da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) 630da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return BAD_INDEX; 631da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 632da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian int fd = INVALID_OPERATION; 633da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 634da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const DisplayData& disp(mDisplayData[id]); 635da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (disp.framebufferTarget) { 636da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian fd = disp.framebufferTarget->releaseFenceFd; 637d30b36d1fd0c7ab80553e784a155266be9703e47Jamie Gennis disp.framebufferTarget->acquireFenceFd = -1; 638da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian disp.framebufferTarget->releaseFenceFd = -1; 639da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 640da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 641da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return fd; 642da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian} 643da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 64430bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopianstatus_t HWComposer::commit() { 6458630320433bd15aca239522e54e711ef6372ab07Mathias Agopian int err = NO_ERROR; 6468630320433bd15aca239522e54e711ef6372ab07Mathias Agopian if (mHwc) { 6479eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 64830bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian // On version 1.0, the OpenGL ES target surface is communicated 649f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // by the (dpy, sur) fields and we are guaranteed to have only 650f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // a single display. 65130bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mLists[0]->dpy = eglGetCurrentDisplay(); 65230bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mLists[0]->sur = eglGetCurrentSurface(EGL_DRAW); 65330bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian } 654f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian 65530bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian err = mHwc->set(mHwc, mNumDisplays, mLists); 656f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian 657f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 658f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[i]); 659f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list) { 660db27621e22559a1b16414f890677ef04242fbc3bJesse Hall if (disp.list->retireFenceFd != -1) { 661db27621e22559a1b16414f890677ef04242fbc3bJesse Hall close(disp.list->retireFenceFd); 662db27621e22559a1b16414f890677ef04242fbc3bJesse Hall disp.list->retireFenceFd = -1; 663f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 664f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flags &= ~HWC_GEOMETRY_CHANGED; 665f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 6668630320433bd15aca239522e54e711ef6372ab07Mathias Agopian } 66758959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 668a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 669a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 670a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 67181cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopianstatus_t HWComposer::release(int disp) { 672c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden LOG_FATAL_IF(disp >= HWC_NUM_DISPLAY_TYPES); 6737ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 67481cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian eventControl(disp, HWC_EVENT_VSYNC, 0); 675c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden return (status_t)mHwc->blank(mHwc, disp, 1); 6767ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 6777ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 6787ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 6797ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 68081cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopianstatus_t HWComposer::acquire(int disp) { 681c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden LOG_FATAL_IF(disp >= HWC_NUM_DISPLAY_TYPES); 68210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc) { 683c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden return (status_t)mHwc->blank(mHwc, disp, 0); 68410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 68510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return NO_ERROR; 68610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross} 68710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 68827ec5739bc05330e08b02f25b62a8f597bad897aAndy McFaddenvoid HWComposer::disconnectDisplay(int disp) { 6895a8f9012ee8bb9dc1ad14432b96a821f08802ee3Andy McFadden LOG_ALWAYS_FATAL_IF(disp < 0 || disp == HWC_DISPLAY_PRIMARY); 6905a8f9012ee8bb9dc1ad14432b96a821f08802ee3Andy McFadden if (disp >= HWC_NUM_DISPLAY_TYPES) { 6915a8f9012ee8bb9dc1ad14432b96a821f08802ee3Andy McFadden // nothing to do for these yet 6925a8f9012ee8bb9dc1ad14432b96a821f08802ee3Andy McFadden return; 6935a8f9012ee8bb9dc1ad14432b96a821f08802ee3Andy McFadden } 69427ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden DisplayData& dd(mDisplayData[disp]); 69527ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden if (dd.list != NULL) { 69627ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden free(dd.list); 69727ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden dd.list = NULL; 69827ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden dd.framebufferTarget = NULL; // points into dd.list 69927ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden } 70027ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden} 70127ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden 702cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopianint HWComposer::getVisualID() const { 703d3d35f18345c3ef93217313a583ace473b5a47adJesse Hall if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 704da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // FIXME: temporary hack until HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED 705da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // is supported by the implementation. we can only be in this case 706da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // if we have HWC 1.1 707da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return HAL_PIXEL_FORMAT_RGBA_8888; 708da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian //return HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; 709cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian } else { 710cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian return mFbDev->format; 711cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian } 712b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 713b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 714da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianbool HWComposer::supportsFramebufferTarget() const { 715da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)); 716da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian} 717da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 718da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianint HWComposer::fbPost(int32_t id, 719da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) { 720d3d35f18345c3ef93217313a583ace473b5a47adJesse Hall if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 721da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return setFramebufferTarget(id, acquireFence, buffer); 722da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } else { 723da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (acquireFence != NULL) { 724ba607d53c6a94ea8c4c12571980c4ad159af308bJesse Hall acquireFence->waitForever(1000, "HWComposer::fbPost"); 725da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 726da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return mFbDev->post(mFbDev, buffer->handle); 727cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian } 728cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian} 729cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian 730cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopianint HWComposer::fbCompositionComplete() { 731d3d35f18345c3ef93217313a583ace473b5a47adJesse Hall if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) 732da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return NO_ERROR; 733da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 734da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (mFbDev->compositionComplete) { 735da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return mFbDev->compositionComplete(mFbDev); 736da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } else { 737da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return INVALID_OPERATION; 738b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 739b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 740b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 741b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid HWComposer::fbDump(String8& result) { 742cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian if (mFbDev && mFbDev->common.version >= 1 && mFbDev->dump) { 743b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden const size_t SIZE = 4096; 744b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden char buffer[SIZE]; 745b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mFbDev->dump(mFbDev, buffer, SIZE); 746b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden result.append(buffer); 747b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 748b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 749b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 7503e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 7513e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Helper template to implement a concrete HWCLayer 7523e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This holds the pointer to the concrete hwc layer type 7533e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * and implements the "iterable" side of HWCLayer. 7543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 7553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopiantemplate<typename CONCRETE, typename HWCTYPE> 7563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianclass Iterable : public HWComposer::HWCLayer { 7573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprotected: 7583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* const mLayerList; 7593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* mCurrentLayer; 7603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian Iterable(HWCTYPE* layer) : mLayerList(layer), mCurrentLayer(layer) { } 7613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE const * getLayer() const { return mCurrentLayer; } 7623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE* getLayer() { return mCurrentLayer; } 7633e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual ~Iterable() { } 7643e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprivate: 7653e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // returns a copy of ourselves 7663e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual HWComposer::HWCLayer* dup() { 7673e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return new CONCRETE( static_cast<const CONCRETE&>(*this) ); 7683e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 7693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual status_t setLayer(size_t index) { 7703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCurrentLayer = &mLayerList[index]; 7713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return NO_ERROR; 7723e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 7733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 7743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 7755880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall/* 7765880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_1_0. 7775880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * This implements the HWCLayer side of HWCIterableLayer. 7785880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall */ 7795880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> { 7803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianpublic: 7815880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion1(hwc_layer_1_t* layer) 7825880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion1, hwc_layer_1_t>(layer) { } 7833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 7843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual int32_t getCompositionType() const { 7853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->compositionType; 7863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 7873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual uint32_t getHints() const { 7883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->hints; 7893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 790ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 791ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall int fd = getLayer()->releaseFenceFd; 792ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall getLayer()->releaseFenceFd = -1; 793ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return fd; 794ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 795dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 796dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall getLayer()->acquireFenceFd = fenceFd; 797dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 7983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 7993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setDefaultState() { 8003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 8013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->hints = 0; 8023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags = HWC_SKIP_LAYER; 80355882dea1b1b305f15192b96ff7814f18babb212Mathias Agopian getLayer()->handle = 0; 8043e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = 0; 8053e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = HWC_BLENDING_NONE; 8063e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.numRects = 0; 8073e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = NULL; 8085880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->acquireFenceFd = -1; 8095880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->releaseFenceFd = -1; 8103e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8113e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setSkip(bool skip) { 8123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (skip) { 8133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 8143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 8153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags &= ~HWC_SKIP_LAYER; 8163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8173e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8183e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBlending(uint32_t blending) { 8193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = blending; 8203e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8213e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setTransform(uint32_t transform) { 8223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = transform; 8233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8243e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setFrame(const Rect& frame) { 8253e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 8263e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8273e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setCrop(const Rect& crop) { 8283e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 8293e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8303e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setVisibleRegionScreen(const Region& reg) { 831c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian // Region::getSharedBuffer creates a reference to the underlying 832c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian // SharedBuffer of this Region, this reference is freed 833c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian // in onDisplayed() 834c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian hwc_region_t& visibleRegion = getLayer()->visibleRegionScreen; 835c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian SharedBuffer const* sb = reg.getSharedBuffer(&visibleRegion.numRects); 836c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian visibleRegion.rects = reinterpret_cast<hwc_rect_t const *>(sb->data()); 8373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 8393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (buffer == 0 || buffer->handle == 0) { 8403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 8413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 8423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = 0; 8433e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 8443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = buffer->handle; 8453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 8463e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 847c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian virtual void onDisplayed() { 848c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian hwc_region_t& visibleRegion = getLayer()->visibleRegionScreen; 849c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian SharedBuffer const* sb = SharedBuffer::bufferFromData(visibleRegion.rects); 850c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian if (sb) { 851c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian sb->release(); 852c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian // not technically needed but safer 853c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian visibleRegion.numRects = 0; 854c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian visibleRegion.rects = NULL; 855c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian } 856e25d005d91344c500450f01d4a258ca9c3676627Jesse Hall 857e25d005d91344c500450f01d4a258ca9c3676627Jesse Hall getLayer()->acquireFenceFd = -1; 858c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian } 8593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 8603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 8613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 8623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator initialized at a given index in the layer list 8633e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 8645f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::getLayerIterator(int32_t id, size_t index) { 865f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 8665f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian return LayerListIterator(); 867f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 868f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const DisplayData& disp(mDisplayData[id]); 869f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (!mHwc || !disp.list || index > disp.list->numHwLayers) { 8703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return LayerListIterator(); 871f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 872f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return LayerListIterator(new HWCLayerVersion1(disp.list->hwLayers), index); 8733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 8743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 8753e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 8763e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the beginning of the layer list 8773e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 8785f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::begin(int32_t id) { 8791e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian return getLayerIterator(id, 0); 880a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 881a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 8823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 8833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the end of the layer list 8843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 8855f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::end(int32_t id) { 886da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian size_t numLayers = 0; 887da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (uint32_t(id) <= 31 && mAllocatedDisplayIDs.hasBit(id)) { 888da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const DisplayData& disp(mDisplayData[id]); 889da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (mHwc && disp.list) { 890da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian numLayers = disp.list->numHwLayers; 891da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 892da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // with HWC 1.1, the last layer is always the HWC_FRAMEBUFFER_TARGET, 893da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // which we ignore when iterating through the layer list. 894da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian ALOGE_IF(!numLayers, "mDisplayData[%d].list->numHwLayers is 0", id); 895da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (numLayers) { 896da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian numLayers--; 897da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 898da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 899da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 900da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 901da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return getLayerIterator(id, numLayers); 9023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 9033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 90422da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 90522da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 906b685c542836b93c99cd85053e07696406ea37adbJesse Hall if (mHwc) { 907cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian result.appendFormat("Hardware Composer state (version %8x):\n", hwcApiVersion(mHwc)); 908f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.appendFormat(" mDebugForceFakeVSync=%d\n", mDebugForceFakeVSync); 909f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 910f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const DisplayData& disp(mDisplayData[i]); 911b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian 912b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian if (disp.connected) { 913b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian result.appendFormat( 914b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian " Display[%d] : %ux%u, xdpi=%f, ydpi=%f, refresh=%lld\n", 915b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian i, disp.width, disp.height, disp.xdpi, disp.ydpi, disp.refresh); 916b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian } 917b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian 918b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian if (disp.list && disp.connected) { 919b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian result.appendFormat( 920b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian " numHwLayers=%u, flags=%08x\n", 921b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian disp.list->numHwLayers, disp.list->flags); 922b4d18ed34e3513f3a14ea0876c7e330bee72a529Mathias Agopian 923f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.append( 924da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian " type | handle | hints | flags | tr | blend | format | source crop | frame name \n" 925da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "------------+----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 926da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian // " __________ | ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 927f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { 928f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const hwc_layer_1_t&l = disp.list->hwLayers[i]; 929f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int32_t format = -1; 930da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian String8 name("unknown"); 931da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (i < visibleLayersSortedByZ.size()) { 932da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const sp<LayerBase>& layer(visibleLayersSortedByZ[i]); 933da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (layer->getLayer() != NULL) { 934da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian const sp<GraphicBuffer>& buffer( 935f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian layer->getLayer()->getActiveBuffer()); 936da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (buffer != NULL) { 937da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian format = buffer->getPixelFormat(); 938da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 939f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 940da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian name = layer->getName(); 941da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian } 942da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 943da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian int type = l.compositionType; 944da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (type == HWC_FRAMEBUFFER_TARGET) { 945da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian name = "HWC_FRAMEBUFFER_TARGET"; 946da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian format = disp.format; 947f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 948da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 949da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian static char const* compositionTypeName[] = { 950da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "GLES", 951da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "HWC", 952da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "BACKGROUND", 953da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "FB TARGET", 954da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian "UNKNOWN"}; 955da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (type >= NELEM(compositionTypeName)) 956da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian type = NELEM(compositionTypeName) - 1; 957da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 958f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.appendFormat( 959da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian " %10s | %08x | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 960da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian compositionTypeName[type], 961f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, format, 962f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 963f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 964da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian name.string()); 965fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 966fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 9678372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 9681d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 96930bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian 97030bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian if (mHwc && mHwc->dump) { 97130bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mHwc->dump(mHwc, buffer, SIZE); 9721d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling result.append(buffer); 9738372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 9748372785879d329f592f6883620b5a32d80d74691Mathias Agopian} 9758372785879d329f592f6883620b5a32d80d74691Mathias Agopian 976a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 9772965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 9782965b26022f95051f65b09d7eac47cbe923855c9Mathias AgopianHWComposer::VSyncThread::VSyncThread(HWComposer& hwc) 9792965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian : mHwc(hwc), mEnabled(false), 9802965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync(0), 981b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mRefreshPeriod(hwc.getRefreshPeriod(HWC_DISPLAY_PRIMARY)) 9822965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian{ 9832965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 9842965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 9852965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::setEnabled(bool enabled) { 9862965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 98781cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian if (mEnabled != enabled) { 98881cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian mEnabled = enabled; 98981cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian mCondition.signal(); 99081cd5d3b94d21253a0be925f4ae58cc7f4afeef7Mathias Agopian } 9912965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 9922965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 9932965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::onFirstRef() { 9942965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian run("VSyncThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); 9952965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 9962965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 9972965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianbool HWComposer::VSyncThread::threadLoop() { 9982965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian { // scope for lock 9992965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 10002965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian while (!mEnabled) { 10012965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.wait(mLock); 10022965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 10032965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 10042965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10052965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t period = mRefreshPeriod; 10062965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t now = systemTime(CLOCK_MONOTONIC); 10072965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t next_vsync = mNextFakeVSync; 10082965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t sleep = next_vsync - now; 10092965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (sleep < 0) { 10102965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian // we missed, find where the next vsync should be 10112965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian sleep = (period - ((now - next_vsync) % period)); 10122965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian next_vsync = now + sleep; 10132965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 10142965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync = next_vsync + period; 10152965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10162965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian struct timespec spec; 10172965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_sec = next_vsync / 1000000000; 10182965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_nsec = next_vsync % 1000000000; 10192965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10202965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian int err; 10212965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian do { 10222965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); 10232965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } while (err<0 && errno == EINTR); 10242965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10252965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (err == 0) { 10262965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mHwc.mEventHandler.onVSyncReceived(0, next_vsync); 10272965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 10282965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10292965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian return true; 10302965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 10312965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 10322965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian// --------------------------------------------------------------------------- 1033a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 1034