summaryrefslogtreecommitdiffstats
path: root/libs/ui/Overlay.cpp
blob: 2267c3e7686ae4364a8e9e2e3326a19fdfa10038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <utils/IMemory.h>
#include <utils/Parcel.h>

#include <ui/IOverlay.h>
#include <ui/Overlay.h>

namespace android {

Overlay::Overlay(overlay_handle_t* handle, 
        const sp<IOverlay>& o, const sp<IMemoryHeap>& heap, 
        uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
    : mOverlay(o), mHeap(heap), mCurrentBufferOffset(0), mOverlayHandle(handle),
      mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs)
{
}

Overlay::Overlay(overlay_t* overlay, 
        const sp<IOverlay>& o, const sp<IMemoryHeap>& heap)
    : mOverlay(o), mHeap(heap) 
{
    mCurrentBufferOffset = 0; 
    mOverlayHandle = overlay->getHandleRef(overlay);
    mWidth = overlay->w;
    mHeight = overlay->h;
    mFormat = overlay->format; 
    mWidthStride = overlay->w_stride;
    mHeightStride = overlay->h_stride;
}


Overlay::~Overlay() {
}

void Overlay::destroy() {  
    mOverlay->destroy();
}

status_t Overlay::swapBuffers() {
    ssize_t result = mOverlay->swapBuffers();
    if (result < 0)
        return status_t(result);
    mCurrentBufferOffset = result;
    return NO_ERROR;
}

overlay_handle_t const* Overlay::getHandleRef() const {
    return mOverlayHandle;
}

size_t Overlay::getBufferOffset() const {
    return mCurrentBufferOffset;
}

sp<IMemoryHeap> Overlay::getHeap() const {
    return mHeap;
}

uint32_t Overlay::getWidth() const {
    return mWidth;
}

uint32_t Overlay::getHeight() const {
    return mHeight;
}

int32_t Overlay::getFormat() const {
    return mFormat;
}

int32_t Overlay::getWidthStride() const {
    return mWidthStride;
}

int32_t Overlay::getHeightStride() const {
    return mHeightStride;
}

sp<Overlay> Overlay::readFromParcel(const Parcel& data) {
    sp<Overlay> result;
    sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
    if (overlay != NULL) {
        sp<IMemoryHeap> heap = IMemoryHeap::asInterface(data.readStrongBinder());
        uint32_t w = data.readInt32();
        uint32_t h = data.readInt32();
        uint32_t f = data.readInt32();
        uint32_t ws = data.readInt32();
        uint32_t hs = data.readInt32();
        /* FIXME: handles should be promoted to "real" API and be handled by 
         * the framework */
        int numfd = data.readInt32();
        int numint = data.readInt32();
        overlay_handle_t* handle = (overlay_handle_t*)malloc(
                sizeof(overlay_handle_t) + numint*sizeof(int));
        for (int i=0 ; i<numfd ; i++)
            handle->fds[i] = data.readFileDescriptor();
        for (int i=0 ; i<numint ; i++)
            handle->data[i] = data.readInt32();
        result = new Overlay(handle, overlay, heap, w, h, f, ws, hs);
    }
    return result;
}

status_t Overlay::writeToParcel(Parcel* reply, const sp<Overlay>& o) {
    if (o != NULL) {
        reply->writeStrongBinder(o->mOverlay->asBinder());
        reply->writeStrongBinder(o->mHeap->asBinder());
        reply->writeInt32(o->mWidth);
        reply->writeInt32(o->mHeight);
        reply->writeInt32(o->mFormat);
        reply->writeInt32(o->mWidthStride);
        reply->writeInt32(o->mHeightStride);
        /* FIXME: handles should be promoted to "real" API and be handled by 
         * the framework */
        reply->writeInt32(o->mOverlayHandle->numFds);
        reply->writeInt32(o->mOverlayHandle->numInts);
        for (int i=0 ; i<o->mOverlayHandle->numFds ; i++)
            reply->writeFileDescriptor(o->mOverlayHandle->fds[i]);
        for (int i=0 ; i<o->mOverlayHandle->numInts ; i++)
            reply->writeInt32(o->mOverlayHandle->data[i]);
    } else {
        reply->writeStrongBinder(NULL);
    }
    return NO_ERROR;
}

// ----------------------------------------------------------------------------

}; // namespace android