Home | History | Annotate | Download | only in surfaceflinger
      1 /*
      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 #ifndef ANDROID_SF_ISURFACE_H
     18 #define ANDROID_SF_ISURFACE_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <utils/Errors.h>
     24 #include <utils/RefBase.h>
     25 
     26 #include <binder/IInterface.h>
     27 
     28 #include <ui/PixelFormat.h>
     29 
     30 #include <hardware/hardware.h>
     31 #include <hardware/gralloc.h>
     32 
     33 namespace android {
     34 
     35 typedef int32_t    SurfaceID;
     36 
     37 class IMemoryHeap;
     38 class OverlayRef;
     39 class GraphicBuffer;
     40 
     41 class ISurface : public IInterface
     42 {
     43 protected:
     44     enum {
     45         REGISTER_BUFFERS = IBinder::FIRST_CALL_TRANSACTION,
     46         UNREGISTER_BUFFERS,
     47         POST_BUFFER, // one-way transaction
     48         CREATE_OVERLAY,
     49         REQUEST_BUFFER,
     50         SET_BUFFER_COUNT,
     51     };
     52 
     53 public:
     54     DECLARE_META_INTERFACE(Surface);
     55 
     56     /*
     57      * requests a new buffer for the given index. If w, h, or format are
     58      * null the buffer is created with the parameters assigned to the
     59      * surface it is bound to. Otherwise the buffer's parameters are
     60      * set to those specified.
     61      */
     62     virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
     63             uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0;
     64 
     65     /*
     66      * sets the number of buffers dequeuable for this surface.
     67      */
     68     virtual status_t setBufferCount(int bufferCount) = 0;
     69 
     70     // ------------------------------------------------------------------------
     71     // Deprecated...
     72     // ------------------------------------------------------------------------
     73 
     74     class BufferHeap {
     75     public:
     76         enum {
     77             /* rotate source image */
     78             ROT_0     = 0,
     79             ROT_90    = HAL_TRANSFORM_ROT_90,
     80             ROT_180   = HAL_TRANSFORM_ROT_180,
     81             ROT_270   = HAL_TRANSFORM_ROT_270,
     82         };
     83         BufferHeap();
     84 
     85         BufferHeap(uint32_t w, uint32_t h,
     86                 int32_t hor_stride, int32_t ver_stride,
     87                 PixelFormat format, const sp<IMemoryHeap>& heap);
     88 
     89         BufferHeap(uint32_t w, uint32_t h,
     90                 int32_t hor_stride, int32_t ver_stride,
     91                 PixelFormat format, uint32_t transform, uint32_t flags,
     92                 const sp<IMemoryHeap>& heap);
     93 
     94         ~BufferHeap();
     95 
     96         uint32_t w;
     97         uint32_t h;
     98         int32_t hor_stride;
     99         int32_t ver_stride;
    100         PixelFormat format;
    101         uint32_t transform;
    102         uint32_t flags;
    103         sp<IMemoryHeap> heap;
    104     };
    105 
    106     virtual status_t registerBuffers(const BufferHeap& buffers) = 0;
    107     virtual void postBuffer(ssize_t offset) = 0; // one-way
    108     virtual void unregisterBuffers() = 0;
    109 
    110     virtual sp<OverlayRef> createOverlay(
    111             uint32_t w, uint32_t h, int32_t format, int32_t orientation) = 0;
    112 };
    113 
    114 // ----------------------------------------------------------------------------
    115 
    116 class BnSurface : public BnInterface<ISurface>
    117 {
    118 public:
    119     virtual status_t    onTransact( uint32_t code,
    120                                     const Parcel& data,
    121                                     Parcel* reply,
    122                                     uint32_t flags = 0);
    123 };
    124 
    125 // ----------------------------------------------------------------------------
    126 
    127 }; // namespace android
    128 
    129 #endif // ANDROID_SF_ISURFACE_H
    130