blob: 4854d6a2a26f2f9c2585e2466f480ded942365f4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian07952722009-05-19 19:08:10 -070017#include <binder/IMemory.h>
18#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019#include <utils/Errors.h>
Mathias Agopian07952722009-05-19 19:08:10 -070020#include <binder/MemoryHeapBase.h>
The Android Open Source Project9066cfe2009-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 Wong6d2090e2009-07-15 18:44:27 -050062status_t Overlay::setCrop(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
63{
64 if (mStatus != NO_ERROR) return mStatus;
65 return mOverlayData->setCrop(mOverlayData, x, y, w, h);
66}
67
68status_t Overlay::getCrop(uint32_t* x, uint32_t* y, uint32_t* w, uint32_t* h)
69{
70 if (mStatus != NO_ERROR) return mStatus;
71 return mOverlayData->getCrop(mOverlayData, x, y, w, h);
72}
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074int32_t Overlay::getBufferCount() const
75{
76 if (mStatus != NO_ERROR) return mStatus;
77 return mOverlayData->getBufferCount(mOverlayData);
78}
79
80void* Overlay::getBufferAddress(overlay_buffer_t buffer)
81{
82 if (mStatus != NO_ERROR) return NULL;
83 return mOverlayData->getBufferAddress(mOverlayData, buffer);
84}
85
86void Overlay::destroy() {
87 if (mStatus != NO_ERROR) return;
Benny Wong6d2090e2009-07-15 18:44:27 -050088
89 // Must delete the objects in reverse creation order, thus the
90 // data side must be closed first and then the destroy send to
91 // the control side.
92 if (mOverlayData) {
93 overlay_data_close(mOverlayData);
94 mOverlayData = NULL;
95 }
96
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 mOverlayRef->mOverlayChannel->destroy();
98}
99
100status_t Overlay::getStatus() const {
101 return mStatus;
102}
103
104overlay_handle_t Overlay::getHandleRef() const {
105 if (mStatus != NO_ERROR) return NULL;
106 return mOverlayRef->mOverlayHandle;
107}
108
109uint32_t Overlay::getWidth() const {
110 if (mStatus != NO_ERROR) return 0;
111 return mOverlayRef->mWidth;
112}
113
114uint32_t Overlay::getHeight() const {
115 if (mStatus != NO_ERROR) return 0;
116 return mOverlayRef->mHeight;
117}
118
119int32_t Overlay::getFormat() const {
120 if (mStatus != NO_ERROR) return -1;
121 return mOverlayRef->mFormat;
122}
123
124int32_t Overlay::getWidthStride() const {
125 if (mStatus != NO_ERROR) return 0;
126 return mOverlayRef->mWidthStride;
127}
128
129int32_t Overlay::getHeightStride() const {
130 if (mStatus != NO_ERROR) return 0;
131 return mOverlayRef->mHeightStride;
132}
133// ----------------------------------------------------------------------------
134
135OverlayRef::OverlayRef()
136 : mOverlayHandle(0),
137 mWidth(0), mHeight(0), mFormat(0), mWidthStride(0), mHeightStride(0),
138 mOwnHandle(true)
139{
140}
141
142OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel,
143 uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
144 : mOverlayHandle(handle), mOverlayChannel(channel),
145 mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
146 mOwnHandle(false)
147{
148}
149
150OverlayRef::~OverlayRef()
151{
152 if (mOwnHandle) {
Mathias Agopiandfece802009-05-21 16:29:38 -0700153 native_handle_close(mOverlayHandle);
154 native_handle_delete(const_cast<native_handle*>(mOverlayHandle));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 }
156}
157
158sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) {
159 sp<OverlayRef> result;
160 sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
161 if (overlay != NULL) {
162 uint32_t w = data.readInt32();
163 uint32_t h = data.readInt32();
164 uint32_t f = data.readInt32();
165 uint32_t ws = data.readInt32();
166 uint32_t hs = data.readInt32();
Mathias Agopiandfece802009-05-21 16:29:38 -0700167 native_handle* handle = data.readNativeHandle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168
169 result = new OverlayRef();
170 result->mOverlayHandle = handle;
171 result->mOverlayChannel = overlay;
172 result->mWidth = w;
173 result->mHeight = h;
174 result->mFormat = f;
175 result->mWidthStride = ws;
176 result->mHeightStride = hs;
177 }
178 return result;
179}
180
181status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
182 if (o != NULL) {
183 reply->writeStrongBinder(o->mOverlayChannel->asBinder());
184 reply->writeInt32(o->mWidth);
185 reply->writeInt32(o->mHeight);
186 reply->writeInt32(o->mFormat);
187 reply->writeInt32(o->mWidthStride);
188 reply->writeInt32(o->mHeightStride);
Mathias Agopiandfece802009-05-21 16:29:38 -0700189 reply->writeNativeHandle(o->mOverlayHandle);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 } else {
191 reply->writeStrongBinder(NULL);
192 }
193 return NO_ERROR;
194}
195
196// ----------------------------------------------------------------------------
197
198}; // namespace android