Mathias Agopian | e0d5f5b | 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 | b59beb5 | 2010-08-11 17:31:33 -0700 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
Mathias Agopian | 90da4dd | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 24 | #include <utils/String8.h> |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 25 | |
| 26 | #include <hardware/hardware.h> |
| 27 | |
| 28 | #include <cutils/log.h> |
| 29 | |
| 30 | #include <EGL/egl.h> |
| 31 | |
| 32 | #include "HWComposer.h" |
| 33 | |
| 34 | namespace android { |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | HWComposer::HWComposer() |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 38 | : mModule(0), mHwc(0), mList(0), mCapacity(0), |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 39 | mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE) |
| 40 | { |
| 41 | int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); |
| 42 | LOGW_IF(err, "%s module not found", HWC_HARDWARE_MODULE_ID); |
| 43 | if (err == 0) { |
| 44 | err = hwc_open(mModule, &mHwc); |
| 45 | LOGE_IF(err, "%s device failed to initialize (%s)", |
| 46 | HWC_HARDWARE_COMPOSER, strerror(-err)); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | HWComposer::~HWComposer() { |
| 51 | free(mList); |
| 52 | if (mHwc) { |
| 53 | hwc_close(mHwc); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | status_t HWComposer::initCheck() const { |
| 58 | return mHwc ? NO_ERROR : NO_INIT; |
| 59 | } |
| 60 | |
| 61 | void HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { |
| 62 | mDpy = (hwc_display_t)dpy; |
| 63 | mSur = (hwc_surface_t)sur; |
| 64 | } |
| 65 | |
| 66 | status_t HWComposer::createWorkList(size_t numLayers) { |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 67 | if (mHwc) { |
| 68 | if (!mList || mCapacity < numLayers) { |
| 69 | free(mList); |
| 70 | size_t size = sizeof(hwc_layer_list) + numLayers*sizeof(hwc_layer_t); |
| 71 | mList = (hwc_layer_list_t*)malloc(size); |
| 72 | mCapacity = numLayers; |
| 73 | } |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 74 | mList->flags = HWC_GEOMETRY_CHANGED; |
| 75 | mList->numHwLayers = numLayers; |
| 76 | } |
| 77 | return NO_ERROR; |
| 78 | } |
| 79 | |
| 80 | status_t HWComposer::prepare() const { |
| 81 | int err = mHwc->prepare(mHwc, mList); |
| 82 | return (status_t)err; |
| 83 | } |
| 84 | |
| 85 | status_t HWComposer::commit() const { |
| 86 | int err = mHwc->set(mHwc, mDpy, mSur, mList); |
Mathias Agopian | 3e1a18a | 2010-10-07 14:57:04 -0700 | [diff] [blame^] | 87 | if (mList) { |
| 88 | mList->flags &= ~HWC_GEOMETRY_CHANGED; |
| 89 | } |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 90 | return (status_t)err; |
| 91 | } |
| 92 | |
Antti Hatala | 11042a4 | 2010-09-09 02:33:05 -0700 | [diff] [blame] | 93 | status_t HWComposer::release() const { |
| 94 | int err = mHwc->set(mHwc, NULL, NULL, NULL); |
| 95 | return (status_t)err; |
| 96 | } |
| 97 | |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 98 | size_t HWComposer::getNumLayers() const { |
| 99 | return mList ? mList->numHwLayers : 0; |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Mathias Agopian | f8e705d | 2010-08-12 15:03:26 -0700 | [diff] [blame] | 102 | hwc_layer_t* HWComposer::getLayers() const { |
| 103 | return mList ? mList->hwLayers : 0; |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Mathias Agopian | 90da4dd | 2010-09-23 18:13:21 -0700 | [diff] [blame] | 106 | void HWComposer::dump(String8& result, char* buffer, size_t SIZE) const { |
| 107 | if (mHwc && mList) { |
| 108 | result.append("Hardware Composer state:\n"); |
| 109 | |
| 110 | snprintf(buffer, SIZE, " numHwLayers=%u, flags=%08x\n", |
| 111 | mList->numHwLayers, mList->flags); |
| 112 | result.append(buffer); |
| 113 | |
| 114 | for (size_t i=0 ; i<mList->numHwLayers ; i++) { |
| 115 | const hwc_layer_t& l(mList->hwLayers[i]); |
| 116 | snprintf(buffer, SIZE, " %8s | %08x | %08x | %02x | %04x | [%5d,%5d,%5d,%5d] | [%5d,%5d,%5d,%5d]\n", |
| 117 | l.compositionType ? "OVERLAY" : "FB", |
| 118 | l.hints, l.flags, l.transform, l.blending, |
| 119 | l.sourceCrop.left, l.sourceCrop.top, l.sourceCrop.right, l.sourceCrop.bottom, |
| 120 | l.displayFrame.left, l.displayFrame.top, l.displayFrame.right, l.displayFrame.bottom); |
| 121 | result.append(buffer); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 126 | // --------------------------------------------------------------------------- |
| 127 | }; // namespace android |