DisplayDevice.h revision f435863467ab407f2a482604beed5fa6f0144c62
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 {
55        DISPLAY_ID_MAIN = HWC_DISPLAY_PRIMARY,
56        DISPLAY_ID_HDMI = HWC_DISPLAY_EXTERNAL,
57        DISPLAY_ID_COUNT = HWC_NUM_DISPLAY_TYPES
58    };
59
60    enum {
61        PARTIAL_UPDATES = 0x00020000, // video driver feature
62        SWAP_RECTANGLE  = 0x00080000,
63    };
64
65    DisplayDevice(
66            const sp<SurfaceFlinger>& flinger,
67            int32_t dpy, int32_t hwcDisplayId,
68            const sp<ANativeWindow>& nativeWindow,
69            const sp<FramebufferSurface>& framebufferSurface,
70            EGLConfig config);
71
72    ~DisplayDevice();
73
74    // whether this is a valid object. An invalid DisplayDevice is returned
75    // when an non existing id is requested
76    bool isValid() const;
77
78    // Flip the front and back buffers if the back buffer is "dirty".  Might
79    // be instantaneous, might involve copying the frame buffer around.
80    void flip(const Region& dirty) const;
81
82    int         getWidth() const;
83    int         getHeight() const;
84    PixelFormat getFormat() const;
85    uint32_t    getFlags() const;
86
87    EGLSurface  getEGLSurface() const;
88
89    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
90    Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
91    bool                    getSecureLayerVisible() const;
92    Region                  getDirtyRegion(bool repaintEverything) const;
93
94    status_t                setOrientation(int orientation);
95    void                    setLayerStack(uint32_t stack);
96
97    int                     getOrientation() const { return mOrientation; }
98    const Transform&        getTransform() const { return mGlobalTransform; }
99    uint32_t                getLayerStack() const { return mLayerStack; }
100    int32_t                 getDisplayId() const { return mId; }
101    int32_t                 getHwcDisplayId() const { return mHwcDisplayId; }
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 sp<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    int32_t mHwcDisplayId;
139
140    // ANativeWindow this display is rendering into
141    sp<ANativeWindow> mNativeWindow;
142
143    // set if mNativeWindow is a FramebufferSurface
144    sp<FramebufferSurface> mFramebufferSurface;
145
146    EGLDisplay      mDisplay;
147    EGLSurface      mSurface;
148    EGLContext      mContext;
149    int             mDisplayWidth;
150    int             mDisplayHeight;
151    PixelFormat     mFormat;
152    uint32_t        mFlags;
153    mutable uint32_t mPageFlipCount;
154
155    /*
156     * Can only accessed from the main thread, these members
157     * don't need synchronization.
158     */
159
160    // list of visible layers on that display
161    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
162
163    // Whether we have a visible secure layer on this display
164    bool mSecureLayerVisible;
165
166    // Whether the screen is blanked;
167    mutable int mScreenAcquired;
168
169
170    /*
171     * Transaction state
172     */
173    static status_t orientationToTransfrom(int orientation, int w, int h,
174            Transform* tr);
175    Transform mGlobalTransform;
176    int mOrientation;
177    uint32_t mLayerStack;
178};
179
180}; // namespace android
181
182#endif // ANDROID_DISPLAY_DEVICE_H
183