HWComposer.h revision 27ec5739bc05330e08b02f25b62a8f597bad897a
1a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian/*
2a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Copyright (C) 2010 The Android Open Source Project
3a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian *
4a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * you may not use this file except in compliance with the License.
6a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * You may obtain a copy of the License at
7a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian *
8a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian *
10a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Unless required by applicable law or agreed to in writing, software
11a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * See the License for the specific language governing permissions and
14a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * limitations under the License.
15a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian */
16a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
17a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#ifndef ANDROID_SF_HWCOMPOSER_H
18a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#define ANDROID_SF_HWCOMPOSER_H
19a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
20a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <stdint.h>
21a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <sys/types.h>
22a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
233e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian#include <hardware/hwcomposer_defs.h>
24a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
25921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <utils/Condition.h>
26921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <utils/Mutex.h>
27c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include <utils/StrongPointer.h>
28921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <utils/Thread.h>
29921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <utils/Timers.h>
3022da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h>
31e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian#include <utils/BitSet.h>
32c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian
333eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopianextern "C" int clock_nanosleep(clockid_t clock_id, int flags,
343eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian                           const struct timespec *request,
353eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian                           struct timespec *remain);
363eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
375880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallstruct hwc_composer_device_1;
38b685c542836b93c99cd85053e07696406ea37adbJesse Hallstruct hwc_display_contents_1;
39da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianstruct hwc_layer_1;
403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianstruct hwc_procs;
418b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopianstruct framebuffer_device_t;
423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android {
44a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// ---------------------------------------------------------------------------
45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
46921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass GraphicBuffer;
47da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianclass Fence;
48921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass LayerBase;
491a4d883dcc1725892bfb5c28dec255a233186524Jamie Gennisclass Region;
508372785879d329f592f6883620b5a32d80d74691Mathias Agopianclass String8;
51c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianclass SurfaceFlinger;
528372785879d329f592f6883620b5a32d80d74691Mathias Agopian
53a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianclass HWComposer
54a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{
55a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianpublic:
563eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    class EventHandler {
573eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        friend class HWComposer;
581bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall        virtual void onVSyncReceived(int disp, nsecs_t timestamp) = 0;
59148994e5f33ce240ff24ceb5bc0500b7f2001959Mathias Agopian        virtual void onHotplugReceived(int disp, bool connected) = 0;
603eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    protected:
613eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        virtual ~EventHandler() {}
623eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    };
63a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
641e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    enum {
658f971ff6661c875e7adb3f14731e1579c3c80c62Jesse Hall        MAX_DISPLAYS = HWC_NUM_DISPLAY_TYPES + 1
661e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    };
671e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian
688b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian    HWComposer(
698b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian            const sp<SurfaceFlinger>& flinger,
70b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden            EventHandler& handler);
718b736f138cfd9b239a2c7073347a13c489534ae1Mathias Agopian
72a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    ~HWComposer();
73a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
74a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    status_t initCheck() const;
75a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
76e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // returns a display ID starting at MAX_DISPLAYS, this ID
77e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // is to be used with createWorkList (and all other
78e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // methods requiring an ID below).
79e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // IDs below MAX_DISPLAY are pre-defined and therefore are always valid.
80e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // returns a negative error code if an ID cannot be allocated
81e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    int32_t allocateDisplayId();
82e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian
83e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // recycles the given ID and frees the associated worklist.
84e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // IDs below MAX_DISPLAYS are not recycled
85e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    status_t freeDisplayId(int32_t id);
86e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian
87e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian
88a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    // Asks the HAL what it can do
89e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    status_t prepare();
90a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
91a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian    // commits the list
9230bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian    status_t commit();
93a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
9410fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross    // release hardware resources and blank screen
95c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden    status_t release(int disp) const;
96a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
9710fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross    // acquire hardware resources and unblank screen
98c01a79d77b829e7de86ef137694e8ad708470ca1Andy McFadden    status_t acquire(int disp) const;
9910fbdb6059755f009e02f0ccc2b9d289beb6b086Colin Cross
10027ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden    // reset state when an external, non-virtual display is disconnected
10127ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden    void disconnectDisplay(int disp);
10227ec5739bc05330e08b02f25b62a8f597bad897aAndy McFadden
1033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    // create a work list for numLayers layer. sets HWC_GEOMETRY_CHANGED.
1041e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    status_t createWorkList(int32_t id, size_t numLayers);
105a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
106da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    bool supportsFramebufferTarget() const;
107da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian
108e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // does this display have layers handled by HWC
109e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    bool hasHwcComposition(int32_t id) const;
110e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian
111e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // does this display have layers handled by GLES
112e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    bool hasGlesComposition(int32_t id) const;
1139c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian
114da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    // get the releaseFence file descriptor for the given display
115da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    // the release fence is only valid after commit()
116da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    int getAndResetReleaseFenceFd(int32_t id);
117da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian
1183e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    // needed forward declarations
1193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    class LayerListIterator;
1203e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
121cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian    // return the visual id to be used to find a suitable EGLConfig for
122cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian    // *ALL* displays.
123cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian    int getVisualID() const;
124cde87a3b9d3f8dc15232d927b56ee9e5e520f58dMathias Agopian
125b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    // Forwarding to FB HAL for pre-HWC-1.1 code (see FramebufferSurface).
126da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    int fbPost(int32_t id, const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf);
127b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    int fbCompositionComplete();
128b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    void fbDump(String8& result);
129b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden
1303e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    /*
1313e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * Interface to hardware composer's layers functionality.
1323e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * This abstracts the HAL interface to layers which can evolve in
1333e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * incompatible ways from one release to another.
1343e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * The idea is that we could extend this interface as we add
1353e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * features to h/w composer.
1363e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     */
1373e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    class HWCLayerInterface {
1383e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    protected:
1393e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual ~HWCLayerInterface() { }
1403e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    public:
1413e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual int32_t getCompositionType() const = 0;
1423e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual uint32_t getHints() const = 0;
143ef19414bd8b77a26f5751f3845be79025a8263feJesse Hall        virtual int getAndResetReleaseFenceFd() = 0;
1443e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setDefaultState() = 0;
1453e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setSkip(bool skip) = 0;
1463e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setBlending(uint32_t blending) = 0;
1473e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setTransform(uint32_t transform) = 0;
1483e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setFrame(const Rect& frame) = 0;
1493e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setCrop(const Rect& crop) = 0;
1503e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setVisibleRegionScreen(const Region& reg) = 0;
1513e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual void setBuffer(const sp<GraphicBuffer>& buffer) = 0;
152dc5b485f74edf2d2f31c62054eb6c180421a3adeJesse Hall        virtual void setAcquireFenceFd(int fenceFd) = 0;
153c39736088398a9b4367b30fc307ed7de96ac342eMathias Agopian        virtual void onDisplayed() = 0;
1543e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    };
1553e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1563e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    /*
1573e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * Interface used to implement an iterator to a list
1583e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * of HWCLayer.
1593e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     */
1603e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    class HWCLayer : public HWCLayerInterface {
1613e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        friend class LayerListIterator;
1623e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // select the layer at the given index
1633e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual status_t setLayer(size_t index) = 0;
1643e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual HWCLayer* dup() = 0;
1653e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        static HWCLayer* copy(HWCLayer *rhs) {
1663e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            return rhs ? rhs->dup() : NULL;
1673e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        }
1683e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    protected:
1693e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        virtual ~HWCLayer() { }
1703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    };
1713e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1723e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    /*
1733e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * Iterator through a HWCLayer list.
1743e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     * This behaves more or less like a forward iterator.
1753e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian     */
1763e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    class LayerListIterator {
1773e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        friend struct HWComposer;
1783e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        HWCLayer* const mLayerList;
1793e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        size_t mIndex;
1803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        LayerListIterator() : mLayerList(NULL), mIndex(0) { }
1823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        LayerListIterator(HWCLayer* layer, size_t index)
1843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            : mLayerList(layer), mIndex(index) { }
1853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // we don't allow assignment, because we don't need it for now
1873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        LayerListIterator& operator = (const LayerListIterator& rhs);
1883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    public:
1903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // copy operators
1913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        LayerListIterator(const LayerListIterator& rhs)
1923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            : mLayerList(HWCLayer::copy(rhs.mLayerList)), mIndex(rhs.mIndex) {
1933e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        }
1943e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1953e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        ~LayerListIterator() { delete mLayerList; }
1963e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
1973e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // pre-increment
1983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        LayerListIterator& operator++() {
1993e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            mLayerList->setLayer(++mIndex);
2003e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            return *this;
2013e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        }
2023e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2033e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // dereference
2043e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        HWCLayerInterface& operator * () { return *mLayerList; }
2053e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        HWCLayerInterface* operator -> () { return mLayerList; }
2063e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2073e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        // comparison
2083e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        bool operator == (const LayerListIterator& rhs) const {
2093e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            return mIndex == rhs.mIndex;
2103e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        }
2113e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        bool operator != (const LayerListIterator& rhs) const {
2123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian            return !operator==(rhs);
2133e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian        }
2143e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    };
2153e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2163e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    // Returns an iterator to the beginning of the layer list
2171e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    LayerListIterator begin(int32_t id);
2183e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2193e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    // Returns an iterator to the end of the layer list
2201e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    LayerListIterator end(int32_t id);
2213e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2223e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian
2233eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    // Events handling ---------------------------------------------------------
2243eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
2253eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    enum {
2263eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        EVENT_VSYNC = HWC_EVENT_VSYNC
2273eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    };
2283eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
22903e407270c7ad76632f982c886d0776bed9e9b4cMathias Agopian    void eventControl(int event, int enabled);
2303eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
231b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    // Query display parameters.  Pass in a display index (e.g.
232b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    // HWC_DISPLAY_PRIMARY).
233b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    nsecs_t getRefreshPeriod(int disp) const;
234b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    nsecs_t getRefreshTimestamp(int disp) const;
235db27621e22559a1b16414f890677ef04242fbc3bJesse Hall    uint32_t getWidth(int disp) const;
236db27621e22559a1b16414f890677ef04242fbc3bJesse Hall    uint32_t getHeight(int disp) const;
237b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    uint32_t getFormat(int disp) const;
238b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    float getDpiX(int disp) const;
239b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    float getDpiY(int disp) const;
240f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian    bool isConnected(int disp) const;
241d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian
2423eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    // this class is only used to fake the VSync event on systems that don't
2433eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    // have it.
2443eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    class VSyncThread : public Thread {
2453eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        HWComposer& mHwc;
2463eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        mutable Mutex mLock;
2473eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        Condition mCondition;
2483eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        bool mEnabled;
2493eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        mutable nsecs_t mNextFakeVSync;
2503eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian        nsecs_t mRefreshPeriod;
2512965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian        virtual void onFirstRef();
2522965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian        virtual bool threadLoop();
2533eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    public:
2542965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian        VSyncThread(HWComposer& hwc);
2552965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian        void setEnabled(bool enabled);
2563eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    };
2573eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
2583eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    friend class VSyncThread;
2593eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian
2603eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    // for debugging ----------------------------------------------------------
26122da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian    void dump(String8& out, char* scratch, size_t SIZE,
26222da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian            const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const;
2638372785879d329f592f6883620b5a32d80d74691Mathias Agopian
264a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianprivate:
265b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    void loadHwcModule();
266b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    void loadFbHalModule();
267b685c542836b93c99cd85053e07696406ea37adbJesse Hall
2681e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian    LayerListIterator getLayerIterator(int32_t id, size_t index);
26931d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian
2703e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian    struct cb_context;
27131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian
272bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall    static void hook_invalidate(const struct hwc_procs* procs);
2731bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall    static void hook_vsync(const struct hwc_procs* procs, int disp,
274bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall            int64_t timestamp);
2751bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall    static void hook_hotplug(const struct hwc_procs* procs, int disp,
2761bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall            int connected);
27731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian
2783eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian    inline void invalidate();
2791bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall    inline void vsync(int disp, int64_t timestamp);
2801bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall    inline void hotplug(int disp, int connected);
281c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian
2821604f777d11c40daae8ec91d8ea75625996bfbacMathias Agopian    status_t queryDisplayProperties(int disp);
2831e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian
284da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian    status_t setFramebufferTarget(int32_t id,
285da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian            const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf);
286da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian
287da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian
288e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    struct DisplayData {
289e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        DisplayData() : xdpi(0), ydpi(0), refresh(0),
290f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian            connected(false), hasFbComp(false), hasOvComp(false),
291da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian            capacity(0), list(NULL),
292da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian            framebufferTarget(NULL), fbTargetHandle(NULL) { }
293f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian        ~DisplayData() {
294f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian            free(list);
295f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian        }
296db27621e22559a1b16414f890677ef04242fbc3bJesse Hall        uint32_t width;
297db27621e22559a1b16414f890677ef04242fbc3bJesse Hall        uint32_t height;
298b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden        uint32_t format;    // pixel format from FB hal, for pre-hwc-1.1
299e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        float xdpi;
300e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        float ydpi;
301e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        nsecs_t refresh;
302f5a33928349bebc8eebc9f466618997e98c24e68Mathias Agopian        bool connected;
303e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        bool hasFbComp;
304e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian        bool hasOvComp;
305f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian        size_t capacity;
306f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian        hwc_display_contents_1* list;
307da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian        hwc_layer_1* framebufferTarget;
308da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian        buffer_handle_t fbTargetHandle;
309e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    };
310e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian
3115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    sp<SurfaceFlinger>              mFlinger;
312b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden    framebuffer_device_t*           mFbDev;
3135880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    struct hwc_composer_device_1*   mHwc;
314b685c542836b93c99cd85053e07696406ea37adbJesse Hall    // invariant: mLists[0] != NULL iff mHwc != NULL
315e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    // mLists[i>0] can be NULL. that display is to be ignored
316b685c542836b93c99cd85053e07696406ea37adbJesse Hall    struct hwc_display_contents_1*  mLists[MAX_DISPLAYS];
317e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian    DisplayData                     mDisplayData[MAX_DISPLAYS];
3188f971ff6661c875e7adb3f14731e1579c3c80c62Jesse Hall    size_t                          mNumDisplays;
3191e26087493ac0e7d7dc6dea8ad85cfef08b3271fMathias Agopian
3205880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    cb_context*                     mCBContext;
3215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    EventHandler&                   mEventHandler;
3225880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    size_t                          mVSyncCount;
3235880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    sp<VSyncThread>                 mVSyncThread;
3245880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall    bool                            mDebugForceFakeVSync;
325f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian    BitSet32                        mAllocatedDisplayIDs;
326d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian
327d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian    // protected by mLock
328d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian    mutable Mutex mLock;
329d3ee231eddce0b69ec5e35188dbd0f4a2c3b9ac3Mathias Agopian    mutable nsecs_t mLastHwVSync;
330a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian};
331a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
332a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// ---------------------------------------------------------------------------
333a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android
334a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian
335a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#endif // ANDROID_SF_HWCOMPOSER_H
336