DisplayDevice.h revision 92a979a92c34b7de609ce2b1662c73bb8a2728b9
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 "Transform.h"
32
33namespace android {
34
35class DisplayInfo;
36class FramebufferSurface;
37class LayerBase;
38class SurfaceFlinger;
39class SurfaceTextureClient;
40
41class DisplayDevice
42{
43public:
44    // region in layer-stack space
45    mutable Region dirtyRegion;
46    // region in screen space
47    mutable Region swapRegion;
48    // region in screen space
49    Region undefinedRegion;
50
51    enum {
52        DISPLAY_ID_MAIN = 0,
53        DISPLAY_ID_HDMI = 1
54    };
55
56    enum {
57        PARTIAL_UPDATES = 0x00020000, // video driver feature
58        SWAP_RECTANGLE  = 0x00080000,
59    };
60
61    DisplayDevice();
62
63    DisplayDevice(
64            const sp<SurfaceFlinger>& flinger,
65            int dpy,
66            const sp<SurfaceTextureClient>& surface,
67            EGLConfig config);
68
69    ~DisplayDevice();
70
71    // must be called when this object is no longer needed. this will
72    // render the associated EGLSurface invalid.
73    void terminate();
74
75    // whether this is a valid object. An invalid DisplayDevice is returned
76    // when an non existing id is requested
77    bool isValid() const;
78
79    // Flip the front and back buffers if the back buffer is "dirty".  Might
80    // be instantaneous, might involve copying the frame buffer around.
81    void flip(const Region& dirty) const;
82
83    float       getDpiX() const;
84    float       getDpiY() const;
85    float       getRefreshRate() const;
86    float       getDensity() const;
87    int         getWidth() const;
88    int         getHeight() const;
89    PixelFormat getFormat() const;
90    uint32_t    getFlags() const;
91    nsecs_t     getRefreshPeriod() const;
92    status_t    getInfo(DisplayInfo* info) const;
93
94    EGLSurface  getEGLSurface() const;
95
96    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
97    Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
98    bool                    getSecureLayerVisible() const;
99
100    status_t                setOrientation(int orientation);
101    int                     getOrientation() const { return mOrientation; }
102    const Transform&        getTransform() const { return mGlobalTransform; }
103    uint32_t                getLayerStack() const { return mLayerStack; }
104
105    status_t compositionComplete() const;
106
107    Rect getBounds() const {
108        return Rect(mDisplayWidth, mDisplayHeight);
109    }
110    inline Rect bounds() const { return getBounds(); }
111
112    static void makeCurrent(const DisplayDevice& hw, EGLContext ctx);
113
114    /* ------------------------------------------------------------------------
115     * blank / unplank management
116     */
117    void releaseScreen() const;
118    void acquireScreen() const;
119    bool isScreenAcquired() const;
120    bool canDraw() const;
121
122    /* ------------------------------------------------------------------------
123     * Debugging
124     */
125    uint32_t getPageFlipCount() const;
126    void dump(String8& res) const;
127
128    inline bool operator < (const DisplayDevice& rhs) const {
129        return mId < rhs.mId;
130    }
131
132private:
133    void init(EGLConfig config);
134
135    /*
136     *  Constants, set during initialization
137     */
138    sp<SurfaceFlinger> mFlinger;
139    int32_t mId;
140
141    // ANativeWindow this display is rendering into
142    sp<SurfaceTextureClient> mNativeWindow;
143
144    // set if mNativeWindow is a FramebufferSurface
145    sp<FramebufferSurface> mFramebufferSurface;
146
147    EGLDisplay      mDisplay;
148    EGLSurface      mSurface;
149    EGLContext      mContext;
150    float           mDpiX;
151    float           mDpiY;
152    float           mRefreshRate;
153    float           mDensity;
154    int             mDisplayWidth;
155    int             mDisplayHeight;
156    PixelFormat     mFormat;
157    uint32_t        mFlags;
158    mutable uint32_t mPageFlipCount;
159    nsecs_t         mRefreshPeriod;
160
161    /*
162     * Can only accessed from the main thread, these members
163     * don't need synchronization.
164     */
165
166    // list of visible layers on that display
167    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
168
169    // Whether we have a visible secure layer on this display
170    bool mSecureLayerVisible;
171
172    // Whether the screen is blanked;
173    mutable int mScreenAcquired;
174
175
176    /*
177     * Transaction state
178     */
179    static status_t orientationToTransfrom(int orientation, int w, int h,
180            Transform* tr);
181    Transform mGlobalTransform;
182    int mOrientation;
183    uint32_t mLayerStack;
184};
185
186}; // namespace android
187
188#endif // ANDROID_DISPLAY_DEVICE_H
189