HWComposer.cpp revision 9c6e297271ec9af9d974242d89cfa08cb6ceaa0a
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 17a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <stdint.h> 18f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdio.h> 19f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <stdlib.h> 20f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian#include <string.h> 21a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <sys/types.h> 22a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 23a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <utils/Errors.h> 248372785879d329f592f6883620b5a32d80d74691Mathias Agopian#include <utils/String8.h> 2522da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h> 26a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 27a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h> 28a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 29a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h> 30a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 31a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h> 32a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 3322da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include "LayerBase.h" 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h" 35c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include "SurfaceFlinger.h" 36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 38a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 40c7d14e247117392fbd44aa454622778a25c076aeMathias AgopianHWComposer::HWComposer(const sp<SurfaceFlinger>& flinger) 41c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian : mFlinger(flinger), 42c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mModule(0), mHwc(0), mList(0), mCapacity(0), 439c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers(0), mNumFBLayers(0), 44a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE) 45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 46a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); 47a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); 48a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (err == 0) { 49a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian err = hwc_open(mModule, &mHwc); 50a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian LOGE_IF(err, "%s device failed to initialize (%s)", 51a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian HWC_HARDWARE_COMPOSER, strerror(-err)); 52c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (err == 0) { 53c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian if (mHwc->registerProcs) { 54c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mCBContext.hwc = this; 55c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mCBContext.procs.invalidate = &hook_invalidate; 56c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mHwc->registerProcs(mHwc, &mCBContext.procs); 57c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 58c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian } 59a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 60a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 61a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 62a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() { 63a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian free(mList); 64a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if (mHwc) { 65a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_close(mHwc); 66a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 67a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 68a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 69a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const { 70a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return mHwc ? NO_ERROR : NO_INIT; 71a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 72a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 73c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::hook_invalidate(struct hwc_procs* procs) { 74c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian reinterpret_cast<cb_context *>(procs)->hwc->invalidate(); 75c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 76c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 77c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid HWComposer::invalidate() { 78c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian mFlinger->signalEvent(); 79c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian} 80c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 81a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianvoid HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { 82a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mDpy = (hwc_display_t)dpy; 83a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mSur = (hwc_surface_t)sur; 84a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 85a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 86a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::createWorkList(size_t numLayers) { 8745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (mHwc) { 8845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian if (!mList || mCapacity < numLayers) { 8945721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian free(mList); 9045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t); 9145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mList = (hwc_layer_list_t*)malloc(size); 9245721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian mCapacity = numLayers; 9345721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian } 94a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->flags = HWC_GEOMETRY_CHANGED; 95a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian mList->numHwLayers = numLayers; 96a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 97a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return NO_ERROR; 98a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 99a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 100a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::prepare() const { 101a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->prepare(mHwc, mList); 1029c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (err == NO_ERROR) { 1039c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numOVLayers = 0; 1049c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t numFBLayers = 0; 1059c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t count = mList->numHwLayers; 1069c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian for (size_t i=0 ; i<count ; i++) { 1079c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian hwc_layer& l(mList->hwLayers[i]); 1089c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian if (l.flags & HWC_SKIP_LAYER) { 1099c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian l.compositionType = HWC_FRAMEBUFFER; 1109c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1119c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (l.compositionType) { 1129c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 1139c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numOVLayers++; 1149c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 1159c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 1169c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian numFBLayers++; 1179c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian break; 1189c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1199c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1209c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumOVLayers = numOVLayers; 1219c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mNumFBLayers = numFBLayers; 1229c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 123a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 124a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 125a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 1269c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopiansize_t HWComposer::getLayerCount(int type) const { 1279c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian switch (type) { 1289c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_OVERLAY: 1299c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumOVLayers; 1309c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian case HWC_FRAMEBUFFER: 1319c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return mNumFBLayers; 1329c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian } 1339c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian return 0; 1349c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian} 1359c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 136a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::commit() const { 137a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian int err = mHwc->set(mHwc, mDpy, mSur, mList); 13858959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian if (mList) { 13958959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian mList->flags &= ~HWC_GEOMETRY_CHANGED; 14058959343dbdb6157fa5f5463262d4842b8954353Mathias Agopian } 141a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return (status_t)err; 142a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 143a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 144f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const { 1457ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 1467ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->set(mHwc, NULL, NULL, NULL); 1477ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 1487ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 1497ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 1507ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian} 1517ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 1527ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopianstatus_t HWComposer::disable() { 1537ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian if (mHwc) { 1547ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian free(mList); 1557ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian mList = NULL; 1567ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian int err = mHwc->prepare(mHwc, NULL); 1577ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return (status_t)err; 1587ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian } 1597ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian return NO_ERROR; 160f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala} 161f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala 16245721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopiansize_t HWComposer::getNumLayers() const { 16345721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->numHwLayers : 0; 164a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 165a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 16645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopianhwc_layer_t* HWComposer::getLayers() const { 16745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian return mList ? mList->hwLayers : 0; 168a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 169a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 17022da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE, 17122da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const { 1728372785879d329f592f6883620b5a32d80d74691Mathias Agopian if (mHwc && mList) { 1738372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append("Hardware Composer state:\n"); 1748372785879d329f592f6883620b5a32d80d74691Mathias Agopian 1758372785879d329f592f6883620b5a32d80d74691Mathias Agopian snprintf(buffer, SIZE, " numHwLayers=%u, flags=%08x\n", 1768372785879d329f592f6883620b5a32d80d74691Mathias Agopian mList->numHwLayers, mList->flags); 1778372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append(buffer); 178fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian result.append( 179fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian " type | hints | flags | tr | blend | format | source rectangle | crop rectangle name \n" 180fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian "-----------+----------+----------+----+-------+----------+---------------------------+--------------------------------\n"); 181fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian // " ________ | ________ | ________ | __ | _____ | ________ | [_____,_____,_____,_____] | [_____,_____,_____,_____] 1828372785879d329f592f6883620b5a32d80d74691Mathias Agopian for (size_t i=0 ; i<mList->numHwLayers ; i++) { 1838372785879d329f592f6883620b5a32d80d74691Mathias Agopian const hwc_layer_t& l(mList->hwLayers[i]); 184fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<LayerBase> layer(visibleLayersSortedByZ[i]); 185fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian int32_t format = -1; 186fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (layer->getLayer() != NULL) { 187fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian const sp<GraphicBuffer>& buffer(layer->getLayer()->getActiveBuffer()); 188fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian if (buffer != NULL) { 189fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian format = buffer->getPixelFormat(); 190fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 191fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian } 192fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian snprintf(buffer, SIZE, 193fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian " %8s | %08x | %08x | %02x | %05x | %08x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d] %s\n", 1948372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.compositionType ? "OVERLAY" : "FB", 195fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian l.hints, l.flags, l.transform, l.blending, format, 1968372785879d329f592f6883620b5a32d80d74691Mathias Agopian l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, 19722da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom, 198fb4d5d5726c172adbe62341d99a2148685a98379Mathias Agopian layer->getName().string()); 1998372785879d329f592f6883620b5a32d80d74691Mathias Agopian result.append(buffer); 2008372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 2011d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling } 2021d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling if (mHwc && mHwc->common.version >= 1 && mHwc->dump) { 2031d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling mHwc->dump(mHwc, buffer, SIZE); 2041d21a9cafc534c34a2f28c985c4c7aa176d0e67bErik Gilling result.append(buffer); 2058372785879d329f592f6883620b5a32d80d74691Mathias Agopian } 2068372785879d329f592f6883620b5a32d80d74691Mathias Agopian} 2078372785879d329f592f6883620b5a32d80d74691Mathias Agopian 208a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 209a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 210