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_SURFACE_COMPOSER_CLIENT_H
     18 #define ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <binder/IBinder.h>
     24 
     25 #include <utils/SortedVector.h>
     26 #include <utils/RefBase.h>
     27 #include <utils/threads.h>
     28 
     29 #include <ui/PixelFormat.h>
     30 #include <ui/Region.h>
     31 
     32 #include <surfaceflinger/Surface.h>
     33 
     34 namespace android {
     35 
     36 // ---------------------------------------------------------------------------
     37 
     38 class Region;
     39 class SharedClient;
     40 class ISurfaceComposer;
     41 class DisplayInfo;
     42 
     43 class SurfaceComposerClient : virtual public RefBase
     44 {
     45 public:
     46                 SurfaceComposerClient();
     47     virtual     ~SurfaceComposerClient();
     48 
     49     // Always make sure we could initialize
     50     status_t    initCheck() const;
     51 
     52     // Return the connection of this client
     53     sp<IBinder> connection() const;
     54 
     55     // Retrieve a client for an existing connection.
     56     static sp<SurfaceComposerClient>
     57                 clientForConnection(const sp<IBinder>& conn);
     58 
     59     // Forcibly remove connection before all references have gone away.
     60     void        dispose();
     61 
     62     // ------------------------------------------------------------------------
     63     // surface creation / destruction
     64 
     65     //! Create a surface
     66     sp<SurfaceControl> createSurface(
     67             int pid,            // pid of the process the surface is for
     68             const String8& name,// name of the surface
     69             DisplayID display,  // Display to create this surface on
     70             uint32_t w,         // width in pixel
     71             uint32_t h,         // height in pixel
     72             PixelFormat format, // pixel-format desired
     73             uint32_t flags = 0  // usage flags
     74     );
     75 
     76     sp<SurfaceControl> createSurface(
     77             int pid,            // pid of the process the surface is for
     78             DisplayID display,  // Display to create this surface on
     79             uint32_t w,         // width in pixel
     80             uint32_t h,         // height in pixel
     81             PixelFormat format, // pixel-format desired
     82             uint32_t flags = 0  // usage flags
     83     );
     84 
     85 
     86     // ------------------------------------------------------------------------
     87     // Composer parameters
     88     // All composer parameters must be changed within a transaction
     89     // several surfaces can be updated in one transaction, all changes are
     90     // committed at once when the transaction is closed.
     91     // CloseTransaction() usually requires an IPC with the server.
     92 
     93     //! Open a composer transaction
     94     status_t    openTransaction();
     95 
     96     //! commit the transaction
     97     status_t    closeTransaction();
     98 
     99     //! Open a composer transaction on all active SurfaceComposerClients.
    100     static void openGlobalTransaction();
    101 
    102     //! Close a composer transaction on all active SurfaceComposerClients.
    103     static void closeGlobalTransaction();
    104 
    105     //! Freeze the specified display but not transactions.
    106     static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
    107 
    108     //! Resume updates on the specified display.
    109     static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
    110 
    111     //! Set the orientation of the given display
    112     static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
    113 
    114     // Query the number of displays
    115     static ssize_t getNumberOfDisplays();
    116 
    117     // Get information about a display
    118     static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
    119     static ssize_t getDisplayWidth(DisplayID dpy);
    120     static ssize_t getDisplayHeight(DisplayID dpy);
    121     static ssize_t getDisplayOrientation(DisplayID dpy);
    122 
    123     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
    124             void* cookie = NULL, uint32_t flags = 0);
    125 
    126 private:
    127     friend class Surface;
    128     friend class SurfaceControl;
    129 
    130     SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
    131             const sp<IBinder>& conn);
    132 
    133     status_t    hide(SurfaceID id);
    134     status_t    show(SurfaceID id, int32_t layer = -1);
    135     status_t    freeze(SurfaceID id);
    136     status_t    unfreeze(SurfaceID id);
    137     status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
    138     status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
    139     status_t    setLayer(SurfaceID id, int32_t layer);
    140     status_t    setAlpha(SurfaceID id, float alpha=1.0f);
    141     status_t    setFreezeTint(SurfaceID id, uint32_t tint);
    142     status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
    143     status_t    setPosition(SurfaceID id, int32_t x, int32_t y);
    144     status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
    145 
    146     void        signalServer();
    147 
    148     status_t    destroySurface(SurfaceID sid);
    149 
    150     void        _init(const sp<ISurfaceComposer>& sm,
    151                     const sp<ISurfaceFlingerClient>& conn);
    152 
    153     inline layer_state_t*   _get_state_l(SurfaceID id);
    154     layer_state_t*          _lockLayerState(SurfaceID id);
    155     inline void             _unlockLayerState();
    156 
    157     mutable     Mutex                               mLock;
    158                 layer_state_t*                      mPrebuiltLayerState;
    159                 SortedVector<layer_state_t>         mStates;
    160                 int32_t                             mTransactionOpen;
    161 
    162                 // these don't need to be protected because they never change
    163                 // after assignment
    164                 status_t                    mStatus;
    165                 SharedClient*               mControl;
    166                 sp<IMemoryHeap>             mControlMemory;
    167                 sp<ISurfaceFlingerClient>   mClient;
    168                 sp<ISurfaceComposer>        mSignalServer;
    169 };
    170 
    171 }; // namespace android
    172 
    173 #endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
    174 
    175