HWComposer.cpp revision 3a77871383bc1a03cc866686d81628493d14de7c
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 19a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <stdint.h> 20f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdio.h> 21f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdlib.h> 22f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <string.h> 23a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <sys/types.h> 24a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 25a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <utils/Errors.h> 268372785879d329f592f6883620b5a32d80d74691Mathias Agopian#include <utils/String8.h> 273eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <utils/Thread.h> 282965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#include <utils/Trace.h> 2922da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h> 30a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 31a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h> 323eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian#include <hardware/hwcomposer.h> 33a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h> 35a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h> 37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 3822da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 40c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 41a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 44a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 453eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias AgopianHWComposer::HWComposer( 463eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const sp<SurfaceFlinger>& flinger, 473eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EventHandler& handler, 483eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian nsecs_t refreshPeriod) 49c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 50c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mModule(0), mHwc(0), mList(0), mCapacity(0), 519c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers(0), mNumFBLayers(0), 523eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE), 533eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler(handler), 542965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mRefreshPeriod(refreshPeriod), mVSyncCount(0) 55a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 563a77871383bc1a03cc866686d81628493d14de7cMathias Agopian bool needVSyncThread = false; 57a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); 5832397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); 59a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (err == 0) { 60a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian err = hwc_open(mModule, &mHwc); 61e6f43ddce78d6846af12550ff9193c5c6fe5844bSteve Block ALOGE_IF(err, "%s device failed to initialize (%s)", 62a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian HWC_HARDWARE_COMPOSER, strerror(-err)); 63c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (err == 0) { 64c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (mHwc->registerProcs) { 65c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mCBContext.hwc = this; 66c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mCBContext.procs.invalidate = &hook_invalidate; 6731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian mCBContext.procs.vsync = &hook_vsync; 68c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mHwc->registerProcs(mHwc, &mCBContext.procs); 6931d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian memset(mCBContext.procs.zero, 0, sizeof(mCBContext.procs.zero)); 70c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 713eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mHwc->common.version < HWC_DEVICE_API_VERSION_0_3) { 723a77871383bc1a03cc866686d81628493d14de7cMathias Agopian needVSyncThread = true; 733eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 74c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 753a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } else { 763a77871383bc1a03cc866686d81628493d14de7cMathias Agopian needVSyncThread = true; 773a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 783a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 793a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (needVSyncThread) { 803a77871383bc1a03cc866686d81628493d14de7cMathias Agopian // we don't have VSYNC support, we need to fake it 813a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread = new VSyncThread(*this); 82a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 83a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 84a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 85a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 86a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian free(mList); 873eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian if (mVSyncThread != NULL) { 883eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mVSyncThread->requestExitAndWait(); 893eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 90a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 91a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_close(mHwc); 92a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 93a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 94a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 95a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 96a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 97a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 98a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 99c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::hook_invalidate(struct hwc_procs* procs) { 100c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->invalidate(); 101c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 102c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 10331d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::hook_vsync(struct hwc_procs* procs, int dpy, int64_t timestamp) { 10431d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->vsync(dpy, timestamp); 10531d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 10631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 107c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 108e2c2f9213f936f98db604dc9c126ff22f725a824Mathias Agopian mFlinger->repaintEverything(); 109c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 110c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 11131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopianvoid HWComposer::vsync(int dpy, int64_t timestamp) { 1122965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian ATRACE_INT("VSYNC", ++mVSyncCount&1); 1133eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mEventHandler.onVSyncReceived(dpy, timestamp); 1143eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian} 1153eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 1163eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopianstatus_t HWComposer::eventControl(int event, int enabled) { 1173eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t err = NO_ERROR; 1181a3bf41b7165ba294af46bc32483eaad61e707eaErik Gilling if (mHwc && mHwc->common.version >= HWC_DEVICE_API_VERSION_0_3) { 1193eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian err = mHwc->methods->eventControl(mHwc, event, enabled); 1203eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian } 1213a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 1223a77871383bc1a03cc866686d81628493d14de7cMathias Agopian if (err == NO_ERROR && mVSyncThread != NULL) { 1233a77871383bc1a03cc866686d81628493d14de7cMathias Agopian mVSyncThread->setEnabled(enabled); 1243a77871383bc1a03cc866686d81628493d14de7cMathias Agopian } 1253a77871383bc1a03cc866686d81628493d14de7cMathias Agopian 1263eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian return err; 12731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian} 12831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 129a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianvoid HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { 130a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mDpy = (hwc_display_t)dpy; 131a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mSur = (hwc_surface_t)sur; 132a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 133a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 134a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::createWorkList(size_t numLayers) { 13545721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 13645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (!mList || mCapacity < numLayers) { 13745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian free(mList); 13845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t); 13945721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mList = (hwc_layer_list_t*)malloc(size); 14045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mCapacity = numLayers; 14145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 142a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->flags = HWC_GEOMETRY_CHANGED; 143a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->numHwLayers = numLayers; 144a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 145a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 146a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 147a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 148a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::prepare() const { 149a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->prepare(mHwc, mList); 1509c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 1519c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numOVLayers = 0; 1529c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numFBLayers = 0; 1539c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t count = mList->numHwLayers; 1549c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian for (size_t i=0 ; i<count ; i++) { 1559c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian hwc_layer& l(mList->hwLayers[i]); 1569c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (l.flags & HWC_SKIP_LAYER) { 1579c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian l.compositionType = HWC_FRAMEBUFFER; 1589c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1599c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (l.compositionType) { 1609c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 1619c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numOVLayers++; 1629c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 1639c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 1649c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numFBLayers++; 1659c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 1669c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1679c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1689c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers = numOVLayers; 1699c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumFBLayers = numFBLayers; 1709c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 171a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 172a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 173a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 1749c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopiansize_t HWComposer::getLayerCount(int type) const { 1759c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (type) { 1769c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 1779c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumOVLayers; 1789c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 1799c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumFBLayers; 1809c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1819c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return 0; 1829c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 1839c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 184a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::commit() const { 185a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->set(mHwc, mDpy, mSur, mList); 18658959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian if (mList) { 18758959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian mList->flags &= ~HWC_GEOMETRY_CHANGED; 18858959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 189a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 190a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 191a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 192f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const { 1937ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 1947ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->set(mHwc, NULL, NULL, NULL); 1957ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 1967ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 1977ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 1987ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 1997ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 2007ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopianstatus_t HWComposer::disable() { 2017ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 2027ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian free(mList); 2037ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian mList = NULL; 2047ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->prepare(mHwc, NULL); 2057ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 2067ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 2077ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 208f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala} 209f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala 21045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopiansize_t HWComposer::getNumLayers() const { 21145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->numHwLayers : 0; 212a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 213a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 21445721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopianhwc_layer_t* HWComposer::getLayers() const { 21545721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->hwLayers : 0; 216a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 217a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 21822da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 21922da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 2208372785879d329f592f6883620b5a32d80d74691Mathias Agopian if (mHwc && mList) { 2218372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append("Hardware Composer state:\n"); 2228372785879d329f592f6883620b5a32d80d74691Mathias Agopian 2238372785879d329f592f6883620b5a32d80d74691Mathias Agopian snprintf(buffer, SIZE, " numHwLayers=%u, flags=%08x\n", 2248372785879d329f592f6883620b5a32d80d74691Mathias Agopian mList->numHwLayers, mList->flags); 2258372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append(buffer); 226fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian result.append( 227aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " type | handle | hints | flags | tr | blend | format | source crop | frame name \n" 228aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian "----------+----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 229aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian // " ________ | ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 2308372785879d329f592f6883620b5a32d80d74691Mathias Agopian for (size_t i=0 ; i<mList->numHwLayers ; i++) { 2318372785879d329f592f6883620b5a32d80d74691Mathias Agopian const hwc_layer_t& l(mList->hwLayers[i]); 232fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<LayerBase> layer(visibleLayersSortedByZ[i]); 233fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian int32_t format = -1; 234fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (layer->getLayer() != NULL) { 235fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<GraphicBuffer>& buffer(layer->getLayer()->getActiveBuffer()); 236fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (buffer != NULL) { 237fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian format = buffer->getPixelFormat(); 238fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 239fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 240fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian snprintf(buffer, SIZE, 241aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian " %8s | %08x | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 2428372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.compositionType ? "OVERLAY" : "FB", 243aebac5f34a098f733f887c993bd617a393e10db8Mathias Agopian intptr_t(l.handle), l.hints, l.flags, l.transform, l.blending, format, 2448372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 24522da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 246fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian layer->getName().string()); 2478372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append(buffer); 2488372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 2491d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 2501d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling if (mHwc && mHwc->common.version >= 1 && mHwc->dump) { 2511d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling mHwc->dump(mHwc, buffer, SIZE); 2521d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling result.append(buffer); 2538372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 2548372785879d329f592f6883620b5a32d80d74691Mathias Agopian} 2558372785879d329f592f6883620b5a32d80d74691Mathias Agopian 256a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 2572965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2582965b26022f95051f65b09d7eac47cbe923855c9Mathias AgopianHWComposer::VSyncThread::VSyncThread(HWComposer& hwc) 2592965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian : mHwc(hwc), mEnabled(false), 2602965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync(0), 2612965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mRefreshPeriod(hwc.mRefreshPeriod) 2622965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian{ 2632965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 2642965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2652965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::setEnabled(bool enabled) { 2662965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 2672965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mEnabled = enabled; 2682965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.signal(); 2692965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 2702965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2712965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianvoid HWComposer::VSyncThread::onFirstRef() { 2722965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian run("VSyncThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE); 2732965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 2742965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2752965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopianbool HWComposer::VSyncThread::threadLoop() { 2762965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian { // scope for lock 2772965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian Mutex::Autolock _l(mLock); 2782965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian while (!mEnabled) { 2792965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mCondition.wait(mLock); 2802965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 2812965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 2822965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2832965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t period = mRefreshPeriod; 2842965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian const nsecs_t now = systemTime(CLOCK_MONOTONIC); 2852965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t next_vsync = mNextFakeVSync; 2862965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian nsecs_t sleep = next_vsync - now; 2872965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (sleep < 0) { 2882965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian // we missed, find where the next vsync should be 2892965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian sleep = (period - ((now - next_vsync) % period)); 2902965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian next_vsync = now + sleep; 2912965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 2922965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mNextFakeVSync = next_vsync + period; 2932965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2942965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian struct timespec spec; 2952965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_sec = next_vsync / 1000000000; 2962965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian spec.tv_nsec = next_vsync % 1000000000; 2972965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 2982965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian int err; 2992965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian do { 3002965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); 3012965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } while (err<0 && errno == EINTR); 3022965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 3032965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian if (err == 0) { 3042965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian mHwc.mEventHandler.onVSyncReceived(0, next_vsync); 3052965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian } 3062965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 3072965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian return true; 3082965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 3092965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian 3102965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian// --------------------------------------------------------------------------- 311a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 312