HWComposer.cpp revision 8372785879d329f592f6883620b5a32d80d74691
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>
25a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
26a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hardware.h>
27a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
28a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <cutils/log.h>
29a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
30a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h>
31a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
32a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include "HWComposer.h"
33a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android {
35a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// ---------------------------------------------------------------------------
36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::HWComposer()
3845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian    : mModule(0), mHwc(0), mList(0), mCapacity(0),
39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian      mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE)
40a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{
41a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule);
42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID);
43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    if (err == 0) {
44a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian        err = hwc_open(mModule, &mHwc);
45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian        LOGE_IF(err, "%s device failed to initialize (%s)",
46a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian                HWC_HARDWARE_COMPOSER, strerror(-err));
47a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    }
48a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
49a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
50a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianHWComposer::~HWComposer() {
51a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    free(mList);
52a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    if (mHwc) {
53a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian        hwc_close(mHwc);
54a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    }
55a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
56a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
57a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::initCheck() const {
58a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    return mHwc ? NO_ERROR : NO_INIT;
59a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
60a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
61a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianvoid HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) {
62a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    mDpy = (hwc_display_t)dpy;
63a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    mSur = (hwc_surface_t)sur;
64a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
65a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
66a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::createWorkList(size_t numLayers) {
6745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian    if (mHwc) {
6845721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian        if (!mList || mCapacity < numLayers) {
6945721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian            free(mList);
7045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian            size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t);
7145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian            mList = (hwc_layer_list_t*)malloc(size);
7245721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian            mCapacity = numLayers;
7345721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian        }
74a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian        mList->flags = HWC_GEOMETRY_CHANGED;
75a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian        mList->numHwLayers = numLayers;
76a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    }
77a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    return NO_ERROR;
78a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
79a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
80a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::prepare() const {
81a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    int err = mHwc->prepare(mHwc, mList);
82a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    return (status_t)err;
83a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
84a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
85a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianstatus_t HWComposer::commit() const {
86a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    int err = mHwc->set(mHwc, mDpy, mSur, mList);
87a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    mList->flags &= ~HWC_GEOMETRY_CHANGED;
88a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    return (status_t)err;
89a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
90a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
91f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatalastatus_t HWComposer::release() const {
92f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala    int err = mHwc->set(mHwc, NULL, NULL, NULL);
93f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala    return (status_t)err;
94f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala}
95f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala
9645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopiansize_t HWComposer::getNumLayers() const {
9745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian    return mList ? mList->numHwLayers : 0;
98a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
99a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
10045721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopianhwc_layer_t* HWComposer::getLayers() const {
10145721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian    return mList ? mList->hwLayers : 0;
102a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}
103a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
1048372785879d329f592f6883620b5a32d80d74691Mathias Agopianvoid HWComposer::dump(String8& result, char* buffer, size_t SIZE) const {
1058372785879d329f592f6883620b5a32d80d74691Mathias Agopian    if (mHwc && mList) {
1068372785879d329f592f6883620b5a32d80d74691Mathias Agopian        result.append("Hardware Composer state:\n");
1078372785879d329f592f6883620b5a32d80d74691Mathias Agopian
1088372785879d329f592f6883620b5a32d80d74691Mathias Agopian        snprintf(buffer, SIZE, "  numHwLayers=%u, flags=%08x\n",
1098372785879d329f592f6883620b5a32d80d74691Mathias Agopian                mList->numHwLayers, mList->flags);
1108372785879d329f592f6883620b5a32d80d74691Mathias Agopian        result.append(buffer);
1118372785879d329f592f6883620b5a32d80d74691Mathias Agopian
1128372785879d329f592f6883620b5a32d80d74691Mathias Agopian        for (size_t i=0 ; i<mList->numHwLayers ; i++) {
1138372785879d329f592f6883620b5a32d80d74691Mathias Agopian            const hwc_layer_t& l(mList->hwLayers[i]);
1148372785879d329f592f6883620b5a32d80d74691Mathias Agopian            snprintf(buffer, SIZE, "  %8s | %08x | %08x | %02x | %04x | [%5d,%5d,%5d,%5d] |  [%5d,%5d,%5d,%5d]\n",
1158372785879d329f592f6883620b5a32d80d74691Mathias Agopian                    l.compositionType ? "OVERLAY" : "FB",
1168372785879d329f592f6883620b5a32d80d74691Mathias Agopian                    l.hints, l.flags, l.transform, l.blending,
1178372785879d329f592f6883620b5a32d80d74691Mathias Agopian                    l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom,
1188372785879d329f592f6883620b5a32d80d74691Mathias Agopian                    l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom);
1198372785879d329f592f6883620b5a32d80d74691Mathias Agopian            result.append(buffer);
1208372785879d329f592f6883620b5a32d80d74691Mathias Agopian        }
1218372785879d329f592f6883620b5a32d80d74691Mathias Agopian    }
1228372785879d329f592f6883620b5a32d80d74691Mathias Agopian}
1238372785879d329f592f6883620b5a32d80d74691Mathias Agopian
124a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// ---------------------------------------------------------------------------
125a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android
126