HWComposer.cpp revision 028508cad5ef63ef9fbd42c14e76658e4fd9ebf2
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 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 42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h> 43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 44921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include "Layer.h" // needed only for debugging 4522da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 46a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 47c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 48a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 49a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 515880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// --------------------------------------------------------------------------- 525880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// Support for HWC_DEVICE_API_VERSION_0_3 and older: 535880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// Since v0.3 is deprecated and support will be dropped soon, as much as 545880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// possible the code is written to target v1.0. When using a v0.3 HWC, we 555880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// allocate v0.3 structures, but assign them to v1.0 pointers. Fields that 565880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// exist in both versions are located at the same offset, so in most cases we 575880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// can just use the v1.0 pointer without branches or casts. 585880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 595880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall#if HWC_REMOVE_DEPRECATED_VERSIONS 605880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// We need complete types with to satisfy semantic checks, even though the 615880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// code paths that use these won't get executed at runtime (and will likely be 625880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// dead-code-eliminated). When we remove the code to support v0.3 we can remove 635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// these as well. 645880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_layer_1_t hwc_layer_t; 655880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_layer_list_1_t hwc_layer_list_t; 665880cc573823148237eac9ab7bc586b8e4eb7160Jesse Halltypedef hwc_composer_device_1_t hwc_composer_device_t; 675880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall#endif 685880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// This function assumes we've already rejected HWC's with lower-than-required 705880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// versions. Don't use it for the initial "does HWC meet requirements" check! 715880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallstatic bool hwcHasVersion(const hwc_composer_device_1_t* hwc, uint32_t version) { 725880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (HWC_REMOVE_DEPRECATED_VERSIONS && 735880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall version <= HWC_DEVICE_API_VERSION_1_0) { 745880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return true; 755880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 765880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return hwc->common.version >= version; 775880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 785880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall} 795880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 805880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallstatic size_t sizeofHwcLayerList(const hwc_composer_device_1_t* hwc, 815880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall size_t numLayers) { 825880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(hwc, HWC_DEVICE_API_VERSION_1_0)) { 835880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return sizeof(hwc_layer_list_1_t) + numLayers*sizeof(hwc_layer_1_t); 845880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 855880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return sizeof(hwc_layer_list_t) + numLayers*sizeof(hwc_layer_t); 865880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 875880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall} 885880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 89a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 90a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianstruct HWComposer::cb_context { 923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian struct callbacks : public hwc_procs_t { 933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // these are here to facilitate the transition when adding 943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // new callbacks (an implementation can check for NULL before 953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // calling a new callback). 963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian void (*zero[4])(void); 973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian }; 983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian callbacks procs; 993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWComposer* hwc; 1003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 1013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 1023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian// --------------------------------------------------------------------------- 1033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 1043eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias AgopianHWComposer::HWComposer( 1053eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const sp<SurfaceFlinger>& flinger, 1063eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EventHandler& handler, 1073eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian nsecs_t refreshPeriod) 108c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 109c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mModule(0), mHwc(0), mList(0), mCapacity(0), 1109c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers(0), mNumFBLayers(0), 1113eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE), 1123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext(new cb_context), 1133eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler(handler), 114e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mRefreshPeriod(refreshPeriod), 115e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mVSyncCount(0), mDebugForceFakeVSync(false) 116a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 117e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian char value[PROPERTY_VALUE_MAX]; 118e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian property_get("debug.sf.no_hw_vsync", value, "0"); 119e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync = atoi(value); 120e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian 121028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian bool needVSyncThread = true; 122a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); 12332397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); 124a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (err == 0) { 1255880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall err = hwc_open_1(mModule, &mHwc); 126e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(err, "%s device failed to initialize (%s)", 127a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian HWC_HARDWARE_COMPOSER, strerror(-err)); 128c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (err == 0) { 1295880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (HWC_REMOVE_DEPRECATED_VERSIONS && 1305880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mHwc->common.version < HWC_DEVICE_API_VERSION_1_0) { 1315880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall ALOGE("%s device version %#x too old, will not be used", 1325880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWC_HARDWARE_COMPOSER, mHwc->common.version); 1335880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 1345880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mHwc = NULL; 1355880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1365880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 1375880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 1385880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (mHwc) { 139028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { 140028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian // always turn vsync off when we start 141028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); 142028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian needVSyncThread = false; 143028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian } 144c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (mHwc->registerProcs) { 1453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->hwc = this; 1463e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->procs.invalidate = &hook_invalidate; 1473e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCBContext->procs.vsync = &hook_vsync; 1483e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mHwc->registerProcs(mHwc, &mCBContext->procs); 1493e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian memset(mCBContext->procs.zero, 0, sizeof(mCBContext->procs.zero)); 150c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 151c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 1523a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 1533a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 1543a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (needVSyncThread) { 1553a77871383bc1a03cc866686d81628493d14de7cMathias Agopian // we don't have VSYNC support, we need to fake it 1563a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread = new VSyncThread(*this); 157a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 158a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 159a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 160a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 161e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian eventControl(EVENT_VSYNC, 0); 162a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian free(mList); 1633eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mVSyncThread != NULL) { 1643eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mVSyncThread->requestExitAndWait(); 1653eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 166a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 1675880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_close_1(mHwc); 168a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 1693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian delete mCBContext; 170a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 171a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 172a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 173a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 174a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 175a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 176c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::hook_invalidate(struct hwc_procs* procs) { 177c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->invalidate(); 178c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 179c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 18031d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::hook_vsync(struct hwc_procs* procs, int dpy, int64_t timestamp) { 18131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->vsync(dpy, timestamp); 18231d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 18331d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 184c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 185e2c2f9213f936f98db604dc9c126ff22f725a824Mathias Agopian mFlinger->repaintEverything(); 186c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 187c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 18831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::vsync(int dpy, int64_t timestamp) { 1892965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian ATRACE_INT("VSYNC", ++mVSyncCount&1); 1903eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler.onVSyncReceived(dpy, timestamp); 1913eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian} 1923eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 19303e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopianvoid HWComposer::eventControl(int event, int enabled) { 1943eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t err = NO_ERROR; 1951a3bf41b7165ba294af46bc32483eaad61e707eaErik Gilling if (mHwc && mHwc->common.version >= HWC_DEVICE_API_VERSION_0_3) { 196e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian if (!mDebugForceFakeVSync) { 197e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian err = mHwc->methods->eventControl(mHwc, event, enabled); 19803e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // error here should not happen -- not sure what we should 19903e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian // do if it does. 20003e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian ALOGE_IF(err, "eventControl(%d, %d) failed %s", 20103e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian event, enabled, strerror(-err)); 202e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 2033eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 2043a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 2053a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (err == NO_ERROR && mVSyncThread != NULL) { 2063a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread->setEnabled(enabled); 2073a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 20831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 20931d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 210a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianvoid HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { 211a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mDpy = (hwc_display_t)dpy; 212a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mSur = (hwc_surface_t)sur; 213a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 214a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 215a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::createWorkList(size_t numLayers) { 21645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 21745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (!mList || mCapacity < numLayers) { 21845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian free(mList); 2195880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall size_t size = sizeofHwcLayerList(mHwc, numLayers); 2205880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall mList = (hwc_layer_list_1_t*)malloc(size); 22145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mCapacity = numLayers; 22245721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 223a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->flags = HWC_GEOMETRY_CHANGED; 224a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->numHwLayers = numLayers; 225a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 226a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 227a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 228a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 229a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::prepare() const { 230a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->prepare(mHwc, mList); 2319c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 2329c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numOVLayers = 0; 2339c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numFBLayers = 0; 2349c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t count = mList->numHwLayers; 2359c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian for (size_t i=0 ; i<count ; i++) { 2365880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_1_t* l = NULL; 2375880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 2385880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = &mList->hwLayers[i]; 2395880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 2405880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall // mList really has hwc_layer_list_t memory layout 2415880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list = (hwc_layer_list_t*)mList; 2425880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_t* layer = &list->hwLayers[i]; 2435880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = (hwc_layer_1_t*)layer; 2449c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2455880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (l->flags & HWC_SKIP_LAYER) { 2465880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l->compositionType = HWC_FRAMEBUFFER; 2475880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 2485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall switch (l->compositionType) { 2499c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 2509c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numOVLayers++; 2519c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 2529c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 2539c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numFBLayers++; 2549c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 2559c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2569c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2579c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers = numOVLayers; 2589c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumFBLayers = numFBLayers; 2599c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 260a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 261a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 262a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 2639c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopiansize_t HWComposer::getLayerCount(int type) const { 2649c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (type) { 2659c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 2669c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumOVLayers; 2679c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 2689c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumFBLayers; 2699c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 2709c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return 0; 2719c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 2729c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 273a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::commit() const { 2748630320433bd15aca239522e54e711ef6372ab07Mathias Agopian int err = NO_ERROR; 2758630320433bd15aca239522e54e711ef6372ab07Mathias Agopian if (mHwc) { 2768630320433bd15aca239522e54e711ef6372ab07Mathias Agopian err = mHwc->set(mHwc, mDpy, mSur, mList); 2778630320433bd15aca239522e54e711ef6372ab07Mathias Agopian if (mList) { 2788630320433bd15aca239522e54e711ef6372ab07Mathias Agopian mList->flags &= ~HWC_GEOMETRY_CHANGED; 2798630320433bd15aca239522e54e711ef6372ab07Mathias Agopian } 2808630320433bd15aca239522e54e711ef6372ab07Mathias Agopian } else { 2818630320433bd15aca239522e54e711ef6372ab07Mathias Agopian eglSwapBuffers(mDpy, mSur); 28258959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 283a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 284a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 285a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 286f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const { 2877ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 2885880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_3)) { 28922ffb117b0c2a906bd04aef9738a52223cdd1dceMathias Agopian mHwc->methods->eventControl(mHwc, HWC_EVENT_VSYNC, 0); 29022ffb117b0c2a906bd04aef9738a52223cdd1dceMathias Agopian } 2917ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->set(mHwc, NULL, NULL, NULL); 29210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (err < 0) { 29310fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return (status_t)err; 29410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 29510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 29610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 29710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc->methods && mHwc->methods->blank) { 29810fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross err = mHwc->methods->blank(mHwc, 1); 29910fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 30010fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 3017ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 3027ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 3037ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 3047ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 3057ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 30610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Crossstatus_t HWComposer::acquire() const { 30710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc) { 30810fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 30910fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross if (mHwc->methods && mHwc->methods->blank) { 31010fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross int err = mHwc->methods->blank(mHwc, 0); 31110fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return (status_t)err; 31210fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31310fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross } 31510fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 31610fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross return NO_ERROR; 31710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross} 31810fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross 3197ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopianstatus_t HWComposer::disable() { 3207ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 3217ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian free(mList); 3227ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian mList = NULL; 3237ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->prepare(mHwc, NULL); 3247ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 3257ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 3267ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 327f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala} 328f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala 32945721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopiansize_t HWComposer::getNumLayers() const { 33045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->numHwLayers : 0; 331a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 332a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 3333e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 3343e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Helper template to implement a concrete HWCLayer 3353e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This holds the pointer to the concrete hwc layer type 3363e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * and implements the "iterable" side of HWCLayer. 3373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 3383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopiantemplate<typename CONCRETE, typename HWCTYPE> 3393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianclass Iterable : public HWComposer::HWCLayer { 3403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprotected: 3413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* const mLayerList; 3423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian HWCTYPE* mCurrentLayer; 3433e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian Iterable(HWCTYPE* layer) : mLayerList(layer), mCurrentLayer(layer) { } 3443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE const * getLayer() const { return mCurrentLayer; } 3453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian inline HWCTYPE* getLayer() { return mCurrentLayer; } 3463e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual ~Iterable() { } 3473e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianprivate: 3483e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian // returns a copy of ourselves 3493e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual HWComposer::HWCLayer* dup() { 3503e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return new CONCRETE( static_cast<const CONCRETE&>(*this) ); 3513e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 3523e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual status_t setLayer(size_t index) { 3533e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mCurrentLayer = &mLayerList[index]; 3543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return NO_ERROR; 3553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 3563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 3573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 3585880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// #if !HWC_REMOVE_DEPRECATED_VERSIONS 3593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 3603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_0_3 3613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * This implements the HWCLayer side of HWCIterableLayer. 3623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 3635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion0 : public Iterable<HWCLayerVersion0, hwc_layer_t> { 3645880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallpublic: 3655880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion0(hwc_layer_t* layer) 3665880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion0, hwc_layer_t>(layer) { } 3675880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 3685880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual int32_t getCompositionType() const { 3695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return getLayer()->compositionType; 3705880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3715880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual uint32_t getHints() const { 3725880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return getLayer()->hints; 3735880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 374ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 375ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall // not supported on VERSION_03 376ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return -1; 377ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 378dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 379dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall if (fenceFd != -1) { 380dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall ALOGE("HWC 0.x can't handle acquire fences"); 381dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall close(fenceFd); 382dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 383dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 3845880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 3855880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setDefaultState() { 3865880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->compositionType = HWC_FRAMEBUFFER; 3875880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->hints = 0; 3885880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags = HWC_SKIP_LAYER; 3895880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->transform = 0; 3905880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->blending = HWC_BLENDING_NONE; 3915880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.numRects = 0; 3925880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.rects = NULL; 3935880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 3945880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setSkip(bool skip) { 3955880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (skip) { 3965880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags |= HWC_SKIP_LAYER; 3975880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 3985880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags &= ~HWC_SKIP_LAYER; 3995880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4005880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4015880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setBlending(uint32_t blending) { 4025880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->blending = blending; 4035880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4045880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setTransform(uint32_t transform) { 4055880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->transform = transform; 4065880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setFrame(const Rect& frame) { 4085880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 4095880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4105880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setCrop(const Rect& crop) { 4115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 4125880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4135880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setVisibleRegionScreen(const Region& reg) { 4145880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->visibleRegionScreen.rects = 4155880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reinterpret_cast<hwc_rect_t const *>( 4165880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall reg.getArray(&getLayer()->visibleRegionScreen.numRects)); 4175880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4185880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 4195880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (buffer == 0 || buffer->handle == 0) { 4205880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->compositionType = HWC_FRAMEBUFFER; 4215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->flags |= HWC_SKIP_LAYER; 4225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->handle = 0; 4235880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 4245880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->handle = buffer->handle; 4255880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4265880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 4275880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall}; 4285880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall// #endif // !HWC_REMOVE_DEPRECATED_VERSIONS 4295880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall 4305880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall/* 4315880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * Concrete implementation of HWCLayer for HWC_DEVICE_API_VERSION_1_0. 4325880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall * This implements the HWCLayer side of HWCIterableLayer. 4335880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall */ 4345880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallclass HWCLayerVersion1 : public Iterable<HWCLayerVersion1, hwc_layer_1_t> { 4353e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianpublic: 4365880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall HWCLayerVersion1(hwc_layer_1_t* layer) 4375880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall : Iterable<HWCLayerVersion1, hwc_layer_1_t>(layer) { } 4383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual int32_t getCompositionType() const { 4403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->compositionType; 4413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual uint32_t getHints() const { 4433e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayer()->hints; 4443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 445ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall virtual int getAndResetReleaseFenceFd() { 446ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall int fd = getLayer()->releaseFenceFd; 447ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall getLayer()->releaseFenceFd = -1; 448ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall return fd; 449ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall } 450dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall virtual void setAcquireFenceFd(int fenceFd) { 451dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall getLayer()->acquireFenceFd = fenceFd; 452dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall } 4533e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 4543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setDefaultState() { 4553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->hints = 0; 4573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags = HWC_SKIP_LAYER; 4583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = 0; 4593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = HWC_BLENDING_NONE; 4603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.numRects = 0; 4613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = NULL; 4625880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->acquireFenceFd = -1; 4635880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall getLayer()->releaseFenceFd = -1; 4643e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4653e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setSkip(bool skip) { 4663e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (skip) { 4673e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4683e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags &= ~HWC_SKIP_LAYER; 4703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4723e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBlending(uint32_t blending) { 4733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->blending = blending; 4743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4753e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setTransform(uint32_t transform) { 4763e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->transform = transform; 4773e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4783e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setFrame(const Rect& frame) { 4793e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->displayFrame) = frame; 4803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setCrop(const Rect& crop) { 4823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<Rect&>(getLayer()->sourceCrop) = crop; 4833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setVisibleRegionScreen(const Region& reg) { 4853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->visibleRegionScreen.rects = 4863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reinterpret_cast<hwc_rect_t const *>( 4873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian reg.getArray(&getLayer()->visibleRegionScreen.numRects)); 4883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian virtual void setBuffer(const sp<GraphicBuffer>& buffer) { 4903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (buffer == 0 || buffer->handle == 0) { 4913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->compositionType = HWC_FRAMEBUFFER; 4923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->flags |= HWC_SKIP_LAYER; 4933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = 0; 4943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } else { 4953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian getLayer()->handle = buffer->handle; 4963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 4983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian}; 4993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator initialized at a given index in the layer list 5023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::getLayerIterator(size_t index) { 5043e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (!mList || index > mList->numHwLayers) { 5053e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return LayerListIterator(); 5063e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 5075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 5085880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return LayerListIterator(new HWCLayerVersion1(mList->hwLayers), index); 5095880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 5105880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list0 = (hwc_layer_list_t*)mList; 5115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall return LayerListIterator(new HWCLayerVersion0(list0->hwLayers), index); 5125880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 5133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the beginning of the layer list 5173e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5183e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::begin() { 5193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayerIterator(0); 520a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 521a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 5223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian/* 5233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian * returns an iterator on the end of the layer list 5243e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian */ 5253e8b853d67c737abdb363f9c978e7d83eac4d888Mathias AgopianHWComposer::LayerListIterator HWComposer::end() { 5263e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return getLayerIterator(getNumLayers()); 5273e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 5283e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5293e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 5303e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 53122da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 53222da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 5338372785879d329f592f6883620b5a32d80d74691Mathias Agopian if (mHwc && mList) { 5348372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append("Hardware Composer state:\n"); 535e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat(" mDebugForceFakeVSync=%d\n", 536e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian mDebugForceFakeVSync); 537e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat(" numHwLayers=%u, flags=%08x\n", 5388372785879d329f592f6883620b5a32d80d74691Mathias Agopian mList->numHwLayers, mList->flags); 539fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian result.append( 540aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " type | handle | hints | flags | tr | blend | format | source crop | frame name \n" 541aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian "----------+----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 542aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian // " ________ | ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 5438372785879d329f592f6883620b5a32d80d74691Mathias Agopian for (size_t i=0 ; i<mList->numHwLayers ; i++) { 5445880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_1_t l; 5455880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_1_0)) { 5465880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l = mList->hwLayers[i]; 5475880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } else { 5485880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall hwc_layer_list_t* list0 = (hwc_layer_list_t*)mList; 5495880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall *(hwc_layer_t*)&l = list0->hwLayers[i]; 5505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall l.acquireFenceFd = l.releaseFenceFd = -1; 5515880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall } 552fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<LayerBase> layer(visibleLayersSortedByZ[i]); 553fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian int32_t format = -1; 554fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (layer->getLayer() != NULL) { 555fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<GraphicBuffer>& buffer(layer->getLayer()->getActiveBuffer()); 556fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (buffer != NULL) { 557fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian format = buffer->getPixelFormat(); 558fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 559fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 560e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian result.appendFormat( 561aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " %8s | %08x | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 5628372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.compositionType ? "OVERLAY" : "FB", 563aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, format, 5648372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 56522da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 566fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian layer->getName().string()); 5678372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 5681d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 5695880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall if (mHwc && hwcHasVersion(mHwc, HWC_DEVICE_API_VERSION_0_1) && mHwc->dump) { 5701d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling mHwc->dump(mHwc, buffer, SIZE); 5711d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling result.append(buffer); 5728372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 5738372785879d329f592f6883620b5a32d80d74691Mathias Agopian} 5748372785879d329f592f6883620b5a32d80d74691Mathias Agopian 575a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 5762965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5772965b26022f95051f65b09d7eac47cbe923855c9Mathias AgopianHWComposer::VSyncThread::VSyncThread(HWComposer& hwc) 5782965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian : mHwc(hwc), mEnabled(false), 5792965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync(0), 5802965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mRefreshPeriod(hwc.mRefreshPeriod) 5812965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian{ 5822965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5832965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5842965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::setEnabled(bool enabled) { 5852965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 5862965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mEnabled = enabled; 5872965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.signal(); 5882965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5892965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5902965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::onFirstRef() { 5912965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian run("VSyncThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); 5922965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 5932965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 5942965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianbool HWComposer::VSyncThread::threadLoop() { 5952965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian { // scope for lock 5962965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 5972965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian while (!mEnabled) { 5982965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.wait(mLock); 5992965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6002965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6012965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6022965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t period = mRefreshPeriod; 6032965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t now = systemTime(CLOCK_MONOTONIC); 6042965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t next_vsync = mNextFakeVSync; 6052965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t sleep = next_vsync - now; 6062965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (sleep < 0) { 6072965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian // we missed, find where the next vsync should be 6082965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian sleep = (period - ((now - next_vsync) % period)); 6092965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian next_vsync = now + sleep; 6102965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6112965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync = next_vsync + period; 6122965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6132965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian struct timespec spec; 6142965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_sec = next_vsync / 1000000000; 6152965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_nsec = next_vsync % 1000000000; 6162965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6172965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian int err; 6182965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian do { 6192965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); 6202965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } while (err<0 && errno == EINTR); 6212965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6222965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (err == 0) { 6232965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mHwc.mEventHandler.onVSyncReceived(0, next_vsync); 6242965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 6252965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6262965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian return true; 6272965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 6282965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 6292965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian// --------------------------------------------------------------------------- 630a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 631