blob: b082c534a0fbdb93806359e9de53c0438f831657 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -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
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070017#include <binder/IMemory.h>
18#include <binder/Parcel.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070020#include <binder/MemoryHeapBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
22#include <ui/IOverlay.h>
23#include <ui/Overlay.h>
24
25#include <hardware/overlay.h>
26
27namespace android {
28
29Overlay::Overlay(const sp<OverlayRef>& overlayRef)
30 : mOverlayRef(overlayRef), mOverlayData(0), mStatus(NO_INIT)
31{
32 mOverlayData = NULL;
33 hw_module_t const* module;
34 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 }
40 }
41 }
42}
43
44Overlay::~Overlay() {
45 if (mOverlayData) {
46 overlay_data_close(mOverlayData);
47 }
48}
49
50status_t Overlay::dequeueBuffer(overlay_buffer_t* buffer)
51{
52 if (mStatus != NO_ERROR) return mStatus;
53 return mOverlayData->dequeueBuffer(mOverlayData, buffer);
54}
55
56status_t Overlay::queueBuffer(overlay_buffer_t buffer)
57{
58 if (mStatus != NO_ERROR) return mStatus;
59 return mOverlayData->queueBuffer(mOverlayData, buffer);
60}
61
Benny Wonge5627112009-07-24 19:25:30 -050062status_t Overlay::resizeInput(uint32_t width, uint32_t height)
63{
64 if (mStatus != NO_ERROR) return mStatus;
65 return mOverlayData->resizeInput(mOverlayData, width, height);
66}
67
68status_t Overlay::setParameter(int param, int value)
69{
70 if (mStatus != NO_ERROR) return mStatus;
71 return mOverlayData->setParameter(mOverlayData, param, value);
72}
73
Benny Wong71f77152009-07-15 18:44:27 -050074status_t Overlay::setCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
75{
76 if (mStatus != NO_ERROR) return mStatus;
77 return mOverlayData->setCrop(mOverlayData, x, y, w, h);
78}
79
80status_t Overlay::getCrop(uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h)
81{
82 if (mStatus != NO_ERROR) return mStatus;
83 return mOverlayData->getCrop(mOverlayData, x, y, w, h);
84}
85
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086int32_t Overlay::getBufferCount() const
87{
88 if (mStatus != NO_ERROR) return mStatus;
89 return mOverlayData->getBufferCount(mOverlayData);
90}
91
92void* Overlay::getBufferAddress(overlay_buffer_t buffer)
93{
94 if (mStatus != NO_ERROR) return NULL;
95 return mOverlayData->getBufferAddress(mOverlayData, buffer);
96}
97
98void Overlay::destroy() {
Benny Wong71f77152009-07-15 18:44:27 -050099
100 // Must delete the objects in reverse creation order, thus the
101 // data side must be closed first and then the destroy send to
102 // the control side.
103 if (mOverlayData) {
104 overlay_data_close(mOverlayData);
105 mOverlayData = NULL;
Naomi Luis29a73ba2010-11-18 12:48:25 -0800106 } else {
107 LOGD("Overlay::destroy mOverlayData is NULL");
Benny Wong71f77152009-07-15 18:44:27 -0500108 }
109
Naomi Luis29a73ba2010-11-18 12:48:25 -0800110 if (mOverlayRef != 0) {
111 mOverlayRef->mOverlayChannel->destroy();
112 } else {
113 LOGD("Overlay::destroy mOverlayRef is NULL");
114 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115}
116
117status_t Overlay::getStatus() const {
118 return mStatus;
119}
120
121overlay_handle_t Overlay::getHandleRef() const {
122 if (mStatus != NO_ERROR) return NULL;
123 return mOverlayRef->mOverlayHandle;
124}
125
126uint32_t Overlay::getWidth() const {
127 if (mStatus != NO_ERROR) return 0;
128 return mOverlayRef->mWidth;
129}
130
131uint32_t Overlay::getHeight() const {
132 if (mStatus != NO_ERROR) return 0;
133 return mOverlayRef->mHeight;
134}
135
136int32_t Overlay::getFormat() const {
137 if (mStatus != NO_ERROR) return -1;
138 return mOverlayRef->mFormat;
139}
140
141int32_t Overlay::getWidthStride() const {
142 if (mStatus != NO_ERROR) return 0;
143 return mOverlayRef->mWidthStride;
144}
145
146int32_t Overlay::getHeightStride() const {
147 if (mStatus != NO_ERROR) return 0;
148 return mOverlayRef->mHeightStride;
149}
150// ----------------------------------------------------------------------------
151
152OverlayRef::OverlayRef()
153 : mOverlayHandle(0),
154 mWidth(0), mHeight(0), mFormat(0), mWidthStride(0), mHeightStride(0),
155 mOwnHandle(true)
156{
157}
158
159OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel,
160 uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
161 : mOverlayHandle(handle), mOverlayChannel(channel),
162 mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
163 mOwnHandle(false)
164{
165}
166
167OverlayRef::~OverlayRef()
168{
169 if (mOwnHandle) {
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700170 native_handle_close(mOverlayHandle);
171 native_handle_delete(const_cast<native_handle*>(mOverlayHandle));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800172 }
173}
174
175sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) {
176 sp<OverlayRef> result;
177 sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
178 if (overlay != NULL) {
179 uint32_t w = data.readInt32();
180 uint32_t h = data.readInt32();
181 uint32_t f = data.readInt32();
182 uint32_t ws = data.readInt32();
183 uint32_t hs = data.readInt32();
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700184 native_handle* handle = data.readNativeHandle();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185
186 result = new OverlayRef();
187 result->mOverlayHandle = handle;
188 result->mOverlayChannel = overlay;
189 result->mWidth = w;
190 result->mHeight = h;
191 result->mFormat = f;
192 result->mWidthStride = ws;
193 result->mHeightStride = hs;
194 }
195 return result;
196}
197
198status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
199 if (o != NULL) {
200 reply->writeStrongBinder(o->mOverlayChannel->asBinder());
201 reply->writeInt32(o->mWidth);
202 reply->writeInt32(o->mHeight);
203 reply->writeInt32(o->mFormat);
204 reply->writeInt32(o->mWidthStride);
205 reply->writeInt32(o->mHeightStride);
Mathias Agopiana47f02a2009-05-21 16:29:38 -0700206 reply->writeNativeHandle(o->mOverlayHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207 } else {
208 reply->writeStrongBinder(NULL);
209 }
210 return NO_ERROR;
211}
212
213// ----------------------------------------------------------------------------
214
215}; // namespace android