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