DisplayDevice.h revision 3ee454a7bef8bd3d1c9cdd9d17108eb80ebadf2a
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 DisplayType {
55        DISPLAY_ID_INVALID = -1,
56        DISPLAY_PRIMARY     = HWC_DISPLAY_PRIMARY,
57        DISPLAY_EXTERNAL    = HWC_DISPLAY_EXTERNAL,
58        NUM_DISPLAY_TYPES   = HWC_NUM_DISPLAY_TYPES,
59        DISPLAY_VIRTUAL     = HWC_NUM_DISPLAY_TYPES
60    };
61
62    enum {
63        PARTIAL_UPDATES = 0x00020000, // video driver feature
64        SWAP_RECTANGLE  = 0x00080000,
65    };
66
67    DisplayDevice(
68            const sp<SurfaceFlinger>& flinger,
69            DisplayType type, const wp<IBinder>& displayToken,
70            const sp<ANativeWindow>& nativeWindow,
71            const sp<FramebufferSurface>& framebufferSurface,
72            EGLConfig config);
73
74    ~DisplayDevice();
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    int         getWidth() const;
85    int         getHeight() const;
86    PixelFormat getFormat() const;
87    uint32_t    getFlags() const;
88
89    EGLSurface  getEGLSurface() const;
90
91    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
92    const Vector< sp<LayerBase> >& getVisibleLayersSortedByZ() const;
93    bool                    getSecureLayerVisible() const;
94    Region                  getDirtyRegion(bool repaintEverything) const;
95
96    status_t                setOrientation(int orientation);
97    void                    setLayerStack(uint32_t stack);
98
99    int                     getOrientation() const { return mOrientation; }
100    const Transform&        getTransform() const { return mGlobalTransform; }
101    uint32_t                getLayerStack() const { return mLayerStack; }
102    int32_t                 getDisplayType() const { return mType; }
103    int32_t                 getHwcDisplayId() const { return mHwcDisplayId; }
104    const wp<IBinder>&      getDisplayToken() const { return mDisplayToken; }
105
106    status_t compositionComplete() const;
107
108    Rect getBounds() const {
109        return Rect(mDisplayWidth, mDisplayHeight);
110    }
111    inline Rect bounds() const { return getBounds(); }
112
113    static void makeCurrent(const sp<const DisplayDevice>& hw, EGLContext ctx);
114
115    /* ------------------------------------------------------------------------
116     * blank / unplank management
117     */
118    void releaseScreen() const;
119    void acquireScreen() const;
120    bool isScreenAcquired() const;
121    bool canDraw() const;
122
123    /* ------------------------------------------------------------------------
124     * Debugging
125     */
126    uint32_t getPageFlipCount() const;
127    void dump(String8& res) const;
128
129private:
130    void init(EGLConfig config);
131
132    /*
133     *  Constants, set during initialization
134     */
135    sp<SurfaceFlinger> mFlinger;
136    DisplayType mType;
137    int32_t mHwcDisplayId;
138    wp<IBinder> mDisplayToken;
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