/* * 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 #include #include #include namespace android { Overlay::Overlay(overlay_handle_t* handle, const sp& o, const sp& 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& o, const sp& 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 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::readFromParcel(const Parcel& data) { sp result; sp overlay = IOverlay::asInterface(data.readStrongBinder()); if (overlay != NULL) { sp 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 ; ifds[i] = data.readFileDescriptor(); for (int i=0 ; idata[i] = data.readInt32(); result = new Overlay(handle, overlay, heap, w, h, f, ws, hs); } return result; } status_t Overlay::writeToParcel(Parcel* reply, const sp& 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 ; imOverlayHandle->numFds ; i++) reply->writeFileDescriptor(o->mOverlayHandle->fds[i]); for (int i=0 ; imOverlayHandle->numInts ; i++) reply->writeInt32(o->mOverlayHandle->data[i]); } else { reply->writeStrongBinder(NULL); } return NO_ERROR; } // ---------------------------------------------------------------------------- }; // namespace android