SurfaceFlinger.h revision 8b33f032327f8de0dcc0e6d0d43ed80f834b51f6
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
17edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#ifndef ANDROID_SURFACE_FLINGER_H
18edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#define ANDROID_SURFACE_FLINGER_H
19edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
20edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <stdint.h>
21edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <sys/types.h>
22edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
23921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <EGL/egl.h>
24921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <GLES/gl.h>
25921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
2699ed22412db547c59d3da08114d9d5a586442b30Glenn Kasten#include <cutils/compiler.h>
2799ed22412db547c59d3da08114d9d5a586442b30Glenn Kasten
28edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/Atomic.h>
29edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <utils/Errors.h>
3099b49840d309727678b77403d6cc9f920111623fMathias Agopian#include <utils/KeyedVector.h>
31076b1cc3a9b90aa5b381a1ed268ca0b548444c9bMathias Agopian#include <utils/RefBase.h>
3299b49840d309727678b77403d6cc9f920111623fMathias Agopian#include <utils/SortedVector.h>
3399b49840d309727678b77403d6cc9f920111623fMathias Agopian#include <utils/threads.h>
34edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
35a1e6bc864fb821c1b470b7aad9b75c441f54eeb4Mathias Agopian#include <binder/BinderService.h>
3699b49840d309727678b77403d6cc9f920111623fMathias Agopian#include <binder/IMemory.h>
37375f56363a8737119ce2222dcfaacbe1cf733fc0Mathias Agopian
38edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#include <ui/PixelFormat.h>
39921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
4090ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/IGraphicBufferAlloc.h>
4190ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/ISurfaceComposer.h>
4290ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/ISurfaceComposerClient.h>
43edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
44921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include <private/gui/LayerState.h>
45edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
46921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian#include "Barrier.h"
47f1d8e87b09abf963cd5b6a026194c1940fadb7b4Mathias Agopian#include "MessageQueue.h"
48f1d8e87b09abf963cd5b6a026194c1940fadb7b4Mathias Agopian
49edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectnamespace android {
50edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
51edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
52edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
53edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectclass Client;
54d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianclass DisplayEventConnection;
55921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass DisplayHardware;
56d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianclass EventThread;
57edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectclass Layer;
58921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass LayerBase;
59921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass LayerBaseClient;
60b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopianclass LayerDim;
61118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopianclass LayerScreenshot;
62921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass SurfaceTextureClient;
63a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopianstruct surface_flinger_cblk_t;
64edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
65edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
66edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
67921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass GraphicBufferAlloc : public BnGraphicBufferAlloc {
689a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennispublic:
699a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    GraphicBufferAlloc();
709a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    virtual ~GraphicBufferAlloc();
719a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis    virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
72d9e8c64c3dce1612eb948a5c16ba4ff62202b423Mathias Agopian        PixelFormat format, uint32_t usage, status_t* error);
739a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis};
749a78c90cd46b2a3bd637b056873149d3b94384b4Jamie Gennis
75edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
76edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
77edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectenum {
78921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    eTransactionNeeded = 0x01, eTraversalNeeded = 0x02
79edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
80edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
81921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianclass SurfaceFlinger : public BinderService<SurfaceFlinger>,
82921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian                       public BnSurfaceComposer,
83921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian                       private IBinder::DeathRecipient,
84921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian                       private Thread
85edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project{
86edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Projectpublic:
87921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    static char const* getServiceName() {
88921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        return "SurfaceFlinger";
89921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    }
90118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
91921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    SurfaceFlinger();
9299ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian
93921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // post an asynchronous message to the main thread
94921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0,
95921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t flags = 0);
96118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
97921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // post a synchronous message to the main thread
98921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0,
99921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t flags = 0);
100118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
101921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // force full composition on all displays
102921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void repaintEverything();
103b7e930db175c192464cebdeb49eb56cf6dd60114Mathias Agopian
104921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // renders content on given display to a texture. thread-safe version.
105921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t renderScreenToTexture(DisplayID dpy, GLuint* textureName,
106921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        GLfloat* uOut, GLfloat* vOut);
1079575f60722f7a4f54384fe0be6938a8de48dc23aJamie Gennis
108921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // renders content on given display to a texture, w/o acquiring main lock
109921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t renderScreenToTextureLocked(DisplayID dpy, GLuint* textureName,
110921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        GLfloat* uOut, GLfloat* vOut);
111a49126087b4494f4ef50873f3a3f6727265f6621Mathias Agopian
112921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // returns the default Display
113921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    const DisplayHardware& getDefaultDisplayHardware() const {
114921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        return getDisplayHardware(0);
115921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    }
116118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
117921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called on the main thread by MessageQueue when an internal message
118921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // is received
119921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // TODO: this should be made accessible only to MessageQueue
120921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void onMessageReceived(int32_t what);
121118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
122921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // utility function to delete a texture on the main thread
123921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void deleteTextureAsync(GLuint texture);
1241f339ff3875afad128a8e16ee6395c5fad295826Mathias Agopian
1251f339ff3875afad128a8e16ee6395c5fad295826Mathias Agopianprivate:
12696f0819f81293076e652792794a961543e6750d7Mathias Agopian    friend class Client;
127d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    friend class DisplayEventConnection;
128edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    friend class LayerBase;
129edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    friend class LayerBaseClient;
130edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    friend class Layer;
131edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
132921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // We're reference counted, never destroy SurfaceFlinger directly
133921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual ~SurfaceFlinger();
134edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
135921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
136921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Internal data structures
137921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
138118d0245ee0a3b107055782aa8b555404b6f0280Mathias Agopian
139921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    class LayerVector : public SortedVector<sp<LayerBase> > {
140edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    public:
141921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        LayerVector();
142921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        LayerVector(const LayerVector& rhs);
143921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        virtual int do_compare(const void* lhs, const void* rhs) const;
144edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    };
145edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
146edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    struct State {
147921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        State();
148921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        LayerVector layersSortedByZ;
149921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint8_t orientation;
150921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint8_t orientationFlags;
151edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project    };
152edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
153921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
154921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * IBinder interface
155921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
156921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t onTransact(uint32_t code, const Parcel& data,
157921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        Parcel* reply, uint32_t flags);
158921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t dump(int fd, const Vector<String16>& args);
159edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
160921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
161921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * ISurfaceComposer interface
162921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
163921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual sp<ISurfaceComposerClient> createConnection();
164921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc();
165921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual sp<IMemoryHeap> getCblk() const;
166921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void bootFinished();
167921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void setTransactionState(const Vector<ComposerState>& state,
1688b33f032327f8de0dcc0e6d0d43ed80f834b51f6Mathias Agopian            const Vector<DisplayState>& displays, uint32_t flags);
169921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual bool authenticateSurfaceTexture(
170921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        const sp<ISurfaceTexture>& surface) const;
171921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual sp<IDisplayEventConnection> createDisplayEventConnection();
172921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t captureScreen(DisplayID dpy, sp<IMemoryHeap>* heap,
173921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t* width, uint32_t* height, PixelFormat* format,
174921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ,
175921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t maxLayerZ);
176921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t turnElectronBeamOff(int32_t mode);
177921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t turnElectronBeamOn(int32_t mode);
178921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called when screen needs to turn off
179921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void blank();
180921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called when screen is turning back on
181921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void unblank();
182921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void connectDisplay(const sp<ISurfaceTexture> display);
1831b03149f3533db04e72e088d3fdd09d0087ca594Mathias Agopian
184921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
185921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * DeathRecipient interface
186921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
187921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void binderDied(const wp<IBinder>& who);
18899ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian
189921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
190921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Thread interface
191921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
192921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual bool threadLoop();
193921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual status_t readyToRun();
194921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    virtual void onFirstRef();
195921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
196921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
197921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Message handling
198921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
199921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void waitForEvent();
200921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void signalTransaction();
201921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void signalLayerUpdate();
202921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void signalRefresh();
203921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
204921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called on the main thread in response to screenReleased()
205921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void onScreenReleased();
206921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called on the main thread in response to screenAcquired()
207921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void onScreenAcquired();
208921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
209921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleMessageTransaction();
210921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleMessageInvalidate();
211921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleMessageRefresh();
212921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
213921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region handleTransaction(uint32_t transactionFlags);
214921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region handleTransactionLocked(uint32_t transactionFlags);
215921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
216921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* handlePageFilp: this is were we latch a new buffer
217921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * if available and compute the dirty region.
218921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * The return value is the dirty region expressed in the
219921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * window manager's coordinate space (or the layer's state
220921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * space, which is the same thing), in particular the dirty
221921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * region is independent from a specific display's orientation.
222921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
223921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region handlePageFlip();
224921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
225921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleRefresh();
226921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleWorkList(const DisplayHardware& hw);
227921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void handleRepaint(const DisplayHardware& hw);
228921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
229921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
230921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Transactions
231921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
232921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t getTransactionFlags(uint32_t flags);
233921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t peekTransactionFlags(uint32_t flags);
234921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t setTransactionFlags(uint32_t flags);
235921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void commitTransaction();
236921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t setClientStateLocked(const sp<Client>& client,
237921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        const layer_state_t& s);
238921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
239921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
240921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Layer management
241921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
242921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<ISurface> createLayer(ISurfaceComposerClient::surface_data_t* params,
243921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        const String8& name, const sp<Client>& client, DisplayID display,
244921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t w, uint32_t h, PixelFormat format, uint32_t flags);
245921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
246921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<Layer> createNormalLayer(const sp<Client>& client, DisplayID display,
247921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format);
248921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
249921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<LayerDim> createDimLayer(const sp<Client>& client, DisplayID display,
250921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t w, uint32_t h, uint32_t flags);
251921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
252921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<LayerScreenshot> createScreenshotLayer(const sp<Client>& client,
253921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        DisplayID display, uint32_t w, uint32_t h, uint32_t flags);
254921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
255921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called in response to the window-manager calling
256921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // ISurfaceComposerClient::destroySurface()
257921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // The specified layer is first placed in a purgatory list
258921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // until all references from the client are released.
259921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t onLayerRemoved(const sp<Client>& client, SurfaceID sid);
260921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
261921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // called when all clients have released all their references to
262921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // this layer meaning it is entirely safe to destroy all
263921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // resources associated to this layer.
264921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t onLayerDestroyed(const wp<LayerBaseClient>& layer);
265921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
266921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // remove a layer from SurfaceFlinger immediately
267921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t removeLayer(const sp<LayerBase>& layer);
268edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
269921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // add a layer to SurfaceFlinger
270921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    ssize_t addClientLayer(const sp<Client>& client,
271921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        const sp<LayerBaseClient>& lbc);
272921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
273921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t removeLayer_l(const sp<LayerBase>& layer);
274921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t purgatorizeLayer_l(const sp<LayerBase>& layer);
275921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
276921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
277921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Boot animation, on/off animations and screen capture
278921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
279921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
280921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void startBootAnim();
281921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
282921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t captureScreenImplLocked(DisplayID dpy, sp<IMemoryHeap>* heap,
283921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t* width, uint32_t* height, PixelFormat* format,
284921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ,
285921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        uint32_t maxLayerZ);
286921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
287921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t turnElectronBeamOffImplLocked(int32_t mode);
288921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t turnElectronBeamOnImplLocked(int32_t mode);
289921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t electronBeamOffAnimationImplLocked();
290921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    status_t electronBeamOnAnimationImplLocked();
291921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
292921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
293921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * EGL
294921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
295921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    static status_t selectConfigForPixelFormat(EGLDisplay dpy,
296921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        EGLint const* attrs, PixelFormat format, EGLConfig* outConfig);
297921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId);
298921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    static EGLContext createGLContext(EGLDisplay disp, EGLConfig config);
299921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void initializeGL(EGLDisplay display, EGLSurface surface);
300921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t getMaxTextureSize() const;
301921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    uint32_t getMaxViewportDims() const;
302921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
303921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
304921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Display management
305921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
306921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    const DisplayHardware& getDisplayHardware(DisplayID dpy) const {
307921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        return *mDisplayHardwares[dpy];
308921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    }
309921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
310921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
311921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Compositing
312921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
313921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void invalidateHwcGeometry();
314921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void computeVisibleRegions(const LayerVector& currentLayers,
315921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        Region& dirtyRegion, Region& wormholeRegion);
316921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void postFramebuffer();
317921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void setupHardwareComposer(const DisplayHardware& hw);
318921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void composeSurfaces(const DisplayHardware& hw, const Region& dirty);
319921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void setInvalidateRegion(const Region& reg);
320921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region getAndClearInvalidateRegion();
321921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void drawWormhole() const;
322921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    GLuint getProtectedTexName() const {
323921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        return mProtectedTexName;
324921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    }
325921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
326921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
327921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Debugging & dumpsys
328921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
329921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void debugFlashRegions(const DisplayHardware& hw);
330921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void listLayersLocked(const Vector<String16>& args, size_t& index,
331921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        String8& result, char* buffer, size_t SIZE) const;
332921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void dumpStatsLocked(const Vector<String16>& args, size_t& index,
333921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        String8& result, char* buffer, size_t SIZE) const;
334921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void clearStatsLocked(const Vector<String16>& args, size_t& index,
335921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian        String8& result, char* buffer, size_t SIZE) const;
336921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    void dumpAllLocked(String8& result, char* buffer, size_t SIZE) const;
337921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
338921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
339921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Attributes
340921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
341921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
342921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // access must be protected by mStateLock
343921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mutable Mutex mStateLock;
344921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    State mCurrentState;
345921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    volatile int32_t mTransactionFlags;
346921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Condition mTransactionCV;
347921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    SortedVector<sp<LayerBase> > mLayerPurgatory;
348921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    bool mTransationPending;
349921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Vector<sp<LayerBase> > mLayersPendingRemoval;
350921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
351921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // protected by mStateLock (but we could use another lock)
352921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    DisplayHardware* mDisplayHardwares[1];
353921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    bool mLayersRemoved;
354921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
355921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // access must be protected by mInvalidateLock
356921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mutable Mutex mInvalidateLock;
357921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region mInvalidateRegion;
358921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
359921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // constant members (no synchronization needed for access)
360921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<IMemoryHeap> mServerHeap;
361921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    surface_flinger_cblk_t* mServerCblk;
362921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    GLuint mWormholeTexName;
363921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    GLuint mProtectedTexName;
364921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    nsecs_t mBootTime;
365921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<EventThread> mEventThread;
366921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    GLint mMaxViewportDims[2];
367921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    GLint mMaxTextureSize;
368921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    EGLContext mEGLContext;
369921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    EGLConfig mEGLConfig;
370921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
371921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // Can only accessed from the main thread, these members
372921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // don't need synchronization
373921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    State mDrawingState;
374921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region mDirtyRegion;
375921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region mDirtyRegionRemovedLayer;
376921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region mSwapRegion;
377921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Region mWormholeRegion;
378921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    bool mVisibleRegionsDirty;
379921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    bool mHwWorkListDirty;
380921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    int32_t mElectronBeamAnimationMode;
381921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
382921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // don't use a lock for these, we don't care
383921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    int mDebugRegion;
384921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    int mDebugDDMS;
385921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    int mDebugDisableHWC;
386921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    int mDebugDisableTransformHint;
387921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    volatile nsecs_t mDebugInSwapBuffers;
388921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    nsecs_t mLastSwapBufferTime;
389921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    volatile nsecs_t mDebugInTransaction;
390921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    nsecs_t mLastTransactionTime;
391921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    bool mBootFinished;
392921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
393921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // these are thread safe
394921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mutable MessageQueue mEventQueue;
395921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mutable Barrier mReadyToRunBarrier;
396921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
397921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    // protected by mDestroyedLayerLock;
398921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    mutable Mutex mDestroyedLayerLock;
399921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    Vector<LayerBase const *> mDestroyedLayers;
400921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
401921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    /* ------------------------------------------------------------------------
402921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     * Feature prototyping
403921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian     */
404921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian
405921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    EGLSurface getExternalDisplaySurface() const;
406921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    sp<SurfaceTextureClient> mExternalDisplayNativeWindow;
407921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    EGLSurface mExternalDisplaySurface;
408921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopianpublic:
409921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian    surface_flinger_cblk_t* getControlBlock() const;
410edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project};
411edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
412edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project// ---------------------------------------------------------------------------
413edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project}; // namespace android
414edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project
415edbf3b6af777b721cd2a1ef461947e51e88241e1The Android Open Source Project#endif // ANDROID_SURFACE_FLINGER_H
416