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