DisplayDevice.h revision da8d0a5c0cf9d41915d3b106cad4aaec3e767c11
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    void                    setLayerStack(uint32_t stack);
97    void                    setOrientation(int orientation);
98    void                    setViewport(const Rect& viewport);
99    void                    setFrame(const Rect& frame);
100
101    int                     getOrientation() const { return mOrientation; }
102    const Transform&        getTransform() const { return mGlobalTransform; }
103    const Rect&             getViewport() const { return mViewport; }
104    const Rect&             getFrame() const { return mFrame; }
105
106    uint32_t                getLayerStack() const { return mLayerStack; }
107    int32_t                 getDisplayType() const { return mType; }
108    int32_t                 getHwcDisplayId() const { return mHwcDisplayId; }
109    const wp<IBinder>&      getDisplayToken() const { return mDisplayToken; }
110
111    status_t compositionComplete() const;
112
113    Rect getBounds() const {
114        return Rect(mDisplayWidth, mDisplayHeight);
115    }
116    inline Rect bounds() const { return getBounds(); }
117
118    static EGLBoolean makeCurrent(EGLDisplay dpy,
119            const sp<const DisplayDevice>& hw, EGLContext ctx);
120
121    /* ------------------------------------------------------------------------
122     * blank / unplank management
123     */
124    void releaseScreen() const;
125    void acquireScreen() const;
126    bool isScreenAcquired() const;
127    bool canDraw() const;
128
129    /* ------------------------------------------------------------------------
130     * Debugging
131     */
132    uint32_t getPageFlipCount() const;
133    void dump(String8& res) const;
134
135private:
136    void init(EGLConfig config);
137
138    /*
139     *  Constants, set during initialization
140     */
141    sp<SurfaceFlinger> mFlinger;
142    DisplayType mType;
143    int32_t mHwcDisplayId;
144    wp<IBinder> mDisplayToken;
145
146    // ANativeWindow this display is rendering into
147    sp<ANativeWindow> mNativeWindow;
148
149    // set if mNativeWindow is a FramebufferSurface
150    sp<FramebufferSurface> mFramebufferSurface;
151
152    EGLDisplay      mDisplay;
153    EGLSurface      mSurface;
154    EGLContext      mContext;
155    int             mDisplayWidth;
156    int             mDisplayHeight;
157    PixelFormat     mFormat;
158    uint32_t        mFlags;
159    mutable uint32_t mPageFlipCount;
160
161    /*
162     * Can only accessed from the main thread, these members
163     * don't need synchronization.
164     */
165
166    // list of visible layers on that display
167    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
168
169    // Whether we have a visible secure layer on this display
170    bool mSecureLayerVisible;
171
172    // Whether the screen is blanked;
173    mutable int mScreenAcquired;
174
175
176    /*
177     * Transaction state
178     */
179    static status_t orientationToTransfrom(int orientation,
180            int w, int h, Transform* tr);
181
182    void updateGeometryTransform();
183
184    uint32_t mLayerStack;
185    int mOrientation;
186    Rect mViewport;
187    Rect mFrame;
188    Transform mGlobalTransform;
189};
190
191}; // namespace android
192
193#endif // ANDROID_DISPLAY_DEVICE_H
194