OSDN Git Service

SurfaceFlinger: add support for secure displays
[android-x86/frameworks-native.git] / services / surfaceflinger / DisplayDevice.h
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
35 struct ANativeWindow;
36
37 namespace android {
38
39 class DisplayInfo;
40 class FramebufferSurface;
41 class LayerBase;
42 class SurfaceFlinger;
43 class HWComposer;
44
45 class DisplayDevice : public LightRefBase<DisplayDevice>
46 {
47 public:
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 DisplayType {
56         DISPLAY_ID_INVALID = -1,
57         DISPLAY_PRIMARY     = HWC_DISPLAY_PRIMARY,
58         DISPLAY_EXTERNAL    = HWC_DISPLAY_EXTERNAL,
59         NUM_DISPLAY_TYPES   = HWC_NUM_DISPLAY_TYPES,
60         DISPLAY_VIRTUAL     = HWC_NUM_DISPLAY_TYPES
61     };
62
63     enum {
64         PARTIAL_UPDATES = 0x00020000, // video driver feature
65         SWAP_RECTANGLE  = 0x00080000,
66     };
67
68     DisplayDevice(
69             const sp<SurfaceFlinger>& flinger,
70             DisplayType type,
71             bool isSecure,
72             const wp<IBinder>& displayToken,
73             const sp<ANativeWindow>& nativeWindow,
74             const sp<FramebufferSurface>& framebufferSurface,
75             EGLConfig config);
76
77     ~DisplayDevice();
78
79     // whether this is a valid object. An invalid DisplayDevice is returned
80     // when an non existing id is requested
81     bool isValid() const;
82
83     // isSecure indicates whether this display can be trusted to display
84     // secure surfaces.
85     bool isSecure() const { return mIsSecure; }
86
87     // Flip the front and back buffers if the back buffer is "dirty".  Might
88     // be instantaneous, might involve copying the frame buffer around.
89     void flip(const Region& dirty) const;
90
91     int         getWidth() const;
92     int         getHeight() const;
93     PixelFormat getFormat() const;
94     uint32_t    getFlags() const;
95
96     EGLSurface  getEGLSurface() const;
97
98     void                    setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
99     const Vector< sp<LayerBase> >& getVisibleLayersSortedByZ() const;
100     bool                    getSecureLayerVisible() const;
101     Region                  getDirtyRegion(bool repaintEverything) const;
102
103     void                    setLayerStack(uint32_t stack);
104     void                    setProjection(int orientation, const Rect& viewport, const Rect& frame);
105
106     int                     getOrientation() const { return mOrientation; }
107     const Transform&        getTransform() const { return mGlobalTransform; }
108     const Rect&             getViewport() const { return mViewport; }
109     const Rect&             getFrame() const { return mFrame; }
110     bool                    needsFiltering() const { return mNeedsFiltering; }
111
112     uint32_t                getLayerStack() const { return mLayerStack; }
113     int32_t                 getDisplayType() const { return mType; }
114     int32_t                 getHwcDisplayId() const { return mHwcDisplayId; }
115     const wp<IBinder>&      getDisplayToken() const { return mDisplayToken; }
116
117     void swapBuffers(HWComposer& hwc) const;
118     status_t compositionComplete() const;
119     
120     // called after h/w composer has completed its set() call
121     void onSwapBuffersCompleted(HWComposer& hwc) const;
122
123     Rect getBounds() const {
124         return Rect(mDisplayWidth, mDisplayHeight);
125     }
126     inline Rect bounds() const { return getBounds(); }
127
128     void setDisplayName(const String8& displayName);
129     const String8& getDisplayName() const { return mDisplayName; }
130
131     static EGLBoolean makeCurrent(EGLDisplay dpy,
132             const sp<const DisplayDevice>& hw, EGLContext ctx);
133
134     static void setViewportAndProjection(const sp<const DisplayDevice>& hw);
135
136     /* ------------------------------------------------------------------------
137      * blank / unblank management
138      */
139     void releaseScreen() const;
140     void acquireScreen() const;
141     bool isScreenAcquired() const;
142     bool canDraw() const;
143
144     /* ------------------------------------------------------------------------
145      * Debugging
146      */
147     uint32_t getPageFlipCount() const;
148     void dump(String8& result, char* buffer, size_t SIZE) const;
149
150 private:
151     void init(EGLConfig config);
152
153     /*
154      *  Constants, set during initialization
155      */
156     sp<SurfaceFlinger> mFlinger;
157     DisplayType mType;
158     int32_t mHwcDisplayId;
159     wp<IBinder> mDisplayToken;
160
161     // ANativeWindow this display is rendering into
162     sp<ANativeWindow> mNativeWindow;
163
164     // set if mNativeWindow is a FramebufferSurface
165     sp<FramebufferSurface> mFramebufferSurface;
166
167     EGLDisplay      mDisplay;
168     EGLSurface      mSurface;
169     EGLContext      mContext;
170     int             mDisplayWidth;
171     int             mDisplayHeight;
172     PixelFormat     mFormat;
173     uint32_t        mFlags;
174     mutable uint32_t mPageFlipCount;
175     String8         mDisplayName;
176     bool            mIsSecure;
177
178     /*
179      * Can only accessed from the main thread, these members
180      * don't need synchronization.
181      */
182
183     // list of visible layers on that display
184     Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
185
186     // Whether we have a visible secure layer on this display
187     bool mSecureLayerVisible;
188
189     // Whether the screen is blanked;
190     mutable int mScreenAcquired;
191
192
193     /*
194      * Transaction state
195      */
196     static status_t orientationToTransfrom(int orientation,
197             int w, int h, Transform* tr);
198
199     void updateGeometryTransform();
200
201     uint32_t mLayerStack;
202     int mOrientation;
203     Rect mViewport;
204     Rect mFrame;
205     Transform mGlobalTransform;
206     bool mNeedsFiltering;
207 };
208
209 }; // namespace android
210
211 #endif // ANDROID_DISPLAY_DEVICE_H