blob: b236edc290f5834c801da8d75a89b34bf4c26dc6 [file] [log] [blame]
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08001/*
2 * Copyright (C) 2007 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 <utils/IMemory.h>
18#include <utils/Parcel.h>
The Android Open Source Project27629322009-01-09 17:51:23 -080019#include <utils/Errors.h>
20#include <utils/MemoryHeapBase.h>
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080021
22#include <ui/IOverlay.h>
23#include <ui/Overlay.h>
24
The Android Open Source Project27629322009-01-09 17:51:23 -080025#include <hardware/overlay.h>
26
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080027namespace android {
28
The Android Open Source Project27629322009-01-09 17:51:23 -080029Overlay::Overlay(const sp<OverlayRef>& overlayRef)
30 : mOverlayRef(overlayRef), mOverlayData(0), mStatus(NO_INIT)
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080031{
The Android Open Source Project27629322009-01-09 17:51:23 -080032 mOverlayData = NULL;
33 hw_module_t const* module;
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080034 if (overlayRef != 0) {
35 if (hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module) == 0) {
36 if (overlay_data_open(module, &mOverlayData) == NO_ERROR) {
37 mStatus = mOverlayData->initialize(mOverlayData,
38 overlayRef->mOverlayHandle);
39 }
The Android Open Source Project27629322009-01-09 17:51:23 -080040 }
41 }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080042}
43
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080044Overlay::~Overlay() {
The Android Open Source Project27629322009-01-09 17:51:23 -080045 if (mOverlayData) {
46 overlay_data_close(mOverlayData);
47 }
48}
49
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080050status_t Overlay::dequeueBuffer(overlay_buffer_t* buffer)
The Android Open Source Project27629322009-01-09 17:51:23 -080051{
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080052 if (mStatus != NO_ERROR) return mStatus;
53 return mOverlayData->dequeueBuffer(mOverlayData, buffer);
The Android Open Source Project27629322009-01-09 17:51:23 -080054}
55
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080056status_t Overlay::queueBuffer(overlay_buffer_t buffer)
The Android Open Source Project27629322009-01-09 17:51:23 -080057{
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080058 if (mStatus != NO_ERROR) return mStatus;
The Android Open Source Project27629322009-01-09 17:51:23 -080059 return mOverlayData->queueBuffer(mOverlayData, buffer);
60}
61
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080062int32_t Overlay::getBufferCount() const
63{
64 if (mStatus != NO_ERROR) return mStatus;
65 return mOverlayData->getBufferCount(mOverlayData);
66}
67
The Android Open Source Project27629322009-01-09 17:51:23 -080068void* Overlay::getBufferAddress(overlay_buffer_t buffer)
69{
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080070 if (mStatus != NO_ERROR) return NULL;
The Android Open Source Project27629322009-01-09 17:51:23 -080071 return mOverlayData->getBufferAddress(mOverlayData, buffer);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080072}
73
74void Overlay::destroy() {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080075 if (mStatus != NO_ERROR) return;
76 mOverlayRef->mOverlayChannel->destroy();
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080077}
78
The Android Open Source Project27629322009-01-09 17:51:23 -080079status_t Overlay::getStatus() const {
80 return mStatus;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080081}
82
The Android Open Source Project5f78a482009-01-20 14:03:58 -080083overlay_handle_t Overlay::getHandleRef() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080084 if (mStatus != NO_ERROR) return NULL;
The Android Open Source Project27629322009-01-09 17:51:23 -080085 return mOverlayRef->mOverlayHandle;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080086}
87
88uint32_t Overlay::getWidth() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080089 if (mStatus != NO_ERROR) return 0;
The Android Open Source Project27629322009-01-09 17:51:23 -080090 return mOverlayRef->mWidth;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080091}
92
93uint32_t Overlay::getHeight() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080094 if (mStatus != NO_ERROR) return 0;
The Android Open Source Project27629322009-01-09 17:51:23 -080095 return mOverlayRef->mHeight;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080096}
97
98int32_t Overlay::getFormat() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080099 if (mStatus != NO_ERROR) return -1;
The Android Open Source Project27629322009-01-09 17:51:23 -0800100 return mOverlayRef->mFormat;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800101}
102
103int32_t Overlay::getWidthStride() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -0800104 if (mStatus != NO_ERROR) return 0;
The Android Open Source Project27629322009-01-09 17:51:23 -0800105 return mOverlayRef->mWidthStride;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800106}
107
108int32_t Overlay::getHeightStride() const {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -0800109 if (mStatus != NO_ERROR) return 0;
The Android Open Source Project27629322009-01-09 17:51:23 -0800110 return mOverlayRef->mHeightStride;
111}
112// ----------------------------------------------------------------------------
113
114OverlayRef::OverlayRef()
115 : mOverlayHandle(0),
116 mWidth(0), mHeight(0), mFormat(0), mWidthStride(0), mHeightStride(0),
117 mOwnHandle(true)
118{
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800119}
120
The Android Open Source Project5f78a482009-01-20 14:03:58 -0800121OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel,
The Android Open Source Project27629322009-01-09 17:51:23 -0800122 uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
The Android Open Source Project8a7a6752009-01-15 16:12:10 -0800123 : mOverlayHandle(handle), mOverlayChannel(channel),
The Android Open Source Project27629322009-01-09 17:51:23 -0800124 mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
125 mOwnHandle(false)
126{
127}
128
129OverlayRef::~OverlayRef()
130{
131 if (mOwnHandle) {
132 /* FIXME: handles should be promoted to "real" API and be handled by
133 * the framework */
134 for (int i=0 ; i<mOverlayHandle->numFds ; i++) {
The Android Open Source Project5f78a482009-01-20 14:03:58 -0800135 close(mOverlayHandle->data[i]);
The Android Open Source Project27629322009-01-09 17:51:23 -0800136 }
137 free((void*)mOverlayHandle);
138 }
139}
140
141sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) {
142 sp<OverlayRef> result;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800143 sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
144 if (overlay != NULL) {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800145 uint32_t w = data.readInt32();
146 uint32_t h = data.readInt32();
147 uint32_t f = data.readInt32();
148 uint32_t ws = data.readInt32();
149 uint32_t hs = data.readInt32();
The Android Open Source Project5f78a482009-01-20 14:03:58 -0800150 native_handle* handle = data.readNativeHandle(NULL, NULL);
151
The Android Open Source Project27629322009-01-09 17:51:23 -0800152 result = new OverlayRef();
153 result->mOverlayHandle = handle;
The Android Open Source Project8a7a6752009-01-15 16:12:10 -0800154 result->mOverlayChannel = overlay;
The Android Open Source Project27629322009-01-09 17:51:23 -0800155 result->mWidth = w;
156 result->mHeight = h;
157 result->mFormat = f;
158 result->mWidthStride = ws;
159 result->mHeightStride = hs;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800160 }
161 return result;
162}
163
The Android Open Source Project27629322009-01-09 17:51:23 -0800164status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800165 if (o != NULL) {
The Android Open Source Project8a7a6752009-01-15 16:12:10 -0800166 reply->writeStrongBinder(o->mOverlayChannel->asBinder());
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800167 reply->writeInt32(o->mWidth);
168 reply->writeInt32(o->mHeight);
169 reply->writeInt32(o->mFormat);
170 reply->writeInt32(o->mWidthStride);
171 reply->writeInt32(o->mHeightStride);
The Android Open Source Project5f78a482009-01-20 14:03:58 -0800172 reply->writeNativeHandle(*(o->mOverlayHandle));
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800173 } else {
174 reply->writeStrongBinder(NULL);
175 }
176 return NO_ERROR;
177}
178
179// ----------------------------------------------------------------------------
180
181}; // namespace android