1edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project/*
2edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
3edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
4edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * you may not use this file except in compliance with the License.
6edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * You may obtain a copy of the License at
7edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
8edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project *
10edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * See the License for the specific language governing permissions and
14edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project * limitations under the License.
15edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project */
16edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
1790ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
1890ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdint.h>
21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/types.h>
228e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw#include <unordered_map>
23edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
24dd3423c6247965bf67ea30c75e484a6f5d72b1a2Mathias Agopian#include <binder/IBinder.h>
25dd3423c6247965bf67ea30c75e484a6f5d72b1a2Mathias Agopian
26edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/RefBase.h>
27b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#include <utils/Singleton.h>
28b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian#include <utils/SortedVector.h>
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/threads.h>
30edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
31d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav#include <ui/FrameStats.h>
32fd997e0969100418b4df8b8d97d21d497afa76c3Peiyong Lin#include <ui/GraphicTypes.h>
33edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <ui/PixelFormat.h>
349cce325fae8adcf7560a28eef394489f09bad74dMathias Agopian
35abe815dd6978b718c04f6e22e1a893d2b51d11a1Mathias Agopian#include <gui/CpuConsumer.h>
36e3c697fb929c856b59fa56a8e05a2a7eba187c3dMathias Agopian#include <gui/SurfaceControl.h>
3713fdc49516d17f41e64e62e73c313b0928bf13ccchaviw#include <math/vec3.h>
384cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr#include <gui/LayerState.h>
39edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
40edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
41edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
42edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
43edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
44a2362b44b4053344bdf29481ce4d65705f9346acColin Crossstruct DisplayInfo;
45c4f471e75a8ec64ec34e3f2944a5a756215d0becDan Stozaclass HdrCapabilities;
4641f673c9b3aac0d96e41c928845c39186d565212Mathias Agopianclass ISurfaceComposerClient;
472adaf04fab35cf47c824d74d901b54094e01ccd3Andy McFaddenclass IGraphicBufferProducer;
48a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopianclass Region;
49b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian
50b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian// ---------------------------------------------------------------------------
51b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian
52d4784a3b90f849e8732968d45886fb0c8f0d8cf3Mathias Agopianclass SurfaceComposerClient : public RefBase
53edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
54698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    friend class Composer;
556c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hallpublic:
56edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                SurfaceComposerClient();
57f3cf4bcfa2c558f03e178f7044d3cb12fa0e73edJorim Jaggi                SurfaceComposerClient(const sp<ISurfaceComposerClient>& client);
581db73f66624e7d151710483dd58e03eed672f064Robert Carr                SurfaceComposerClient(const sp<IGraphicBufferProducer>& parent);
59edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    virtual     ~SurfaceComposerClient();
60edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
61edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // Always make sure we could initialize
62edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    status_t    initCheck() const;
63edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
64edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // Return the connection of this client
65edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    sp<IBinder> connection() const;
666c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hall
67edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // Forcibly remove connection before all references have gone away.
68edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    void        dispose();
69edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
70e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian    // callback when the composer is dies
71e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
72e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian            void* cookie = NULL, uint32_t flags = 0);
73e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian
747f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // Get a list of supported configurations for a given display
757f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    static status_t getDisplayConfigs(const sp<IBinder>& display,
767f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza            Vector<DisplayInfo>* configs);
777f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza
787f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // Get the DisplayInfo for the currently-active configuration
797f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    static status_t getDisplayInfo(const sp<IBinder>& display,
807f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza            DisplayInfo* info);
817f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza
827f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // Get the index of the current active configuration (relative to the list
837f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // returned by getDisplayInfo)
847f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    static int getActiveConfig(const sp<IBinder>& display);
857f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza
867f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // Set a new active configuration using an index relative to the list
877f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    // returned by getDisplayInfo
887f7da32569f8e0b3d383a40b95f8ac1d55afd801Dan Stoza    static status_t setActiveConfig(const sp<IBinder>& display, int id);
89e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian
9028f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright    // Gets the list of supported color modes for the given display
9128f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright    static status_t getDisplayColorModes(const sp<IBinder>& display,
92fd997e0969100418b4df8b8d97d21d497afa76c3Peiyong Lin            Vector<ui::ColorMode>* outColorModes);
9328f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright
9428f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright    // Gets the active color mode for the given display
95fd997e0969100418b4df8b8d97d21d497afa76c3Peiyong Lin    static ui::ColorMode getActiveColorMode(const sp<IBinder>& display);
9628f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright
9728f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright    // Sets the active color mode for the given display
98fd997e0969100418b4df8b8d97d21d497afa76c3Peiyong Lin    static status_t setActiveColorMode(const sp<IBinder>& display,
99fd997e0969100418b4df8b8d97d21d497afa76c3Peiyong Lin            ui::ColorMode colorMode);
10028f24d0ab481bd9c6fd5618414fee694e837c5c6Michael Wright
1012c9b11f0291210c9b9513a1a0cce6afebd361b3bPrashant Malani    /* Triggers screen on/off or low power mode and waits for it to complete */
1022c9b11f0291210c9b9513a1a0cce6afebd361b3bPrashant Malani    static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
1032a09bb321930e1f782599ec902bca1db58b9af77Jeff Brown
104edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // ------------------------------------------------------------------------
105edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    // surface creation / destruction
106edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
107edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    //! Create a surface
10801b766839e06c32540cef100e3a7710d12cf1eefMathias Agopian    sp<SurfaceControl> createSurface(
109285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian            const String8& name,// name of the surface
110285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian            uint32_t w,         // width in pixel
111285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian            uint32_t h,         // height in pixel
112285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian            PixelFormat format, // pixel-format desired
113479c60c85c40fd3536b0c88036e838dc1a4c56a0Albert Chaulk            uint32_t flags = 0, // usage flags
114479c60c85c40fd3536b0c88036e838dc1a4c56a0Albert Chaulk            SurfaceControl* parent = nullptr, // parent
115ccd348460ca25890a8fb709e82e6f780e3ce878erongliu            int32_t windowType = -1, // from WindowManager.java (STATUS_BAR, INPUT_METHOD, etc.)
116ccd348460ca25890a8fb709e82e6f780e3ce878erongliu            int32_t ownerUid = -1 // UID of the task
117285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian    );
118285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian
1193b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr    status_t createSurfaceChecked(
1203b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            const String8& name,// name of the surface
1213b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            uint32_t w,         // width in pixel
1223b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            uint32_t h,         // height in pixel
1233b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            PixelFormat format, // pixel-format desired
1243b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            sp<SurfaceControl>* outSurface,
1253b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            uint32_t flags = 0, // usage flags
1263b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr            SurfaceControl* parent = nullptr, // parent
127ccd348460ca25890a8fb709e82e6f780e3ce878erongliu            int32_t windowType = -1, // from WindowManager.java (STATUS_BAR, INPUT_METHOD, etc.)
128ccd348460ca25890a8fb709e82e6f780e3ce878erongliu            int32_t ownerUid = -1 // UID of the task
1293b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr    );
1303b382ed2e8a6a79698fb8e65913946bba109d836Robert Carr
1316c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hall    //! Create a virtual display
132dd3cb84cfbe8068790c6233b5829fae9c4a0ee93Jamie Gennis    static sp<IBinder> createDisplay(const String8& displayName, bool secure);
133285dbde2e0cd0057be070ded3be8f5f453147edcMathias Agopian
1346c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hall    //! Destroy a virtual display
1356c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hall    static void destroyDisplay(const sp<IBinder>& display);
1366c913be9ca95fd6b556d056e165a4ba6dc69795bJesse Hall
1379d4e3d2f42e93e2d12bacabe97d307d30c3c20ddJeff Brown    //! Get the token for the existing default displays.
1389d4e3d2f42e93e2d12bacabe97d307d30c3c20ddJeff Brown    //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
1399d4e3d2f42e93e2d12bacabe97d307d30c3c20ddJeff Brown    static sp<IBinder> getBuiltInDisplay(int32_t id);
1409d4e3d2f42e93e2d12bacabe97d307d30c3c20ddJeff Brown
141c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju    static status_t enableVSyncInjections(bool enable);
142c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju
143c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju    static status_t injectVSync(nsecs_t when);
144c1ba5c4649554e744844b07cfe402b42fbe12ff3Sahil Dhanju
1458e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw    struct SCHash {
1468e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw        std::size_t operator()(const sp<SurfaceControl>& sc) const {
1478e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw            return std::hash<SurfaceControl *>{}(sc.get());
1488e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw        }
1498e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw    };
1508e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw
1514cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr    class Transaction {
1528e3fe5d6a78d92e0bcbd90ca98cf7b3f9de7512dchaviw        std::unordered_map<sp<SurfaceControl>, ComposerState, SCHash> mComposerStates;
1534cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        SortedVector<DisplayState > mDisplayStates;
1544cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        uint32_t                    mForceSynchronous = 0;
1554cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        uint32_t                    mTransactionNestCount = 0;
1564cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        bool                        mAnimation = false;
1572713c30843816d3511b39b85a2c268a2b7682047Dan Stoza        bool                        mEarlyWakeup = false;
1584cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
1594cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        int mStatus = NO_ERROR;
1604cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
161763ef57459aa9f10f3587581b119fe8d4ece3cd3chaviw        layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
162763ef57459aa9f10f3587581b119fe8d4ece3cd3chaviw        DisplayState& getDisplayState(const sp<IBinder>& token);
1634cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
1644cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr    public:
1654cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction() = default;
1664cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        virtual ~Transaction() = default;
1674cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction(Transaction const& other);
1684cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
1694cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        status_t apply(bool synchronous = false);
1702c5f6d2257075c8b5ced78b07ed8b2c2323f0df2Robert Carr        // Merge another transaction in to this one, clearing other
1712c5f6d2257075c8b5ced78b07ed8b2c2323f0df2Robert Carr        // as if it had been applied.
1722c5f6d2257075c8b5ced78b07ed8b2c2323f0df2Robert Carr        Transaction& merge(Transaction&& other);
1734cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& show(const sp<SurfaceControl>& sc);
1744cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& hide(const sp<SurfaceControl>& sc);
1754cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setPosition(const sp<SurfaceControl>& sc,
1764cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                float x, float y);
1774cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setSize(const sp<SurfaceControl>& sc,
1784cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                uint32_t w, uint32_t h);
1794cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setLayer(const sp<SurfaceControl>& sc,
1804cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                int32_t z);
1814cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
1824cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Sets a Z order relative to the Surface specified by "relativeTo" but
1834cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // without becoming a full child of the relative. Z-ordering works exactly
1844cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // as if it were a child however.
1854cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        //
1864cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // As a nod to sanity, only non-child surfaces may have a relative Z-order.
1874cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        //
1884cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // This overrides any previous call and is overriden by any future calls
1894cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // to setLayer.
1904cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        //
1914cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // If the relative is removed, the Surface will have no layer and be
1924cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // invisible, until the next time set(Relative)Layer is called.
1934cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setRelativeLayer(const sp<SurfaceControl>& sc,
1944cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<IBinder>& relativeTo, int32_t z);
1954cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setFlags(const sp<SurfaceControl>& sc,
1964cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                uint32_t flags, uint32_t mask);
1974cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc,
1984cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const Region& transparentRegion);
1994cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setAlpha(const sp<SurfaceControl>& sc,
2004cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                float alpha);
2014cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setMatrix(const sp<SurfaceControl>& sc,
2024cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                float dsdx, float dtdx, float dtdy, float dsdy);
2034cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop);
2044cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setFinalCrop(const sp<SurfaceControl>& sc, const Rect& crop);
2054cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack);
2064cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Defers applying any changes made in this transaction until the Layer
2074cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // identified by handle reaches the given frameNumber. If the Layer identified
2084cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // by handle is removed, then we will apply this transaction regardless of
2094cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // what frame number has been reached.
2104cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& deferTransactionUntil(const sp<SurfaceControl>& sc,
2114cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<IBinder>& handle,
2124cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                uint64_t frameNumber);
2134cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // A variant of deferTransactionUntil which identifies the Layer we wait for by
2144cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Surface instead of Handle. Useful for clients which may not have the
2154cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // SurfaceControl for some of their Surfaces. Otherwise behaves identically.
2164cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& deferTransactionUntil(const sp<SurfaceControl>& sc,
2174cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<Surface>& barrierSurface,
2184cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                uint64_t frameNumber);
2194cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Reparents all children of this layer to the new parent handle.
2204cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& reparentChildren(const sp<SurfaceControl>& sc,
2214cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<IBinder>& newParentHandle);
2224cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2234cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        /// Reparents the current layer to the new parent handle. The new parent must not be null.
2244cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // This can be used instead of reparentChildren if the caller wants to
2254cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // only re-parent a specific child.
2264cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& reparent(const sp<SurfaceControl>& sc,
2274cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<IBinder>& newParentHandle);
2284cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2294cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color);
2304cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2314cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Detaches all child surfaces (and their children recursively)
2324cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // from their SurfaceControl.
2334cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // The child SurfaceControls will not throw exceptions or return errors,
2344cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // but transactions will have no effect.
2354cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // The child surfaces will continue to follow their parent surfaces,
2364cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // and remain eligible for rendering, but their relative state will be
2374cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // frozen. We use this in the WindowManager, in app shutdown/relaunch
2384cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // scenarios, where the app would otherwise clean up its child Surfaces.
2394cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Sometimes the WindowManager needs to extend their lifetime slightly
2404cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // in order to perform an exit animation or prevent flicker.
2414cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& detachChildren(const sp<SurfaceControl>& sc);
2424cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // Set an override scaling mode as documented in <system/window.h>
2434cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // the override scaling mode will take precedence over any client
2444cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // specified scaling mode. -1 will clear the override scaling mode.
2454cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc,
2464cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                int32_t overrideScalingMode);
2474cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2484cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // If the size changes in this transaction, all geometry updates specified
2494cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // in this transaction will not complete until a buffer of the new size
2504cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // arrives. As some elements normally apply immediately, this enables
2514cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        // freezing the total geometry of a surface until a resize is completed.
2524cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        Transaction& setGeometryAppliesWithResize(const sp<SurfaceControl>& sc);
2534cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
254ca27f2500cff74ae1e08b3ae06f18e9b3414ffb7chaviw        Transaction& destroySurface(const sp<SurfaceControl>& sc);
255ca27f2500cff74ae1e08b3ae06f18e9b3414ffb7chaviw
2564cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        status_t setDisplaySurface(const sp<IBinder>& token,
2574cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const sp<IGraphicBufferProducer>& bufferProducer);
2584cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2594cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
2604cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
2614cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        /* setDisplayProjection() defines the projection of layer stacks
2624cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * to a given display.
2634cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         *
2644cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * - orientation defines the display's orientation.
2654cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * - layerStackRect defines which area of the window manager coordinate
2664cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * space will be used.
2674cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * - displayRect defines where on the display will layerStackRect be
2684cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * mapped to. displayRect is specified post-orientation, that is
2694cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         * it uses the orientation seen by the end-user.
2704cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr         */
2714cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        void setDisplayProjection(const sp<IBinder>& token,
2724cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                uint32_t orientation,
2734cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const Rect& layerStackRect,
2744cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr                const Rect& displayRect);
2754cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
2764cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr        void setAnimationTransaction();
2772713c30843816d3511b39b85a2c268a2b7682047Dan Stoza        void setEarlyWakeup();
2784cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr    };
27982364e3cea0bf88fa8147766433329b3dd5148b8Robert Carr
280ac9fa427d4a86745e60a5f7fd8e3ea340c4db907Mathias Agopian    status_t    destroySurface(const sp<IBinder>& id);
281edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
282d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav    status_t clearLayerFrameStats(const sp<IBinder>& token) const;
283d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav    status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
284d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav    static status_t clearAnimationFrameStats();
285d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav    static status_t getAnimationFrameStats(FrameStats* outStats);
286d85084b2b65828442eafaff9b811e9b6c9ca9fadSvetoslav
287c4f471e75a8ec64ec34e3f2944a5a756215d0becDan Stoza    static status_t getHdrCapabilities(const sp<IBinder>& display,
288c4f471e75a8ec64ec34e3f2944a5a756215d0becDan Stoza            HdrCapabilities* outCapabilities);
289c4f471e75a8ec64ec34e3f2944a5a756215d0becDan Stoza
29000e8c7a88a5b9c4104a71013a713acd3e4d3b77bMathias Agopian    static void setDisplayProjection(const sp<IBinder>& token,
29100e8c7a88a5b9c4104a71013a713acd3e4d3b77bMathias Agopian            uint32_t orientation,
29200e8c7a88a5b9c4104a71013a713acd3e4d3b77bMathias Agopian            const Rect& layerStackRect,
29300e8c7a88a5b9c4104a71013a713acd3e4d3b77bMathias Agopian            const Rect& displayRect);
294e57f292595bec48f65c8088b00ff6beea01217e9Mathias Agopian
2954cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr    inline sp<ISurfaceComposerClient> getClient() { return mClient; }
2964cdc58f6840d15b4952149d2b345ec1f97d505bcRobert Carr
297631f358d348ea5e7813ca01f86fc9f2a6536add6Mathias Agopianprivate:
298d4784a3b90f849e8732968d45886fb0c8f0d8cf3Mathias Agopian    virtual void onFirstRef();
299edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
300698c0873cf2e07bdc7fd1e72169aee2a19fa40d7Mathias Agopian    mutable     Mutex                       mLock;
301edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project                status_t                    mStatus;
3027e27f05739c8a2655cf0f7faea35614ce0a50278Mathias Agopian                sp<ISurfaceComposerClient>  mClient;
3031db73f66624e7d151710483dd58e03eed672f064Robert Carr                wp<IGraphicBufferProducer>  mParent;
304edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
305edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
306d4784a3b90f849e8732968d45886fb0c8f0d8cf3Mathias Agopian// ---------------------------------------------------------------------------
30774c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian
30840482ff650751819d4104c10a30974838168438cChavi Weingartenclass ScreenshotClient {
3092a9fc493dfdba67108e4335bb1fe931bc1e2a025Mathias Agopianpublic:
310c18790018be5d7ea7061ccbc81f3044e74adc823Dan Stoza    // if cropping isn't required, callers may pass in a default Rect, e.g.:
311c18790018be5d7ea7061ccbc81f3044e74adc823Dan Stoza    //   capture(display, producer, Rect(), reqWidth, ...);
31240482ff650751819d4104c10a30974838168438cChavi Weingarten    static status_t capture(const sp<IBinder>& display, Rect sourceCrop, uint32_t reqWidth,
31340482ff650751819d4104c10a30974838168438cChavi Weingarten                            uint32_t reqHeight, int32_t minLayerZ, int32_t maxLayerZ,
31440482ff650751819d4104c10a30974838168438cChavi Weingarten                            bool useIdentityTransform, uint32_t rotation,
31540482ff650751819d4104c10a30974838168438cChavi Weingarten                            sp<GraphicBuffer>* outBuffer);
316578038fc49f83c4c8c4accdce49df404ecd6ad02Robert Carr    static status_t captureLayers(const sp<IBinder>& layerHandle, Rect sourceCrop, float frameScale,
31740482ff650751819d4104c10a30974838168438cChavi Weingarten                                  sp<GraphicBuffer>* outBuffer);
318578038fc49f83c4c8c4accdce49df404ecd6ad02Robert Carr    static status_t captureChildLayers(const sp<IBinder>& layerHandle, Rect sourceCrop,
319578038fc49f83c4c8c4accdce49df404ecd6ad02Robert Carr                                       float frameScale, sp<GraphicBuffer>* outBuffer);
32074c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian};
32174c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian
32274c40c0a273dbfd7d10617c4cc1b0c066bfc812eMathias Agopian// ---------------------------------------------------------------------------
323edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android
324edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
32590ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
326