/* * 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. */ #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H #include #include #include #include #include #include #include #include #include #include #include #include namespace android { // --------------------------------------------------------------------------- class DisplayInfo; class Composer; class ISurfaceComposerClient; class IGraphicBufferProducer; class Region; // --------------------------------------------------------------------------- class SurfaceComposerClient : public RefBase { friend class Composer; public: SurfaceComposerClient(); virtual ~SurfaceComposerClient(); // Always make sure we could initialize status_t initCheck() const; // Return the connection of this client sp connection() const; // Forcibly remove connection before all references have gone away. void dispose(); // callback when the composer is dies status_t linkToComposerDeath(const sp& recipient, void* cookie = NULL, uint32_t flags = 0); // Get a list of supported configurations for a given display static status_t getDisplayConfigs(const sp& display, Vector* configs); // Get the DisplayInfo for the currently-active configuration static status_t getDisplayInfo(const sp& display, DisplayInfo* info); // Get the index of the current active configuration (relative to the list // returned by getDisplayInfo) static int getActiveConfig(const sp& display); // Set a new active configuration using an index relative to the list // returned by getDisplayInfo static status_t setActiveConfig(const sp& display, int id); /* triggers screen off and waits for it to complete */ static void blankDisplay(const sp& display); /* triggers screen on and waits for it to complete */ static void unblankDisplay(const sp& display); // ------------------------------------------------------------------------ // surface creation / destruction //! Create a surface sp createSurface( const String8& name,// name of the surface uint32_t w, // width in pixel uint32_t h, // height in pixel PixelFormat format, // pixel-format desired uint32_t flags = 0 // usage flags ); //! Create a virtual display static sp createDisplay(const String8& displayName, bool secure); //! Destroy a virtual display static void destroyDisplay(const sp& display); //! Get the token for the existing default displays. //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi. static sp getBuiltInDisplay(int32_t id); // ------------------------------------------------------------------------ // Composer parameters // All composer parameters must be changed within a transaction // several surfaces can be updated in one transaction, all changes are // committed at once when the transaction is closed. // closeGlobalTransaction() requires an IPC with the server. //! Open a composer transaction on all active SurfaceComposerClients. static void openGlobalTransaction(); //! Close a composer transaction on all active SurfaceComposerClients. static void closeGlobalTransaction(bool synchronous = false); //! Flag the currently open transaction as an animation transaction. static void setAnimationTransaction(); status_t hide(const sp& id); status_t show(const sp& id); status_t setFlags(const sp& id, uint32_t flags, uint32_t mask); status_t setTransparentRegionHint(const sp& id, const Region& transparent); status_t setLayer(const sp& id, int32_t layer); status_t setAlpha(const sp& id, float alpha=1.0f); status_t setMatrix(const sp& id, float dsdx, float dtdx, float dsdy, float dtdy); status_t setPosition(const sp& id, float x, float y); status_t setSize(const sp& id, uint32_t w, uint32_t h); status_t setCrop(const sp& id, const Rect& crop); status_t setLayerStack(const sp& id, uint32_t layerStack); status_t destroySurface(const sp& id); status_t clearLayerFrameStats(const sp& token) const; status_t getLayerFrameStats(const sp& token, FrameStats* outStats) const; static status_t clearAnimationFrameStats(); static status_t getAnimationFrameStats(FrameStats* outStats); static void setDisplaySurface(const sp& token, const sp& bufferProducer); static void setDisplayLayerStack(const sp& token, uint32_t layerStack); /* setDisplayProjection() defines the projection of layer stacks * to a given display. * * - orientation defines the display's orientation. * - layerStackRect defines which area of the window manager coordinate * space will be used. * - displayRect defines where on the display will layerStackRect be * mapped to. displayRect is specified post-orientation, that is * it uses the orientation seen by the end-user. */ static void setDisplayProjection(const sp& token, uint32_t orientation, const Rect& layerStackRect, const Rect& displayRect); private: virtual void onFirstRef(); Composer& getComposer(); mutable Mutex mLock; status_t mStatus; sp mClient; Composer& mComposer; }; // --------------------------------------------------------------------------- class ScreenshotClient { public: static status_t capture( const sp& display, const sp& producer, uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform); private: mutable sp mCpuConsumer; mutable sp mProducer; CpuConsumer::LockedBuffer mBuffer; bool mHaveBuffer; public: ScreenshotClient(); ~ScreenshotClient(); // frees the previous screenshot and capture a new one status_t update(const sp& display, bool useIdentityTransform); status_t update(const sp& display, uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform); status_t update(const sp& display, uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform); sp getCpuConsumer() const; // release memory occupied by the screenshot void release(); // pixels are valid until this object is freed or // release() or update() is called void const* getPixels() const; uint32_t getWidth() const; uint32_t getHeight() const; PixelFormat getFormat() const; uint32_t getStride() const; // size of allocated memory in bytes size_t getSize() const; }; // --------------------------------------------------------------------------- }; // namespace android #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H