Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 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> |
Mathias Agopian | f1352df | 2010-08-11 17:31:33 -0700 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 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 | |
| 33 | namespace android { |
| 34 | // --------------------------------------------------------------------------- |
| 35 | |
| 36 | HWComposer::HWComposer() |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 37 | : mModule(0), mHwc(0), mList(0), mCapacity(0), |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 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 | |
| 49 | HWComposer::~HWComposer() { |
| 50 | free(mList); |
| 51 | if (mHwc) { |
| 52 | hwc_close(mHwc); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | status_t HWComposer::initCheck() const { |
| 57 | return mHwc ? NO_ERROR : NO_INIT; |
| 58 | } |
| 59 | |
| 60 | void HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { |
| 61 | mDpy = (hwc_display_t)dpy; |
| 62 | mSur = (hwc_surface_t)sur; |
| 63 | } |
| 64 | |
| 65 | status_t HWComposer::createWorkList(size_t numLayers) { |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 66 | 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 Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 73 | mList->flags = HWC_GEOMETRY_CHANGED; |
| 74 | mList->numHwLayers = numLayers; |
| 75 | } |
| 76 | return NO_ERROR; |
| 77 | } |
| 78 | |
| 79 | status_t HWComposer::prepare() const { |
| 80 | int err = mHwc->prepare(mHwc, mList); |
| 81 | return (status_t)err; |
| 82 | } |
| 83 | |
| 84 | status_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 Hatala | f5f2712 | 2010-09-09 02:33:05 -0700 | [diff] [blame^] | 90 | status_t HWComposer::release() const { |
| 91 | int err = mHwc->set(mHwc, NULL, NULL, NULL); |
| 92 | return (status_t)err; |
| 93 | } |
| 94 | |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 95 | size_t HWComposer::getNumLayers() const { |
| 96 | return mList ? mList->numHwLayers : 0; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Mathias Agopian | 4572177 | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 99 | hwc_layer_t* HWComposer::getLayers() const { |
| 100 | return mList ? mList->hwLayers : 0; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // --------------------------------------------------------------------------- |
| 104 | }; // namespace android |