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