Home | History | Annotate | Download | only in gui
      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_GUI_SURFACE_COMPOSER_CLIENT_H
     18 #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <binder/IBinder.h>
     24 
     25 #include <utils/RefBase.h>
     26 #include <utils/Singleton.h>
     27 #include <utils/SortedVector.h>
     28 #include <utils/threads.h>
     29 
     30 #include <ui/PixelFormat.h>
     31 
     32 #include <gui/Surface.h>
     33 
     34 namespace android {
     35 
     36 // ---------------------------------------------------------------------------
     37 
     38 class DisplayInfo;
     39 class Composer;
     40 class IMemoryHeap;
     41 class ISurfaceComposerClient;
     42 class Region;
     43 
     44 // ---------------------------------------------------------------------------
     45 
     46 class SurfaceComposerClient : public RefBase
     47 {
     48     friend class Composer;
     49 public:
     50                 SurfaceComposerClient();
     51     virtual     ~SurfaceComposerClient();
     52 
     53     // Always make sure we could initialize
     54     status_t    initCheck() const;
     55 
     56     // Return the connection of this client
     57     sp<IBinder> connection() const;
     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             const String8& name,// name of the surface
     68             DisplayID display,  // Display to create this surface on
     69             uint32_t w,         // width in pixel
     70             uint32_t h,         // height in pixel
     71             PixelFormat format, // pixel-format desired
     72             uint32_t flags = 0  // usage flags
     73     );
     74 
     75     sp<SurfaceControl> createSurface(
     76             DisplayID display,  // Display to create this surface on
     77             uint32_t w,         // width in pixel
     78             uint32_t h,         // height in pixel
     79             PixelFormat format, // pixel-format desired
     80             uint32_t flags = 0  // usage flags
     81     );
     82 
     83 
     84     // ------------------------------------------------------------------------
     85     // Composer parameters
     86     // All composer parameters must be changed within a transaction
     87     // several surfaces can be updated in one transaction, all changes are
     88     // committed at once when the transaction is closed.
     89     // closeGlobalTransaction() usually requires an IPC with the server.
     90 
     91     //! Open a composer transaction on all active SurfaceComposerClients.
     92     static void openGlobalTransaction();
     93 
     94     //! Close a composer transaction on all active SurfaceComposerClients.
     95     static void closeGlobalTransaction(bool synchronous = false);
     96 
     97     //! Freeze the specified display but not transactions.
     98     static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
     99 
    100     //! Resume updates on the specified display.
    101     static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
    102 
    103     //! Set the orientation of the given display
    104     static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
    105 
    106     // Query the number of displays
    107     static ssize_t getNumberOfDisplays();
    108 
    109     // Get information about a display
    110     static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
    111     static ssize_t getDisplayWidth(DisplayID dpy);
    112     static ssize_t getDisplayHeight(DisplayID dpy);
    113     static ssize_t getDisplayOrientation(DisplayID dpy);
    114 
    115     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
    116             void* cookie = NULL, uint32_t flags = 0);
    117 
    118     status_t    hide(SurfaceID id);
    119     status_t    show(SurfaceID id, int32_t layer = -1);
    120     status_t    freeze(SurfaceID id);
    121     status_t    unfreeze(SurfaceID id);
    122     status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
    123     status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
    124     status_t    setLayer(SurfaceID id, int32_t layer);
    125     status_t    setAlpha(SurfaceID id, float alpha=1.0f);
    126     status_t    setFreezeTint(SurfaceID id, uint32_t tint);
    127     status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
    128     status_t    setPosition(SurfaceID id, float x, float y);
    129     status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
    130     status_t    setCrop(SurfaceID id, const Rect& crop);
    131     status_t    destroySurface(SurfaceID sid);
    132 
    133 private:
    134     virtual void onFirstRef();
    135     Composer& getComposer();
    136 
    137     mutable     Mutex                       mLock;
    138                 status_t                    mStatus;
    139                 sp<ISurfaceComposerClient>  mClient;
    140                 Composer&                   mComposer;
    141 };
    142 
    143 // ---------------------------------------------------------------------------
    144 
    145 class ScreenshotClient
    146 {
    147     sp<IMemoryHeap> mHeap;
    148     uint32_t mWidth;
    149     uint32_t mHeight;
    150     PixelFormat mFormat;
    151 public:
    152     ScreenshotClient();
    153 
    154     // frees the previous screenshot and capture a new one
    155     status_t update();
    156     status_t update(uint32_t reqWidth, uint32_t reqHeight);
    157     status_t update(uint32_t reqWidth, uint32_t reqHeight,
    158             uint32_t minLayerZ, uint32_t maxLayerZ);
    159 
    160     // release memory occupied by the screenshot
    161     void release();
    162 
    163     // pixels are valid until this object is freed or
    164     // release() or update() is called
    165     void const* getPixels() const;
    166 
    167     uint32_t getWidth() const;
    168     uint32_t getHeight() const;
    169     PixelFormat getFormat() const;
    170     uint32_t getStride() const;
    171     // size of allocated memory in bytes
    172     size_t getSize() const;
    173 };
    174 
    175 // ---------------------------------------------------------------------------
    176 }; // namespace android
    177 
    178 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
    179