blob: 2267c3e7686ae4364a8e9e2e3326a19fdfa10038 [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>
19
20#include <ui/IOverlay.h>
21#include <ui/Overlay.h>
22
23namespace android {
24
25Overlay::Overlay(overlay_handle_t* handle,
26 const sp<IOverlay>& o, const sp<IMemoryHeap>& heap,
27 uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
28 : mOverlay(o), mHeap(heap), mCurrentBufferOffset(0), mOverlayHandle(handle),
29 mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs)
30{
31}
32
33Overlay::Overlay(overlay_t* overlay,
34 const sp<IOverlay>& o, const sp<IMemoryHeap>& heap)
35 : mOverlay(o), mHeap(heap)
36{
37 mCurrentBufferOffset = 0;
38 mOverlayHandle = overlay->getHandleRef(overlay);
39 mWidth = overlay->w;
40 mHeight = overlay->h;
41 mFormat = overlay->format;
42 mWidthStride = overlay->w_stride;
43 mHeightStride = overlay->h_stride;
44}
45
46
47Overlay::~Overlay() {
48}
49
50void Overlay::destroy() {
51 mOverlay->destroy();
52}
53
54status_t Overlay::swapBuffers() {
55 ssize_t result = mOverlay->swapBuffers();
56 if (result < 0)
57 return status_t(result);
58 mCurrentBufferOffset = result;
59 return NO_ERROR;
60}
61
62overlay_handle_t const* Overlay::getHandleRef() const {
63 return mOverlayHandle;
64}
65
66size_t Overlay::getBufferOffset() const {
67 return mCurrentBufferOffset;
68}
69
70sp<IMemoryHeap> Overlay::getHeap() const {
71 return mHeap;
72}
73
74uint32_t Overlay::getWidth() const {
75 return mWidth;
76}
77
78uint32_t Overlay::getHeight() const {
79 return mHeight;
80}
81
82int32_t Overlay::getFormat() const {
83 return mFormat;
84}
85
86int32_t Overlay::getWidthStride() const {
87 return mWidthStride;
88}
89
90int32_t Overlay::getHeightStride() const {
91 return mHeightStride;
92}
93
94sp<Overlay> Overlay::readFromParcel(const Parcel& data) {
95 sp<Overlay> result;
96 sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
97 if (overlay != NULL) {
98 sp<IMemoryHeap> heap = IMemoryHeap::asInterface(data.readStrongBinder());
99 uint32_t w = data.readInt32();
100 uint32_t h = data.readInt32();
101 uint32_t f = data.readInt32();
102 uint32_t ws = data.readInt32();
103 uint32_t hs = data.readInt32();
104 /* FIXME: handles should be promoted to "real" API and be handled by
105 * the framework */
106 int numfd = data.readInt32();
107 int numint = data.readInt32();
108 overlay_handle_t* handle = (overlay_handle_t*)malloc(
109 sizeof(overlay_handle_t) + numint*sizeof(int));
110 for (int i=0 ; i<numfd ; i++)
111 handle->fds[i] = data.readFileDescriptor();
112 for (int i=0 ; i<numint ; i++)
113 handle->data[i] = data.readInt32();
114 result = new Overlay(handle, overlay, heap, w, h, f, ws, hs);
115 }
116 return result;
117}
118
119status_t Overlay::writeToParcel(Parcel* reply, const sp<Overlay>& o) {
120 if (o != NULL) {
121 reply->writeStrongBinder(o->mOverlay->asBinder());
122 reply->writeStrongBinder(o->mHeap->asBinder());
123 reply->writeInt32(o->mWidth);
124 reply->writeInt32(o->mHeight);
125 reply->writeInt32(o->mFormat);
126 reply->writeInt32(o->mWidthStride);
127 reply->writeInt32(o->mHeightStride);
128 /* FIXME: handles should be promoted to "real" API and be handled by
129 * the framework */
130 reply->writeInt32(o->mOverlayHandle->numFds);
131 reply->writeInt32(o->mOverlayHandle->numInts);
132 for (int i=0 ; i<o->mOverlayHandle->numFds ; i++)
133 reply->writeFileDescriptor(o->mOverlayHandle->fds[i]);
134 for (int i=0 ; i<o->mOverlayHandle->numInts ; i++)
135 reply->writeInt32(o->mOverlayHandle->data[i]);
136 } else {
137 reply->writeStrongBinder(NULL);
138 }
139 return NO_ERROR;
140}
141
142// ----------------------------------------------------------------------------
143
144}; // namespace android
145