HWComposer.cpp revision 9eb1eb5bb55740982ceae9966fc536824edc302a
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> 298372785879d329f592f6883620b5a32d80d74691Mathias Agopian#include <utils/String8.h> 303eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <utils/Thread.h> 312965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#include <utils/Trace.h> 3222da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h> 33a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 34921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <ui/GraphicBuffer.h> 35921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian 36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h> 373eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <hardware/hwcomposer.h> 38a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h> 40e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian#include <cutils/properties.h> 41a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 42921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include "Layer.h" // needed only for debugging 4322da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 44a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 45c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 46a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 47a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 499eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall#define MIN_HWC_HEADER_VERSION 0 509eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 519eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic uint32_t hwcApiVersion(const hwc_composer_device_1_t* hwc) { 529eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t hwcVersion = hwc->common.version; 539eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (MIN_HWC_HEADER_VERSION == 0 && 549eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK) == 0) { 559eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall // legacy version encoding 569eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcVersion <<= 16; 579eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 589eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK; 599eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall} 609eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 619eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic uint32_t hwcHeaderVersion(const hwc_composer_device_1_t* hwc) { 629eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t hwcVersion = hwc->common.version; 639eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (MIN_HWC_HEADER_VERSION == 0 && 649eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcVersion & HARDWARE_API_VERSION_2_MAJ_MIN_MASK) == 0) { 659eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall // legacy version encoding 669eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcVersion <<= 16; 679eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 689eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcVersion & HARDWARE_API_VERSION_2_HEADER_MASK; 699eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall} 709eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 719eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallstatic bool hwcHasApiVersion(const hwc_composer_device_1_t* hwc, 729eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall uint32_t version) { 739eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return hwcApiVersion(hwc) >= (version & HARDWARE_API_VERSION_2_MAJ_MIN_MASK); 74bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall} 75bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall 76a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 77a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 783e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianstruct HWComposer::cb_context { 793e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian struct callbacks : public hwc_procs_t { 803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // these are here to facilitate the transition when adding 813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // new callbacks (an implementation can check for NULL before 823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // calling a new callback). 833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian void (*zero[4])(void); 843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian }; 853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian callbacks procs; 863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWComposer* hwc; 873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian// --------------------------------------------------------------------------- 903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 913eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias AgopianHWComposer::HWComposer( 923eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const sp<SurfaceFlinger>& flinger, 938b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian EventHandler& handler, 948b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian framebuffer_device_t const* fbDev) 95c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 96f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mModule(0), mHwc(0), mNumDisplays(1), 973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext(new cb_context), 98e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mEventHandler(handler), 99e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mVSyncCount(0), mDebugForceFakeVSync(false) 100a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 101e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian for (size_t i =0 ; i<MAX_DISPLAYS ; i++) { 102e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mLists[i] = 0; 103e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 104b685c542836b93c99cd85053e07696406ea37adbJesse Hall 105e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian char value[PROPERTY_VALUE_MAX]; 106e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian property_get("debug.sf.no_hw_vsync", value, "0"); 107e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync = atoi(value); 108e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian 109028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian bool needVSyncThread = true; 110a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); 11132397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); 112a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (err == 0) { 1135880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall err = hwc_open_1(mModule, &mHwc); 114e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(err, "%s device failed to initialize (%s)", 115a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian HWC_HARDWARE_COMPOSER, strerror(-err)); 116c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (err == 0) { 1179eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_0) || 1189eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcHeaderVersion(mHwc) < MIN_HWC_HEADER_VERSION || 1199eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall hwcHeaderVersion(mHwc) > HWC_HEADER_VERSION) { 1209eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall ALOGE("%s device version %#x unsupported, will not be used", 1215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWC_HARDWARE_COMPOSER, mHwc->common.version); 1225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 1235880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mHwc = NULL; 1245880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1255880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1265880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 1275880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (mHwc) { 1289eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall ALOGI("Using %s version %u.%u", HWC_HARDWARE_COMPOSER, 1299eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcApiVersion(mHwc) >> 24) & 0xff, 1309eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall (hwcApiVersion(mHwc) >> 16) & 0xff); 131bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall if (mHwc->registerProcs) { 132bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall mCBContext->hwc = this; 133bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall mCBContext->procs.invalidate = &hook_invalidate; 134bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall mCBContext->procs.vsync = &hook_vsync; 135bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); 136bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall mHwc->registerProcs(mHwc, &mCBContext->procs); 137bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall } 138bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall 139b685c542836b93c99cd85053e07696406ea37adbJesse Hall // always turn vsync off when we start 140b685c542836b93c99cd85053e07696406ea37adbJesse Hall needVSyncThread = false; 14130bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mHwc->eventControl(mHwc, 0, HWC_EVENT_VSYNC, 0); 14230bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian 14330bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian int period; 14430bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian if (mHwc->query(mHwc, HWC_VSYNC_PERIOD, &period) == NO_ERROR) { 145f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mDisplayData[HWC_DISPLAY_PRIMARY].refresh = nsecs_t(period); 146028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian } 147b685c542836b93c99cd85053e07696406ea37adbJesse Hall 148f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // these IDs are always reserved 149f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<HWC_NUM_DISPLAY_TYPES ; i++) { 150f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mAllocatedDisplayIDs.markBit(i); 151f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // TODO: we query xdpi / ydpi / refresh 152f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 1538f971ff6661c875e7adb3f14731e1579c3c80c62Jesse Hall 154f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // the number of displays we actually have depends on the 155f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // hw composer version 1569eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_2)) { 157f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // 1.2 adds support for virtual displays 158f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mNumDisplays = MAX_DISPLAYS; 1599eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } else if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 1609eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall // 1.1 adds support for multiple displays 1619eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall mNumDisplays = HWC_NUM_DISPLAY_TYPES; 1629eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } else { 1639eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall mNumDisplays = 1; 164f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 165c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 1663a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 1673a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 1688b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian if (fbDev) { 169f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // if we're here it means we are on version 1.0 170f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[HWC_DISPLAY_PRIMARY]); 171f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.xdpi = fbDev->xdpi; 172f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.ydpi = fbDev->ydpi; 173f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.refresh == 0) { 174f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.refresh = nsecs_t(1e9 / fbDev->fps); 175f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian ALOGW("getting VSYNC period from fb HAL: %lld", disp.refresh); 176f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 177f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.refresh == 0) { 178f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.refresh = nsecs_t(1e9 / 60.0); 179f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian ALOGW("getting VSYNC period thin air: %lld", mDisplayData[HWC_DISPLAY_PRIMARY].refresh); 180888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian } 181888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian } 182888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian 1833a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (needVSyncThread) { 1843a77871383bc1a03cc866686d81628493d14de7cMathias Agopian // we don't have VSYNC support, we need to fake it 1853a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread = new VSyncThread(*this); 186a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 187a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 188a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 189a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 19030bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mHwc->eventControl(mHwc, 0, EVENT_VSYNC, 0); 1913eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mVSyncThread != NULL) { 1923eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mVSyncThread->requestExitAndWait(); 1933eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 194a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 1955880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 196a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 1973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian delete mCBContext; 198a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 199a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 200a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 201a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 202a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 203a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 204bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hallvoid HWComposer::hook_invalidate(const struct hwc_procs* procs) { 205bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall cb_context* ctx = reinterpret_cast<cb_context*>( 206bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall const_cast<hwc_procs_t*>(procs)); 207bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall ctx->hwc->invalidate(); 208c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 209c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 210bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hallvoid HWComposer::hook_vsync(const struct hwc_procs* procs, int dpy, 211bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall int64_t timestamp) { 212bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall cb_context* ctx = reinterpret_cast<cb_context*>( 213bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall const_cast<hwc_procs_t*>(procs)); 214bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall ctx->hwc->vsync(dpy, timestamp); 21531d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 21631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 217c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 218e2c2f9213f936f98db604dc9c126ff22f725a824Mathias Agopian mFlinger->repaintEverything(); 219c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 220c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 22131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::vsync(int dpy, int64_t timestamp) { 2222965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian ATRACE_INT("VSYNC", ++mVSyncCount&1); 2233eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler.onVSyncReceived(dpy, timestamp); 224d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian Mutex::Autolock _l(mLock); 225d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian mLastHwVSync = timestamp; 226d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian} 227d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian 228e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianint32_t HWComposer::allocateDisplayId() { 229f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (mAllocatedDisplayIDs.count() >= mNumDisplays) { 230e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return NO_MEMORY; 231e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 232f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int32_t id = mAllocatedDisplayIDs.firstUnmarkedBit(); 233f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mAllocatedDisplayIDs.markBit(id); 234e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return id; 235e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 236e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian 237e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianstatus_t HWComposer::freeDisplayId(int32_t id) { 238f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (id < HWC_NUM_DISPLAY_TYPES) { 239f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // cannot free the reserved IDs 240e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return BAD_VALUE; 241e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 242f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 243e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return BAD_INDEX; 244e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 245f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mAllocatedDisplayIDs.clearBit(id); 246e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return NO_ERROR; 247e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 248e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian 249888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopiannsecs_t HWComposer::getRefreshPeriod() const { 250f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return mDisplayData[HWC_DISPLAY_PRIMARY].refresh; 251888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian} 252888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian 253d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopiannsecs_t HWComposer::getRefreshTimestamp() const { 254d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // this returns the last refresh timestamp. 255d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // if the last one is not available, we estimate it based on 256d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian // the refresh period and whatever closest timestamp we have. 257d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian Mutex::Autolock _l(mLock); 258d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian nsecs_t now = systemTime(CLOCK_MONOTONIC); 259f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return now - ((now - mLastHwVSync) % mDisplayData[HWC_DISPLAY_PRIMARY].refresh); 2603eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian} 2613eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 2628b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopianfloat HWComposer::getDpiX() const { 263e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[HWC_DISPLAY_PRIMARY].xdpi; 2648b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian} 2658b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian 2668b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopianfloat HWComposer::getDpiY() const { 267e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[HWC_DISPLAY_PRIMARY].ydpi; 2688b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian} 2698b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian 27003e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopianvoid HWComposer::eventControl(int event, int enabled) { 2713eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t err = NO_ERROR; 27230bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian if (mHwc) { 273e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian if (!mDebugForceFakeVSync) { 27430bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian err = mHwc->eventControl(mHwc, 0, event, enabled); 27503e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // error here should not happen -- not sure what we should 27603e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // do if it does. 27703e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian ALOGE_IF(err, "eventControl(%d, %d) failed %s", 27803e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian event, enabled, strerror(-err)); 279e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 2803eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 2813a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 2823a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (err == NO_ERROR && mVSyncThread != NULL) { 2833a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread->setEnabled(enabled); 2843a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 28531d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 28631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 2875f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopianstatus_t HWComposer::createWorkList(int32_t id, size_t numLayers) { 288f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 2891e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian return BAD_INDEX; 290e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian } 2911e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian 29245721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 293f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[id]); 29413a082e160c2d1d8006b93a555a57035213d568bAndy McFadden if (disp.capacity < numLayers || disp.list == NULL) { 295f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const size_t size = sizeof(hwc_display_contents_1_t) 296f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian + numLayers * sizeof(hwc_layer_1_t); 297f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian free(disp.list); 298f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list = (hwc_display_contents_1_t*)malloc(size); 299f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.capacity = numLayers; 30045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 301f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flags = HWC_GEOMETRY_CHANGED; 302f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->numHwLayers = numLayers; 303f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flipFenceFd = -1; 304a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 305a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 306a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 307a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 308e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianstatus_t HWComposer::prepare() { 309f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 310f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mLists[i] = mDisplayData[i].list; 311f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (mLists[i]) { 312f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mLists[i]->dpy = EGL_NO_DISPLAY; 313f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mLists[i]->sur = EGL_NO_SURFACE; 314f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 315f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 316f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int err = mHwc->prepare(mHwc, mNumDisplays, mLists); 3179c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 3185f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // here we're just making sure that "skip" layers are set 3195f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // to HWC_FRAMEBUFFER and we're also counting how many layers 3205f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian // we have of each type. 321f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 322f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[i]); 323f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasFbComp = false; 324f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasOvComp = false; 325f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list) { 326f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { 327f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian hwc_layer_1_t& l = disp.list->hwLayers[i]; 328f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.flags & HWC_SKIP_LAYER) { 329f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.compositionType = HWC_FRAMEBUFFER; 330f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 331f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.compositionType == HWC_FRAMEBUFFER) { 332f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasFbComp = true; 333f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 334f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (l.compositionType == HWC_OVERLAY) { 335f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.hasOvComp = true; 336f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 337f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 3389c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 3399c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 3409c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 341a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 342a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 343a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 344e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianbool HWComposer::hasHwcComposition(int32_t id) const { 345f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) 346e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return false; 347e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[id].hasOvComp; 348e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian} 3495f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian 350e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianbool HWComposer::hasGlesComposition(int32_t id) const { 351f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) 352e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return false; 353e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian return mDisplayData[id].hasFbComp; 3549c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 3559c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 35630bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopianstatus_t HWComposer::commit() { 3578630320433bd15aca239522e54e711ef6372ab07Mathias Agopian int err = NO_ERROR; 3588630320433bd15aca239522e54e711ef6372ab07Mathias Agopian if (mHwc) { 3599eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { 36030bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian // On version 1.0, the OpenGL ES target surface is communicated 361f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // by the (dpy, sur) fields and we are guaranteed to have only 362f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // a single display. 36330bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mLists[0]->dpy = eglGetCurrentDisplay(); 36430bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mLists[0]->sur = eglGetCurrentSurface(EGL_DRAW); 36530bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian } 366f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian 36730bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian err = mHwc->set(mHwc, mNumDisplays, mLists); 368f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian 369f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 370f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian DisplayData& disp(mDisplayData[i]); 371f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list) { 372f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list->flipFenceFd != -1) { 373f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian close(disp.list->flipFenceFd); 374f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flipFenceFd = -1; 375f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 376f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian disp.list->flags &= ~HWC_GEOMETRY_CHANGED; 377f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 3788630320433bd15aca239522e54e711ef6372ab07Mathias Agopian } 37958959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 380a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 381a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 382a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 383f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const { 3847ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 38530bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mHwc->eventControl(mHwc, 0, HWC_EVENT_VSYNC, 0); 38630bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian return (status_t)mHwc->blank(mHwc, 0, 1); 3877ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 3887ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 3897ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 3907ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 39110fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Crossstatus_t HWComposer::acquire() const { 39210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc) { 39330bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian return (status_t)mHwc->blank(mHwc, 0, 0); 39410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 39510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return NO_ERROR; 39610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross} 39710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 398f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopiansize_t HWComposer::getNumLayers(int32_t id) const { 399f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 400f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return 0; 4017ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 402f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return (mHwc && mDisplayData[id].list) ? 403f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian mDisplayData[id].list->numHwLayers : 0; 404a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 405a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 4063e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 4073e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Helper template to implement a concrete HWCLayer 4083e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This holds the pointer to the concrete hwc layer type 4093e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * and implements the "iterable" side of HWCLayer. 4103e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 4113e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopiantemplate<typename CONCRETE, typename HWCTYPE> 4123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianclass Iterable : public HWComposer::HWCLayer { 4133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprotected: 4143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* const mLayerList; 4153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* mCurrentLayer; 4163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian Iterable(HWCTYPE* layer) : mLayerList(layer), mCurrentLayer(layer) { } 4173e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE const * getLayer() const { return mCurrentLayer; } 4183e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE* getLayer() { return mCurrentLayer; } 4193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual ~Iterable() { } 4203e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprivate: 4213e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // returns a copy of ourselves 4223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual HWComposer::HWCLayer* dup() { 4233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return new CONCRETE( static_cast<const CONCRETE&>(*this) ); 4243e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4253e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual status_t setLayer(size_t index) { 4263e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCurrentLayer = &mLayerList[index]; 4273e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return NO_ERROR; 4283e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4293e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 4303e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4315880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall/* 4325880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_1_0. 4335880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * This implements the HWCLayer side of HWCIterableLayer. 4345880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall */ 4355880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> { 4363e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianpublic: 4375880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion1(hwc_layer_1_t* layer) 4385880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion1, hwc_layer_1_t>(layer) { } 4393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual int32_t getCompositionType() const { 4413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->compositionType; 4423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4433e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual uint32_t getHints() const { 4443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->hints; 4453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 446ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 447ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall int fd = getLayer()->releaseFenceFd; 448ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall getLayer()->releaseFenceFd = -1; 449ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return fd; 450ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 451dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 452dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall getLayer()->acquireFenceFd = fenceFd; 453dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 4543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setDefaultState() { 4563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->hints = 0; 4583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags = HWC_SKIP_LAYER; 4593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = 0; 4603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = HWC_BLENDING_NONE; 4613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.numRects = 0; 4623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = NULL; 4635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->acquireFenceFd = -1; 4645880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->releaseFenceFd = -1; 4653e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4663e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setSkip(bool skip) { 4673e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (skip) { 4683e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags &= ~HWC_SKIP_LAYER; 4713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4723e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBlending(uint32_t blending) { 4743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = blending; 4753e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4763e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setTransform(uint32_t transform) { 4773e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = transform; 4783e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4793e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setFrame(const Rect& frame) { 4803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 4813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setCrop(const Rect& crop) { 4833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 4843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setVisibleRegionScreen(const Region& reg) { 4863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = 4873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<hwc_rect_t const *>( 4883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reg.getArray(&getLayer()->visibleRegionScreen.numRects)); 4893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 4913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (buffer == 0 || buffer->handle == 0) { 4923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = 0; 4953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = buffer->handle; 4973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 5003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator initialized at a given index in the layer list 5033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5045f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::getLayerIterator(int32_t id, size_t index) { 505f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (uint32_t(id)>31 || !mAllocatedDisplayIDs.hasBit(id)) { 5065f20e2d4462da3471f59152b32cd8640fa4a21daMathias Agopian return LayerListIterator(); 507f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 508f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const DisplayData& disp(mDisplayData[id]); 509f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (!mHwc || !disp.list || index > disp.list->numHwLayers) { 5103e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return LayerListIterator(); 511f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 512f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian return LayerListIterator(new HWCLayerVersion1(disp.list->hwLayers), index); 5133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the beginning of the layer list 5173e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5185f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::begin(int32_t id) { 5191e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian return getLayerIterator(id, 0); 520a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 521a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 5223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the end of the layer list 5243e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5255f20e2d4462da3471f59152b32cd8640fa4a21daMathias AgopianHWComposer::LayerListIterator HWComposer::end(int32_t id) { 5261e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian return getLayerIterator(id, getNumLayers(id)); 5273e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5283e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 52922da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 53022da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 531b685c542836b93c99cd85053e07696406ea37adbJesse Hall if (mHwc) { 5328372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append("Hardware Composer state:\n"); 533f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.appendFormat(" mDebugForceFakeVSync=%d\n", mDebugForceFakeVSync); 534f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<mNumDisplays ; i++) { 535f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const DisplayData& disp(mDisplayData[i]); 536f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (disp.list) { 537f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.appendFormat(" id=%d, numHwLayers=%u, flags=%08x\n", 538f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian i, disp.list->numHwLayers, disp.list->flags); 539f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.append( 540f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian " type | handle | hints | flags | tr | blend | format | source crop | frame name \n" 541f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian "----------+----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 542f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian // " ________ | ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 543f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian for (size_t i=0 ; i<disp.list->numHwLayers ; i++) { 544f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const hwc_layer_1_t&l = disp.list->hwLayers[i]; 545f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const sp<LayerBase> layer(visibleLayersSortedByZ[i]); 546f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian int32_t format = -1; 547f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (layer->getLayer() != NULL) { 548f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian const sp<GraphicBuffer>& buffer( 549f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian layer->getLayer()->getActiveBuffer()); 550f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian if (buffer != NULL) { 551f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian format = buffer->getPixelFormat(); 552f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 553f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian } 554f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian result.appendFormat( 555f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian " %8s | %08x | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 556f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.compositionType ? "OVERLAY" : "FB", 557f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, format, 558f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 559f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 560f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian layer->getName().string()); 561fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 562fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 5638372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 5641d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 56530bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian 56630bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian if (mHwc && mHwc->dump) { 56730bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian mHwc->dump(mHwc, buffer, SIZE); 5681d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling result.append(buffer); 5698372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 5708372785879d329f592f6883620b5a32d80d74691Mathias Agopian} 5718372785879d329f592f6883620b5a32d80d74691Mathias Agopian 572a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 5732965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5742965b26022f95051f65b09d7eac47cbe923855c9Mathias AgopianHWComposer::VSyncThread::VSyncThread(HWComposer& hwc) 5752965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian : mHwc(hwc), mEnabled(false), 5762965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync(0), 577e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mRefreshPeriod(hwc.getRefreshPeriod()) 5782965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian{ 5792965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5802965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5812965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::setEnabled(bool enabled) { 5822965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 5832965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mEnabled = enabled; 5842965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.signal(); 5852965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5862965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5872965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::onFirstRef() { 5882965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian run("VSyncThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); 5892965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5902965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5912965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianbool HWComposer::VSyncThread::threadLoop() { 5922965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian { // scope for lock 5932965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 5942965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian while (!mEnabled) { 5952965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.wait(mLock); 5962965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 5972965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 5982965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5992965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t period = mRefreshPeriod; 6002965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t now = systemTime(CLOCK_MONOTONIC); 6012965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t next_vsync = mNextFakeVSync; 6022965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t sleep = next_vsync - now; 6032965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (sleep < 0) { 6042965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian // we missed, find where the next vsync should be 6052965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian sleep = (period - ((now - next_vsync) % period)); 6062965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian next_vsync = now + sleep; 6072965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6082965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync = next_vsync + period; 6092965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6102965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian struct timespec spec; 6112965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_sec = next_vsync / 1000000000; 6122965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_nsec = next_vsync % 1000000000; 6132965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6142965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian int err; 6152965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian do { 6162965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); 6172965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } while (err<0 && errno == EINTR); 6182965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6192965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (err == 0) { 6202965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mHwc.mEventHandler.onVSyncReceived(0, next_vsync); 6212965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6222965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6232965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian return true; 6242965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 6252965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6262965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian// --------------------------------------------------------------------------- 627a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 628