blob: 59c65146e5d336a78c4b6fbcec349db7035b9822 [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
17#include <utils/IMemory.h>
18#include <utils/Parcel.h>
19#include <utils/Errors.h>
20#include <utils/MemoryHeapBase.h>
21
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
62int32_t Overlay::getBufferCount() const
63{
64 if (mStatus != NO_ERROR) return mStatus;
65 return mOverlayData->getBufferCount(mOverlayData);
66}
67
68void* Overlay::getBufferAddress(overlay_buffer_t buffer)
69{
70 if (mStatus != NO_ERROR) return NULL;
71 return mOverlayData->getBufferAddress(mOverlayData, buffer);
72}
73
74void Overlay::destroy() {
75 if (mStatus != NO_ERROR) return;
76 mOverlayRef->mOverlayChannel->destroy();
77}
78
79status_t Overlay::getStatus() const {
80 return mStatus;
81}
82
83overlay_handle_t Overlay::getHandleRef() const {
84 if (mStatus != NO_ERROR) return NULL;
85 return mOverlayRef->mOverlayHandle;
86}
87
88uint32_t Overlay::getWidth() const {
89 if (mStatus != NO_ERROR) return 0;
90 return mOverlayRef->mWidth;
91}
92
93uint32_t Overlay::getHeight() const {
94 if (mStatus != NO_ERROR) return 0;
95 return mOverlayRef->mHeight;
96}
97
98int32_t Overlay::getFormat() const {
99 if (mStatus != NO_ERROR) return -1;
100 return mOverlayRef->mFormat;
101}
102
103int32_t Overlay::getWidthStride() const {
104 if (mStatus != NO_ERROR) return 0;
105 return mOverlayRef->mWidthStride;
106}
107
108int32_t Overlay::getHeightStride() const {
109 if (mStatus != NO_ERROR) return 0;
110 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{
119}
120
121OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel,
122 uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
123 : mOverlayHandle(handle), mOverlayChannel(channel),
124 mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
125 mOwnHandle(false)
126{
127}
128
129OverlayRef::~OverlayRef()
130{
131 if (mOwnHandle) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700132 native_handle_close(mOverlayHandle);
133 native_handle_delete(const_cast<native_handle*>(mOverlayHandle));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 }
135}
136
137sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) {
138 sp<OverlayRef> result;
139 sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
140 if (overlay != NULL) {
141 uint32_t w = data.readInt32();
142 uint32_t h = data.readInt32();
143 uint32_t f = data.readInt32();
144 uint32_t ws = data.readInt32();
145 uint32_t hs = data.readInt32();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700146 native_handle* handle = data.readNativeHandle();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147
148 result = new OverlayRef();
149 result->mOverlayHandle = handle;
150 result->mOverlayChannel = overlay;
151 result->mWidth = w;
152 result->mHeight = h;
153 result->mFormat = f;
154 result->mWidthStride = ws;
155 result->mHeightStride = hs;
156 }
157 return result;
158}
159
160status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
161 if (o != NULL) {
162 reply->writeStrongBinder(o->mOverlayChannel->asBinder());
163 reply->writeInt32(o->mWidth);
164 reply->writeInt32(o->mHeight);
165 reply->writeInt32(o->mFormat);
166 reply->writeInt32(o->mWidthStride);
167 reply->writeInt32(o->mHeightStride);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700168 reply->writeNativeHandle(o->mOverlayHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800169 } else {
170 reply->writeStrongBinder(NULL);
171 }
172 return NO_ERROR;
173}
174
175// ----------------------------------------------------------------------------
176
177}; // namespace android