HWComposer.cpp revision 10fbdb6059755f009e02f0ccc2b9d289beb6b086
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 205880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// #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 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h> 353eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <hardware/hwcomposer.h> 36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h> 38e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian#include <cutils/properties.h> 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 40a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h> 41a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 4222da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 44c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 46a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 475880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// --------------------------------------------------------------------------- 495880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// Support for HWC_DEVICE_API_VERSION_0_3 and older: 505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// Since v0.3 is deprecated and support will be dropped soon, as much as 515880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// possible the code is written to target v1.0. When using a v0.3 HWC, we 525880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// allocate v0.3 structures, but assign them to v1.0 pointers. Fields that 535880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// exist in both versions are located at the same offset, so in most cases we 545880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// can just use the v1.0 pointer without branches or casts. 555880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 565880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall#if HWC_REMOVE_DEPRECATED_VERSIONS 575880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// We need complete types with to satisfy semantic checks, even though the 585880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// code paths that use these won't get executed at runtime (and will likely be 595880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// dead-code-eliminated). When we remove the code to support v0.3 we can remove 605880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// these as well. 615880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_layer_1_t hwc_layer_t; 625880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_layer_list_1_t hwc_layer_list_t; 635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_composer_device_1_t hwc_composer_device_t; 645880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall#endif 655880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 665880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// This function assumes we've already rejected HWC's with lower-than-required 675880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// versions. Don't use it for the initial "does HWC meet requirements" check! 685880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallstatic bool hwcHasVersion(const hwc_composer_device_1_t* hwc, uint32_t version) { 695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (HWC_REMOVE_DEPRECATED_VERSIONS && 705880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall version <= HWC_DEVICE_API_VERSION_1_0) { 715880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return true; 725880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 735880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return hwc->common.version >= version; 745880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 755880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall} 765880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 775880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallstatic size_t sizeofHwcLayerList(const hwc_composer_device_1_t* hwc, 785880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall size_t numLayers) { 795880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(hwc, HWC_DEVICE_API_VERSION_1_0)) { 805880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return sizeof(hwc_layer_list_1_t) + numLayers*sizeof(hwc_layer_1_t); 815880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 825880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return sizeof(hwc_layer_list_t) + numLayers*sizeof(hwc_layer_t); 835880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 845880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall} 855880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 86a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 87a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianstruct HWComposer::cb_context { 893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian struct callbacks : public hwc_procs_t { 903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // these are here to facilitate the transition when adding 913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // new callbacks (an implementation can check for NULL before 923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // calling a new callback). 933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian void (*zero[4])(void); 943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian }; 953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian callbacks procs; 963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWComposer* hwc; 973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian// --------------------------------------------------------------------------- 1003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 1013eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias AgopianHWComposer::HWComposer( 1023eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const sp<SurfaceFlinger>& flinger, 1033eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EventHandler& handler, 1043eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian nsecs_t refreshPeriod) 105c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 106c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mModule(0), mHwc(0), mList(0), mCapacity(0), 1079c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers(0), mNumFBLayers(0), 1083eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE), 1093e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext(new cb_context), 1103eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler(handler), 111e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mRefreshPeriod(refreshPeriod), 112e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mVSyncCount(0), mDebugForceFakeVSync(false) 113a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 114e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian char value[PROPERTY_VALUE_MAX]; 115e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian property_get("debug.sf.no_hw_vsync", value, "0"); 116e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync = atoi(value); 117e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian 1183a77871383bc1a03cc866686d81628493d14de7cMathias Agopian bool needVSyncThread = false; 119a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); 12032397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); 121a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (err == 0) { 1225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall err = hwc_open_1(mModule, &mHwc); 123e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(err, "%s device failed to initialize (%s)", 124a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian HWC_HARDWARE_COMPOSER, strerror(-err)); 125c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (err == 0) { 1265880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (HWC_REMOVE_DEPRECATED_VERSIONS && 1275880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mHwc->common.version < HWC_DEVICE_API_VERSION_1_0) { 1285880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall ALOGE("%s device version %#x too old, will not be used", 1295880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWC_HARDWARE_COMPOSER, mHwc->common.version); 1305880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 1315880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mHwc = NULL; 1325880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1335880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1345880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 1355880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (mHwc) { 136c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (mHwc->registerProcs) { 1373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->hwc = this; 1383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->procs.invalidate = &hook_invalidate; 1393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->procs.vsync = &hook_vsync; 1403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mHwc->registerProcs(mHwc, &mCBContext->procs); 1413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); 142c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 1435880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { 144e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian if (mDebugForceFakeVSync) { 145e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian // make sure to turn h/w vsync off in "fake vsync" mode 146e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); 147e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 148e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } else { 1493a77871383bc1a03cc866686d81628493d14de7cMathias Agopian needVSyncThread = true; 1503eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 151c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 1523a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } else { 1533a77871383bc1a03cc866686d81628493d14de7cMathias Agopian needVSyncThread = true; 1543a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 1553a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 1563a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (needVSyncThread) { 1573a77871383bc1a03cc866686d81628493d14de7cMathias Agopian // we don't have VSYNC support, we need to fake it 1583a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread = new VSyncThread(*this); 159a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 160a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 161a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 162a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 163e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian eventControl(EVENT_VSYNC, 0); 164a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian free(mList); 1653eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mVSyncThread != NULL) { 1663eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mVSyncThread->requestExitAndWait(); 1673eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 168a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 1695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 170a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 1713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian delete mCBContext; 172a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 173a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 174a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 175a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 176a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 177a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 178c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::hook_invalidate(struct hwc_procs* procs) { 179c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->invalidate(); 180c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 181c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 18231d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::hook_vsync(struct hwc_procs* procs, int dpy, int64_t timestamp) { 18331d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->vsync(dpy, timestamp); 18431d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 18531d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 186c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 187e2c2f9213f936f98db604dc9c126ff22f725a824Mathias Agopian mFlinger->repaintEverything(); 188c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 189c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 19031d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::vsync(int dpy, int64_t timestamp) { 1912965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian ATRACE_INT("VSYNC", ++mVSyncCount&1); 1923eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler.onVSyncReceived(dpy, timestamp); 1933eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian} 1943eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 19503e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopianvoid HWComposer::eventControl(int event, int enabled) { 1963eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t err = NO_ERROR; 1971a3bf41b7165ba294af46bc32483eaad61e707eaErik Gilling if (mHwc && mHwc->common.version >= HWC_DEVICE_API_VERSION_0_3) { 198e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian if (!mDebugForceFakeVSync) { 199e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian err = mHwc->methods->eventControl(mHwc, event, enabled); 20003e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // error here should not happen -- not sure what we should 20103e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // do if it does. 20203e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian ALOGE_IF(err, "eventControl(%d, %d) failed %s", 20303e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian event, enabled, strerror(-err)); 204e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 2053eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 2063a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 2073a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (err == NO_ERROR && mVSyncThread != NULL) { 2083a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread->setEnabled(enabled); 2093a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 21031d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 21131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 212a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianvoid HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { 213a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mDpy = (hwc_display_t)dpy; 214a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mSur = (hwc_surface_t)sur; 215a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 216a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 217a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::createWorkList(size_t numLayers) { 21845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 21945721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (!mList || mCapacity < numLayers) { 22045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian free(mList); 2215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall size_t size = sizeofHwcLayerList(mHwc, numLayers); 2225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mList = (hwc_layer_list_1_t*)malloc(size); 22345721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mCapacity = numLayers; 22445721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 225a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->flags = HWC_GEOMETRY_CHANGED; 226a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->numHwLayers = numLayers; 227a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 228a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 229a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 230a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 231a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::prepare() const { 232a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->prepare(mHwc, mList); 2339c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 2349c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numOVLayers = 0; 2359c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numFBLayers = 0; 2369c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t count = mList->numHwLayers; 2379c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian for (size_t i=0 ; i<count ; i++) { 2385880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_1_t* l = NULL; 2395880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 2405880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = &mList->hwLayers[i]; 2415880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 2425880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall // mList really has hwc_layer_list_t memory layout 2435880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list = (hwc_layer_list_t*)mList; 2445880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_t* layer = &list->hwLayers[i]; 2455880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = (hwc_layer_1_t*)layer; 2469c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2475880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (l->flags & HWC_SKIP_LAYER) { 2485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l->compositionType = HWC_FRAMEBUFFER; 2495880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 2505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall switch (l->compositionType) { 2519c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 2529c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numOVLayers++; 2539c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 2549c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 2559c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numFBLayers++; 2569c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 2579c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2589c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2599c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers = numOVLayers; 2609c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumFBLayers = numFBLayers; 2619c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 262a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 263a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 264a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 2659c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopiansize_t HWComposer::getLayerCount(int type) const { 2669c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (type) { 2679c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 2689c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumOVLayers; 2699c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 2709c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumFBLayers; 2719c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2729c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return 0; 2739c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 2749c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 275a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::commit() const { 276a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->set(mHwc, mDpy, mSur, mList); 27758959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian if (mList) { 27858959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian mList->flags &= ~HWC_GEOMETRY_CHANGED; 27958959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 280a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 281a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 282a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 283f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const { 2847ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 2855880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { 28622ffb117b0c2a906bd04aef9738a52223cdd1dceMathias Agopian mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); 28722ffb117b0c2a906bd04aef9738a52223cdd1dceMathias Agopian } 2887ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->set(mHwc, NULL, NULL, NULL); 28910fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (err < 0) { 29010fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return (status_t)err; 29110fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 29210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 29310fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 29410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc->methods && mHwc->methods->blank) { 29510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross err = mHwc->methods->blank(mHwc, 1); 29610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 29710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 2987ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 2997ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 3007ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 3017ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 3027ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 30310fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Crossstatus_t HWComposer::acquire() const { 30410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc) { 30510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 30610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc->methods && mHwc->methods->blank) { 30710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross int err = mHwc->methods->blank(mHwc, 0); 30810fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return (status_t)err; 30910fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31010fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31110fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 31310fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return NO_ERROR; 31410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross} 31510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 3167ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopianstatus_t HWComposer::disable() { 3177ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 3187ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian free(mList); 3197ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian mList = NULL; 3207ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->prepare(mHwc, NULL); 3217ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 3227ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 3237ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 324f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala} 325f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala 32645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopiansize_t HWComposer::getNumLayers() const { 32745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->numHwLayers : 0; 328a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 329a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 3303e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 3313e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Helper template to implement a concrete HWCLayer 3323e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This holds the pointer to the concrete hwc layer type 3333e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * and implements the "iterable" side of HWCLayer. 3343e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 3353e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopiantemplate<typename CONCRETE, typename HWCTYPE> 3363e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianclass Iterable : public HWComposer::HWCLayer { 3373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprotected: 3383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* const mLayerList; 3393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* mCurrentLayer; 3403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian Iterable(HWCTYPE* layer) : mLayerList(layer), mCurrentLayer(layer) { } 3413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE const * getLayer() const { return mCurrentLayer; } 3423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE* getLayer() { return mCurrentLayer; } 3433e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual ~Iterable() { } 3443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprivate: 3453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // returns a copy of ourselves 3463e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual HWComposer::HWCLayer* dup() { 3473e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return new CONCRETE( static_cast<const CONCRETE&>(*this) ); 3483e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 3493e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual status_t setLayer(size_t index) { 3503e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCurrentLayer = &mLayerList[index]; 3513e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return NO_ERROR; 3523e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 3533e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 3543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 3555880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// #if !HWC_REMOVE_DEPRECATED_VERSIONS 3563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 3573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_0_3 3583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This implements the HWCLayer side of HWCIterableLayer. 3593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 3605880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion0 : public Iterable<HWCLayerVersion0, hwc_layer_t> { 3615880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallpublic: 3625880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion0(hwc_layer_t* layer) 3635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion0, hwc_layer_t>(layer) { } 3645880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 3655880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual int32_t getCompositionType() const { 3665880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return getLayer()->compositionType; 3675880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3685880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual uint32_t getHints() const { 3695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return getLayer()->hints; 3705880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 371ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 372ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall // not supported on VERSION_03 373ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return -1; 374ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 375dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 376dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall if (fenceFd != -1) { 377dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall ALOGE("HWC 0.x can't handle acquire fences"); 378dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall close(fenceFd); 379dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 380dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 3815880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 3825880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setDefaultState() { 3835880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->compositionType = HWC_FRAMEBUFFER; 3845880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->hints = 0; 3855880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags = HWC_SKIP_LAYER; 3865880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->transform = 0; 3875880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->blending = HWC_BLENDING_NONE; 3885880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.numRects = 0; 3895880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.rects = NULL; 3905880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3915880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setSkip(bool skip) { 3925880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (skip) { 3935880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags |= HWC_SKIP_LAYER; 3945880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 3955880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags &= ~HWC_SKIP_LAYER; 3965880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3975880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3985880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setBlending(uint32_t blending) { 3995880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->blending = blending; 4005880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4015880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setTransform(uint32_t transform) { 4025880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->transform = transform; 4035880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4045880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setFrame(const Rect& frame) { 4055880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 4065880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setCrop(const Rect& crop) { 4085880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 4095880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4105880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setVisibleRegionScreen(const Region& reg) { 4115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.rects = 4125880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<hwc_rect_t const *>( 4135880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reg.getArray(&getLayer()->visibleRegionScreen.numRects)); 4145880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4155880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 4165880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (buffer == 0 || buffer->handle == 0) { 4175880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->compositionType = HWC_FRAMEBUFFER; 4185880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags |= HWC_SKIP_LAYER; 4195880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->handle = 0; 4205880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 4215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->handle = buffer->handle; 4225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4235880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4245880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall}; 4255880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// #endif // !HWC_REMOVE_DEPRECATED_VERSIONS 4265880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 4275880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall/* 4285880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_1_0. 4295880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * This implements the HWCLayer side of HWCIterableLayer. 4305880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall */ 4315880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> { 4323e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianpublic: 4335880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion1(hwc_layer_1_t* layer) 4345880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion1, hwc_layer_1_t>(layer) { } 4353e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4363e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual int32_t getCompositionType() const { 4373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->compositionType; 4383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual uint32_t getHints() const { 4403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->hints; 4413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 442ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 443ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall int fd = getLayer()->releaseFenceFd; 444ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall getLayer()->releaseFenceFd = -1; 445ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return fd; 446ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 447dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 448dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall getLayer()->acquireFenceFd = fenceFd; 449dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 4503e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4513e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setDefaultState() { 4523e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4533e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->hints = 0; 4543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags = HWC_SKIP_LAYER; 4553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = 0; 4563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = HWC_BLENDING_NONE; 4573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.numRects = 0; 4583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = NULL; 4595880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->acquireFenceFd = -1; 4605880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->releaseFenceFd = -1; 4613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setSkip(bool skip) { 4633e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (skip) { 4643e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4653e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4663e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags &= ~HWC_SKIP_LAYER; 4673e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4683e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBlending(uint32_t blending) { 4703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = blending; 4713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4723e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setTransform(uint32_t transform) { 4733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = transform; 4743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4753e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setFrame(const Rect& frame) { 4763e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 4773e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4783e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setCrop(const Rect& crop) { 4793e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 4803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setVisibleRegionScreen(const Region& reg) { 4823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = 4833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<hwc_rect_t const *>( 4843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reg.getArray(&getLayer()->visibleRegionScreen.numRects)); 4853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 4873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (buffer == 0 || buffer->handle == 0) { 4883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = 0; 4913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = buffer->handle; 4933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 4963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 4983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator initialized at a given index in the layer list 4993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::getLayerIterator(size_t index) { 5013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (!mList || index > mList->numHwLayers) { 5023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return LayerListIterator(); 5033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 5045880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 5055880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return LayerListIterator(new HWCLayerVersion1(mList->hwLayers), index); 5065880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 5075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list0 = (hwc_layer_list_t*)mList; 5085880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return LayerListIterator(new HWCLayerVersion0(list0->hwLayers), index); 5095880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 5103e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5113e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the beginning of the layer list 5143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::begin() { 5163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayerIterator(0); 517a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 518a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 5193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5203e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the end of the layer list 5213e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::end() { 5233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayerIterator(getNumLayers()); 5243e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5253e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5263e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5273e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 52822da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 52922da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 5308372785879d329f592f6883620b5a32d80d74691Mathias Agopian if (mHwc && mList) { 5318372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append("Hardware Composer state:\n"); 532e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat(" mDebugForceFakeVSync=%d\n", 533e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync); 534e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat(" numHwLayers=%u, flags=%08x\n", 5358372785879d329f592f6883620b5a32d80d74691Mathias Agopian mList->numHwLayers, mList->flags); 536fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian result.append( 537aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " type | handle | hints | flags | tr | blend | format | source crop | frame name \n" 538aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian "----------+----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 539aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian // " ________ | ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 5408372785879d329f592f6883620b5a32d80d74691Mathias Agopian for (size_t i=0 ; i<mList->numHwLayers ; i++) { 5415880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_1_t l; 5425880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 5435880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = mList->hwLayers[i]; 5445880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 5455880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list0 = (hwc_layer_list_t*)mList; 5465880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall *(hwc_layer_t*)&l = list0->hwLayers[i]; 5475880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l.acquireFenceFd = l.releaseFenceFd = -1; 5485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 549fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<LayerBase> layer(visibleLayersSortedByZ[i]); 550fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian int32_t format = -1; 551fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (layer->getLayer() != NULL) { 552fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<GraphicBuffer>& buffer(layer->getLayer()->getActiveBuffer()); 553fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (buffer != NULL) { 554fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian format = buffer->getPixelFormat(); 555fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 556fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 557e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat( 558aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " %8s | %08x | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 5598372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.compositionType ? "OVERLAY" : "FB", 560aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, format, 5618372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 56222da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 563fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian layer->getName().string()); 5648372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 5651d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 5665880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (mHwc && hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_1) && mHwc->dump) { 5671d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling 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), 5772965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mRefreshPeriod(hwc.mRefreshPeriod) 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