DisplayDevice.h revision d8552d796cbcb9a89711fc8f97b34838da5cbdb7
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
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
64    DisplayDevice(
65            const sp<SurfaceFlinger>& flinger,
66            int dpy,
67            const sp<ANativeWindow>& surface,
68            EGLConfig config);
69
70    ~DisplayDevice();
71
72    // must be called when this object is no longer needed. this will
73    // render the associated EGLSurface invalid.
74    void terminate();
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    float       getDpiX() const;
85    float       getDpiY() const;
86    float       getDensity() const;
87    int         getWidth() const;
88    int         getHeight() const;
89    PixelFormat getFormat() const;
90    uint32_t    getFlags() const;
91
92    EGLSurface  getEGLSurface() const;
93
94    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
95    Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
96    bool                    getSecureLayerVisible() const;
97
98    status_t                setOrientation(int orientation);
99    int                     getOrientation() const { return mOrientation; }
100    const Transform&        getTransform() const { return mGlobalTransform; }
101    uint32_t                getLayerStack() const { return mLayerStack; }
102
103    status_t compositionComplete() const;
104
105    Rect getBounds() const {
106        return Rect(mDisplayWidth, mDisplayHeight);
107    }
108    inline Rect bounds() const { return getBounds(); }
109
110    static void makeCurrent(const DisplayDevice& hw, EGLContext ctx);
111
112    /* ------------------------------------------------------------------------
113     * blank / unplank management
114     */
115    void releaseScreen() const;
116    void acquireScreen() const;
117    bool isScreenAcquired() const;
118    bool canDraw() const;
119
120    /* ------------------------------------------------------------------------
121     * Debugging
122     */
123    uint32_t getPageFlipCount() const;
124    void dump(String8& res) const;
125
126    inline bool operator < (const DisplayDevice& rhs) const {
127        return mId < rhs.mId;
128    }
129
130private:
131    void init(EGLConfig config);
132
133    /*
134     *  Constants, set during initialization
135     */
136    sp<SurfaceFlinger> mFlinger;
137    int32_t mId;
138
139    // ANativeWindow this display is rendering into
140    sp<ANativeWindow> mNativeWindow;
141
142    // set if mNativeWindow is a FramebufferSurface
143    sp<FramebufferSurface> mFramebufferSurface;
144
145    EGLDisplay      mDisplay;
146    EGLSurface      mSurface;
147    EGLContext      mContext;
148    float           mDpiX;
149    float           mDpiY;
150    float           mDensity;
151    int             mDisplayWidth;
152    int             mDisplayHeight;
153    PixelFormat     mFormat;
154    uint32_t        mFlags;
155    mutable uint32_t mPageFlipCount;
156
157    /*
158     * Can only accessed from the main thread, these members
159     * don't need synchronization.
160     */
161
162    // list of visible layers on that display
163    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
164
165    // Whether we have a visible secure layer on this display
166    bool mSecureLayerVisible;
167
168    // Whether the screen is blanked;
169    mutable int mScreenAcquired;
170
171
172    /*
173     * Transaction state
174     */
175    static status_t orientationToTransfrom(int orientation, int w, int h,
176            Transform* tr);
177    Transform mGlobalTransform;
178    int mOrientation;
179    uint32_t mLayerStack;
180};
181
182}; // namespace android
183
184#endif // ANDROID_DISPLAY_DEVICE_H
185