HWComposer.cpp revision f1352df47fe20aed23c216a78923c7d248f2bb91
1/* 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> 18#include <stdio.h> 19#include <stdlib.h> 20#include <string.h> 21#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() 37 : mModule(0), mHwc(0), mList(0), 38 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) { 66 if (mHwc && (!mList || mList->numHwLayers < numLayers)) { 67 free(mList); 68 size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t); 69 mList = (hwc_layer_list_t*)malloc(size); 70 mList->flags = HWC_GEOMETRY_CHANGED; 71 mList->numHwLayers = numLayers; 72 } 73 return NO_ERROR; 74} 75 76status_t HWComposer::prepare() const { 77 int err = mHwc->prepare(mHwc, mList); 78 return (status_t)err; 79} 80 81status_t HWComposer::commit() const { 82 int err = mHwc->set(mHwc, mDpy, mSur, mList); 83 mList->flags &= ~HWC_GEOMETRY_CHANGED; 84 return (status_t)err; 85} 86 87HWComposer::iterator HWComposer::begin() { 88 return mList ? &(mList->hwLayers[0]) : NULL; 89} 90 91HWComposer::iterator HWComposer::end() { 92 return mList ? &(mList->hwLayers[mList->numHwLayers]) : NULL; 93} 94 95// --------------------------------------------------------------------------- 96}; // namespace android 97