2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_DISPLAY_DEVICE_H
18 #define ANDROID_DISPLAY_DEVICE_H
20 #include "Transform.h"
25 #include <ui/PixelFormat.h>
27 #include <ui/Region.h>
30 #include <EGL/eglext.h>
33 #include <binder/IBinder.h>
34 #include <utils/RefBase.h>
36 #include <utils/Mutex.h>
37 #include <utils/String8.h>
38 #include <utils/Timers.h>
40 #include <hardware/hwcomposer_defs.h>
53 class IGraphicBufferProducer;
58 class DisplayDevice : public LightRefBase<DisplayDevice>
61 // region in layer-stack space
62 mutable Region dirtyRegion;
63 // region in screen space
64 mutable Region swapRegion;
65 // region in screen space
66 Region undefinedRegion;
67 bool lastCompositionHadVisibleLayers;
70 DISPLAY_ID_INVALID = -1,
71 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
72 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
73 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
74 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
78 PARTIAL_UPDATES = 0x00020000, // video driver feature
79 SWAP_RECTANGLE = 0x00080000,
83 NO_LAYER_STACK = 0xFFFFFFFF,
87 const sp<SurfaceFlinger>& flinger,
94 const wp<IBinder>& displayToken,
95 const sp<DisplaySurface>& displaySurface,
96 const sp<IGraphicBufferProducer>& producer,
101 // whether this is a valid object. An invalid DisplayDevice is returned
102 // when an non existing id is requested
103 bool isValid() const;
105 // isSecure indicates whether this display can be trusted to display
107 bool isSecure() const { return mIsSecure; }
109 // Flip the front and back buffers if the back buffer is "dirty". Might
110 // be instantaneous, might involve copying the frame buffer around.
111 void flip(const Region& dirty) const;
113 int getWidth() const;
114 int getHeight() const;
116 PixelFormat getFormat() const;
118 uint32_t getFlags() const;
120 EGLSurface getEGLSurface() const;
122 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
123 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
124 Region getDirtyRegion(bool repaintEverything) const;
126 void setLayerStack(uint32_t stack);
127 void setDisplaySize(const int newWidth, const int newHeight);
128 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
130 int getOrientation() const { return mOrientation; }
131 uint32_t getOrientationTransform() const;
132 static uint32_t getPrimaryDisplayOrientationTransform();
133 const Transform& getTransform() const { return mGlobalTransform; }
134 const Rect getViewport() const { return mViewport; }
135 const Rect getFrame() const { return mFrame; }
136 const Rect& getScissor() const { return mScissor; }
137 bool needsFiltering() const { return mNeedsFiltering; }
139 uint32_t getLayerStack() const { return mLayerStack; }
140 int32_t getDisplayType() const { return mType; }
141 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
142 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
144 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
145 // machine happy without actually queueing a buffer if nothing has changed
146 status_t beginFrame(bool mustRecompose) const;
148 status_t prepareFrame(HWComposer& hwc);
150 status_t prepareFrame(const HWComposer& hwc) const;
153 void swapBuffers(HWComposer& hwc) const;
155 status_t compositionComplete() const;
158 // called after h/w composer has completed its set() call
160 void onSwapBuffersCompleted() const;
162 void onSwapBuffersCompleted(HWComposer& hwc) const;
165 Rect getBounds() const {
166 return Rect(mDisplayWidth, mDisplayHeight);
168 inline Rect bounds() const { return getBounds(); }
170 void setDisplayName(const String8& displayName);
171 const String8& getDisplayName() const { return mDisplayName; }
173 EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
174 void setViewportAndProjection() const;
176 const sp<Fence>& getClientTargetAcquireFence() const;
178 /* ------------------------------------------------------------------------
179 * Display power mode management.
181 int getPowerMode() const;
182 void setPowerMode(int mode);
183 bool isDisplayOn() const;
186 android_color_mode_t getActiveColorMode() const;
187 void setActiveColorMode(android_color_mode_t mode);
190 /* ------------------------------------------------------------------------
191 * Display active config management.
193 int getActiveConfig() const;
194 void setActiveConfig(int mode);
196 // release HWC resources (if any) for removable displays
197 void disconnect(HWComposer& hwc);
199 /* ------------------------------------------------------------------------
202 uint32_t getPageFlipCount() const;
203 void dump(String8& result) const;
207 * Constants, set during initialization
209 sp<SurfaceFlinger> mFlinger;
211 int32_t mHwcDisplayId;
212 wp<IBinder> mDisplayToken;
214 // ANativeWindow this display is rendering into
215 sp<ANativeWindow> mNativeWindow;
216 sp<DisplaySurface> mDisplaySurface;
227 mutable uint32_t mPageFlipCount;
228 String8 mDisplayName;
232 * Can only accessed from the main thread, these members
233 * don't need synchronization.
236 // list of visible layers on that display
237 Vector< sp<Layer> > mVisibleLayersSortedByZ;
242 static status_t orientationToTransfrom(int orientation,
243 int w, int h, Transform* tr);
245 uint32_t mLayerStack;
247 static uint32_t sPrimaryDisplayOrientation;
248 // user-provided visible area of the layer stack
250 // user-provided rectangle where mViewport gets mapped to
252 // pre-computed scissor to apply to the display
254 Transform mGlobalTransform;
255 bool mNeedsFiltering;
256 // Current power mode
258 // Current active config
261 // current active color mode
262 android_color_mode_t mActiveColorMode;
266 }; // namespace android
268 #endif // ANDROID_DISPLAY_DEVICE_H