DisplayDevice.h revision 0f2f5ff75b7b48ceb64270655ee6b62d09bf4d00
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_HARDWARE_H
18#define ANDROID_DISPLAY_HARDWARE_H
19
20#include <stdlib.h>
21
22#include <ui/PixelFormat.h>
23#include <ui/Region.h>
24
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
29
30#include <utils/Mutex.h>
31#include <utils/Timers.h>
32
33#include "Transform.h"
34
35#include "DisplayHardware/DisplayDeviceBase.h"
36
37namespace android {
38
39class DisplayInfo;
40class FramebufferSurface;
41class LayerBase;
42class SurfaceFlinger;
43class SurfaceTextureClient;
44
45class DisplayDevice : public DisplayDeviceBase
46{
47public:
48    // region in layer-stack space
49    mutable Region dirtyRegion;
50    // region in screen space
51    mutable Region swapRegion;
52    // region in screen space
53    Region undefinedRegion;
54
55    enum {
56        PARTIAL_UPDATES = 0x00020000, // video driver feature
57        SWAP_RECTANGLE  = 0x00080000,
58    };
59
60    DisplayDevice(
61            const sp<SurfaceFlinger>& flinger,
62            int dpy,
63            const sp<SurfaceTextureClient>& surface,
64            EGLConfig config);
65
66    virtual ~DisplayDevice();
67
68    // Flip the front and back buffers if the back buffer is "dirty".  Might
69    // be instantaneous, might involve copying the frame buffer around.
70    void flip(const Region& dirty) const;
71
72    void onVSyncReceived(nsecs_t timestamp);
73
74    float       getDpiX() const;
75    float       getDpiY() const;
76    float       getRefreshRate() const;
77    float       getDensity() const;
78    int         getWidth() const;
79    int         getHeight() const;
80    PixelFormat getFormat() const;
81    uint32_t    getFlags() const;
82    nsecs_t     getRefreshPeriod() const;
83    nsecs_t     getRefreshTimestamp() const;
84    status_t    getInfo(DisplayInfo* info) const;
85
86    EGLSurface  getEGLSurface() const;
87
88    void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
89    Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
90    bool                    getSecureLayerVisible() const;
91
92    status_t                setOrientation(int orientation);
93    int                     getOrientation() const { return mOrientation; }
94    const Transform&        getTransform() const { return mGlobalTransform; }
95    uint32_t                getLayerStack() const { return mLayerStack; }
96
97
98    uint32_t getPageFlipCount() const;
99    EGLDisplay getEGLDisplay() const { return mDisplay; }
100
101    void dump(String8& res) const;
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 DisplayDevice& hw, EGLContext ctx);
111
112private:
113    void init(EGLConfig config);
114
115    /*
116     *  Constants, set during initialization
117     */
118    sp<SurfaceFlinger> mFlinger;
119    int mDisplayId;
120    // ANativeWindow this display is rendering into
121    sp<SurfaceTextureClient> mNativeWindow;
122    // set if mNativeWindow is a FramebufferSurface
123    sp<FramebufferSurface> mFramebufferSurface;
124
125
126    EGLDisplay      mDisplay;
127    EGLSurface      mSurface;
128    EGLContext      mContext;
129    float           mDpiX;
130    float           mDpiY;
131    float           mRefreshRate;
132    float           mDensity;
133    int             mDisplayWidth;
134    int             mDisplayHeight;
135    PixelFormat     mFormat;
136    uint32_t        mFlags;
137    mutable uint32_t mPageFlipCount;
138
139    nsecs_t         mRefreshPeriod;
140
141    /*
142     * Can only accessed from the main thread, these members
143     * don't need synchronization.
144     */
145    // list of visible layers on that display
146    Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
147    // Whether we have a visible secure layer on this display
148    bool mSecureLayerVisible;
149
150
151    // this used to be in GraphicPlane
152    static status_t orientationToTransfrom(int orientation, int w, int h,
153            Transform* tr);
154    Transform mGlobalTransform;
155    int mOrientation;
156
157    uint32_t mLayerStack;
158
159
160    /*
161     *  protected by mLock
162     */
163    mutable Mutex mLock;
164    mutable nsecs_t mLastHwVSync;
165};
166
167}; // namespace android
168
169#endif // ANDROID_DISPLAY_HARDWARE_H
170