DisplayDevice.h revision 00e8c7a88a5b9c4104a71013a713acd3e4d3b77b
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_DISPLAY_DEVICE_H
18#define ANDROID_DISPLAY_DEVICE_H
19
20#include <stdlib.h>
21
22#include <ui/PixelFormat.h>
23#include <ui/Region.h>
24
25#include <EGL/egl.h>
26#include <EGL/eglext.h>
27
28#include <utils/Mutex.h>
29#include <utils/Timers.h>
30
31#include <hardware/hwcomposer_defs.h>
32
33#include "Transform.h"
34
35struct ANativeWindow;
36
37namespace android {
38
39class DisplayInfo;
40class FramebufferSurface;
41class LayerBase;
42class SurfaceFlinger;
43
44class DisplayDevice : public LightRefBase<DisplayDevice>
45{
46public:
47    // region in layer-stack space
48    mutable Region dirtyRegion;
49    // region in screen space
50    mutable Region swapRegion;
51    // region in screen space
52    Region undefinedRegion;
53
54    enum DisplayType {
55        DISPLAY_ID_INVALID = -1,
56        DISPLAY_PRIMARY     = HWC_DISPLAY_PRIMARY,
57        DISPLAY_EXTERNAL    = HWC_DISPLAY_EXTERNAL,
58        NUM_DISPLAY_TYPES   = HWC_NUM_DISPLAY_TYPES,
59        DISPLAY_VIRTUAL     = HWC_NUM_DISPLAY_TYPES
60    };
61
62    enum {
63        PARTIAL_UPDATES = 0x00020000, // video driver feature
64        SWAP_RECTANGLE  = 0x00080000,
65    };
66
67    DisplayDevice(
68            const sp<SurfaceFlinger>& flinger,
69            DisplayType type, const wp<IBinder>& displayToken,
70            const sp<ANativeWindow>& nativeWindow,
71            const sp<FramebufferSurface>& framebufferSurface,
72            EGLConfig config);
73
74    ~DisplayDevice();
75
76    // whether this is a valid object. An invalid DisplayDevice is returned
77    // when an non existing id is requested
78    bool isValid() const;
79
80    // Flip the front and back buffers if the back buffer is "dirty".  Might
81    // be instantaneous, might involve copying the frame buffer around.
82    void flip(const Region& dirty) const;
83
84    int         getWidth() const;
85    int         getHeight() const;
86    PixelFormat getFormat() const;
87    uint32_t    getFlags() const;
88
89    EGLSurface  getEGLSurface() const;
90
91    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
92    const Vector< sp<LayerBase> >& getVisibleLayersSortedByZ() const;
93    bool                    getSecureLayerVisible() const;
94    Region                  getDirtyRegion(bool repaintEverything) const;
95
96    void                    setLayerStack(uint32_t stack);
97    void                    setProjection(int orientation, const Rect& viewport, const Rect& frame);
98
99    int                     getOrientation() const { return mOrientation; }
100    const Transform&        getTransform() const { return mGlobalTransform; }
101    const Rect&             getViewport() const { return mViewport; }
102    const Rect&             getFrame() const { return mFrame; }
103
104    uint32_t                getLayerStack() const { return mLayerStack; }
105    int32_t                 getDisplayType() const { return mType; }
106    int32_t                 getHwcDisplayId() const { return mHwcDisplayId; }
107    const wp<IBinder>&      getDisplayToken() const { return mDisplayToken; }
108
109    status_t compositionComplete() const;
110
111    Rect getBounds() const {
112        return Rect(mDisplayWidth, mDisplayHeight);
113    }
114    inline Rect bounds() const { return getBounds(); }
115
116    static EGLBoolean makeCurrent(EGLDisplay dpy,
117            const sp<const DisplayDevice>& hw, EGLContext ctx);
118
119    /* ------------------------------------------------------------------------
120     * blank / unplank management
121     */
122    void releaseScreen() const;
123    void acquireScreen() const;
124    bool isScreenAcquired() const;
125    bool canDraw() const;
126
127    /* ------------------------------------------------------------------------
128     * Debugging
129     */
130    uint32_t getPageFlipCount() const;
131    void dump(String8& res) const;
132
133private:
134    void init(EGLConfig config);
135
136    /*
137     *  Constants, set during initialization
138     */
139    sp<SurfaceFlinger> mFlinger;
140    DisplayType mType;
141    int32_t mHwcDisplayId;
142    wp<IBinder> mDisplayToken;
143
144    // ANativeWindow this display is rendering into
145    sp<ANativeWindow> mNativeWindow;
146
147    // set if mNativeWindow is a FramebufferSurface
148    sp<FramebufferSurface> mFramebufferSurface;
149
150    EGLDisplay      mDisplay;
151    EGLSurface      mSurface;
152    EGLContext      mContext;
153    int             mDisplayWidth;
154    int             mDisplayHeight;
155    PixelFormat     mFormat;
156    uint32_t        mFlags;
157    mutable uint32_t mPageFlipCount;
158
159    /*
160     * Can only accessed from the main thread, these members
161     * don't need synchronization.
162     */
163
164    // list of visible layers on that display
165    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
166
167    // Whether we have a visible secure layer on this display
168    bool mSecureLayerVisible;
169
170    // Whether the screen is blanked;
171    mutable int mScreenAcquired;
172
173
174    /*
175     * Transaction state
176     */
177    static status_t orientationToTransfrom(int orientation,
178            int w, int h, Transform* tr);
179
180    void updateGeometryTransform();
181
182    uint32_t mLayerStack;
183    int mOrientation;
184    Rect mViewport;
185    Rect mFrame;
186    Transform mGlobalTransform;
187};
188
189}; // namespace android
190
191#endif // ANDROID_DISPLAY_DEVICE_H
192