2008-12-18 02:05:43 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2009-01-10 01:51:23 +00:00
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/MemoryHeapBase.h>
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
#include <ui/IOverlay.h>
|
|
|
|
#include <ui/Overlay.h>
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
#include <hardware/overlay.h>
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
namespace android {
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
Overlay::Overlay(const sp<OverlayRef>& overlayRef)
|
|
|
|
: mOverlayRef(overlayRef), mOverlayData(0), mStatus(NO_INIT)
|
2008-12-18 02:05:43 +00:00
|
|
|
{
|
2009-01-10 01:51:23 +00:00
|
|
|
mOverlayData = NULL;
|
|
|
|
hw_module_t const* module;
|
2009-01-16 00:12:10 +00:00
|
|
|
if (overlayRef != 0) {
|
|
|
|
if (hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module) == 0) {
|
|
|
|
if (overlay_data_open(module, &mOverlayData) == NO_ERROR) {
|
|
|
|
mStatus = mOverlayData->initialize(mOverlayData,
|
|
|
|
overlayRef->mOverlayHandle);
|
|
|
|
}
|
2009-01-10 01:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
Overlay::~Overlay() {
|
|
|
|
if (mOverlayData) {
|
|
|
|
overlay_data_close(mOverlayData);
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 00:12:10 +00:00
|
|
|
status_t Overlay::dequeueBuffer(overlay_buffer_t* buffer)
|
2009-01-10 01:51:23 +00:00
|
|
|
{
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return mStatus;
|
|
|
|
return mOverlayData->dequeueBuffer(mOverlayData, buffer);
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 00:12:10 +00:00
|
|
|
status_t Overlay::queueBuffer(overlay_buffer_t buffer)
|
2009-01-10 01:51:23 +00:00
|
|
|
{
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return mStatus;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayData->queueBuffer(mOverlayData, buffer);
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 23:44:00 +00:00
|
|
|
int32_t Overlay::getBufferCount() const
|
|
|
|
{
|
|
|
|
if (mStatus != NO_ERROR) return mStatus;
|
|
|
|
return mOverlayData->getBufferCount(mOverlayData);
|
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
void* Overlay::getBufferAddress(overlay_buffer_t buffer)
|
|
|
|
{
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return NULL;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayData->getBufferAddress(mOverlayData, buffer);
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
void Overlay::destroy() {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return;
|
|
|
|
mOverlayRef->mOverlayChannel->destroy();
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
status_t Overlay::getStatus() const {
|
|
|
|
return mStatus;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 22:03:58 +00:00
|
|
|
overlay_handle_t Overlay::getHandleRef() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return NULL;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mOverlayHandle;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Overlay::getWidth() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return 0;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mWidth;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Overlay::getHeight() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return 0;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mHeight;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Overlay::getFormat() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return -1;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mFormat;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Overlay::getWidthStride() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return 0;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mWidthStride;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Overlay::getHeightStride() const {
|
2009-01-16 00:12:10 +00:00
|
|
|
if (mStatus != NO_ERROR) return 0;
|
2009-01-10 01:51:23 +00:00
|
|
|
return mOverlayRef->mHeightStride;
|
|
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
OverlayRef::OverlayRef()
|
|
|
|
: mOverlayHandle(0),
|
|
|
|
mWidth(0), mHeight(0), mFormat(0), mWidthStride(0), mHeightStride(0),
|
|
|
|
mOwnHandle(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-20 22:03:58 +00:00
|
|
|
OverlayRef::OverlayRef(overlay_handle_t handle, const sp<IOverlay>& channel,
|
2009-01-10 01:51:23 +00:00
|
|
|
uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs)
|
2009-01-16 00:12:10 +00:00
|
|
|
: mOverlayHandle(handle), mOverlayChannel(channel),
|
2009-01-10 01:51:23 +00:00
|
|
|
mWidth(w), mHeight(h), mFormat(f), mWidthStride(ws), mHeightStride(hs),
|
|
|
|
mOwnHandle(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OverlayRef::~OverlayRef()
|
|
|
|
{
|
|
|
|
if (mOwnHandle) {
|
|
|
|
/* FIXME: handles should be promoted to "real" API and be handled by
|
|
|
|
* the framework */
|
|
|
|
for (int i=0 ; i<mOverlayHandle->numFds ; i++) {
|
2009-01-20 22:03:58 +00:00
|
|
|
close(mOverlayHandle->data[i]);
|
2009-01-10 01:51:23 +00:00
|
|
|
}
|
|
|
|
free((void*)mOverlayHandle);
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
sp<OverlayRef> OverlayRef::readFromParcel(const Parcel& data) {
|
|
|
|
sp<OverlayRef> result;
|
2008-12-18 02:05:43 +00:00
|
|
|
sp<IOverlay> overlay = IOverlay::asInterface(data.readStrongBinder());
|
|
|
|
if (overlay != NULL) {
|
|
|
|
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();
|
2009-01-20 22:03:58 +00:00
|
|
|
native_handle* handle = data.readNativeHandle(NULL, NULL);
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
result = new OverlayRef();
|
|
|
|
result->mOverlayHandle = handle;
|
2009-01-16 00:12:10 +00:00
|
|
|
result->mOverlayChannel = overlay;
|
2009-01-10 01:51:23 +00:00
|
|
|
result->mWidth = w;
|
|
|
|
result->mHeight = h;
|
|
|
|
result->mFormat = f;
|
|
|
|
result->mWidthStride = ws;
|
|
|
|
result->mHeightStride = hs;
|
2008-12-18 02:05:43 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
status_t OverlayRef::writeToParcel(Parcel* reply, const sp<OverlayRef>& o) {
|
2008-12-18 02:05:43 +00:00
|
|
|
if (o != NULL) {
|
2009-01-16 00:12:10 +00:00
|
|
|
reply->writeStrongBinder(o->mOverlayChannel->asBinder());
|
2008-12-18 02:05:43 +00:00
|
|
|
reply->writeInt32(o->mWidth);
|
|
|
|
reply->writeInt32(o->mHeight);
|
|
|
|
reply->writeInt32(o->mFormat);
|
|
|
|
reply->writeInt32(o->mWidthStride);
|
|
|
|
reply->writeInt32(o->mHeightStride);
|
2009-01-20 22:03:58 +00:00
|
|
|
reply->writeNativeHandle(*(o->mOverlayHandle));
|
2008-12-18 02:05:43 +00:00
|
|
|
} else {
|
|
|
|
reply->writeStrongBinder(NULL);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|