blob: 129be4e433e24748e1319d92d112e868fee12722 [file] [log] [blame]
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
Mathias Agopianb59beb52010-08-11 17:31:33 -070018#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070021#include <sys/types.h>
22
23#include <utils/Errors.h>
24
25#include <hardware/hardware.h>
26
27#include <cutils/log.h>
28
29#include <EGL/egl.h>
30
31#include "HWComposer.h"
32
33namespace android {
34// ---------------------------------------------------------------------------
35
36HWComposer::HWComposer()
Mathias Agopianf8e705d2010-08-12 15:03:26 -070037 : mModule(0), mHwc(0), mList(0), mCapacity(0),
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070038 mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE)
39{
40 int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule);
41 LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID);
42 if (err == 0) {
43 err = hwc_open(mModule, &mHwc);
44 LOGE_IF(err, "%s device failed to initialize (%s)",
45 HWC_HARDWARE_COMPOSER, strerror(-err));
46 }
47}
48
49HWComposer::~HWComposer() {
50 free(mList);
51 if (mHwc) {
52 hwc_close(mHwc);
53 }
54}
55
56status_t HWComposer::initCheck() const {
57 return mHwc ? NO_ERROR : NO_INIT;
58}
59
60void HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) {
61 mDpy = (hwc_display_t)dpy;
62 mSur = (hwc_surface_t)sur;
63}
64
65status_t HWComposer::createWorkList(size_t numLayers) {
Mathias Agopianf8e705d2010-08-12 15:03:26 -070066 if (mHwc) {
67 if (!mList || mCapacity < numLayers) {
68 free(mList);
69 size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t);
70 mList = (hwc_layer_list_t*)malloc(size);
71 mCapacity = numLayers;
72 }
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070073 mList->flags = HWC_GEOMETRY_CHANGED;
74 mList->numHwLayers = numLayers;
75 }
76 return NO_ERROR;
77}
78
79status_t HWComposer::prepare() const {
80 int err = mHwc->prepare(mHwc, mList);
81 return (status_t)err;
82}
83
84status_t HWComposer::commit() const {
85 int err = mHwc->set(mHwc, mDpy, mSur, mList);
86 mList->flags &= ~HWC_GEOMETRY_CHANGED;
87 return (status_t)err;
88}
89
Antti Hatala11042a42010-09-09 02:33:05 -070090status_t HWComposer::release() const {
91 int err = mHwc->set(mHwc, NULL, NULL, NULL);
92 return (status_t)err;
93}
94
Mathias Agopianf8e705d2010-08-12 15:03:26 -070095size_t HWComposer::getNumLayers() const {
96 return mList ? mList->numHwLayers : 0;
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070097}
98
Mathias Agopianf8e705d2010-08-12 15:03:26 -070099hwc_layer_t* HWComposer::getLayers() const {
100 return mList ? mList->hwLayers : 0;
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700101}
102
103// ---------------------------------------------------------------------------
104}; // namespace android