blob: 8695a44eca38af9735e37d4a6835e7bcf1146b96 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
Mathias Agopiand3ee2312012-08-02 14:01:42 -070017#ifndef ANDROID_DISPLAY_DEVICE_H
18#define ANDROID_DISPLAY_DEVICE_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdlib.h>
21
22#include <ui/PixelFormat.h>
23#include <ui/Region.h>
24
25#include <EGL/egl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026#include <EGL/eglext.h>
27
Mathias Agopian86303202012-07-24 22:46:10 -070028#include <utils/Mutex.h>
Mathias Agopian4f4f0942013-08-19 17:26:18 -070029#include <utils/String8.h>
Mathias Agopian86303202012-07-24 22:46:10 -070030#include <utils/Timers.h>
31
Mathias Agopianf4358632012-08-22 17:16:19 -070032#include <hardware/hwcomposer_defs.h>
33
Mathias Agopian1b031492012-06-20 17:51:20 -070034#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070035
Mathias Agopiand8552d72012-08-04 21:39:11 -070036struct ANativeWindow;
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
Jesse Hall646f5412014-08-07 22:19:07 -070040struct DisplayInfo;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070041class DisplaySurface;
Jesse Hall9e663de2013-08-16 14:28:37 -070042class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080043class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070044class SurfaceFlinger;
Mathias Agopianda27af92012-09-13 18:17:13 -070045class HWComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
Mathias Agopian028a7572012-08-05 01:23:51 -070047class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048{
49public:
Mathias Agopian87baae12012-07-31 12:38:26 -070050 // region in layer-stack space
51 mutable Region dirtyRegion;
52 // region in screen space
53 mutable Region swapRegion;
54 // region in screen space
55 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070056 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070057
Mathias Agopian3ee454a2012-08-27 16:28:24 -070058 enum DisplayType {
59 DISPLAY_ID_INVALID = -1,
60 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
61 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
Jesse Hall9e663de2013-08-16 14:28:37 -070062 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
63 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
Mathias Agopian92a979a2012-08-02 18:32:23 -070064 };
65
66 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070067 PARTIAL_UPDATES = 0x00020000, // video driver feature
68 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 };
70
Jesse Hall01e29052013-02-19 16:13:35 -080071 enum {
72 NO_LAYER_STACK = 0xFFFFFFFF,
73 };
74
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070075 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070077 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070078 int32_t hwcId, // negative for non-HWC-composited displays
Jesse Hall19e87292013-12-23 21:02:15 -080079 int format,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070080 bool isSecure,
81 const wp<IBinder>& displayToken,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070082 const sp<DisplaySurface>& displaySurface,
Mathias Agopiandb89edc2013-08-02 01:40:18 -070083 const sp<IGraphicBufferProducer>& producer,
Mathias Agopiana4912602012-07-12 14:25:33 -070084 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085
Mathias Agopian028a7572012-08-05 01:23:51 -070086 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070087
88 // whether this is a valid object. An invalid DisplayDevice is returned
89 // when an non existing id is requested
90 bool isValid() const;
91
Jamie Gennisdd3cb842012-10-19 18:19:11 -070092 // isSecure indicates whether this display can be trusted to display
93 // secure surfaces.
94 bool isSecure() const { return mIsSecure; }
95
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 // Flip the front and back buffers if the back buffer is "dirty". Might
97 // be instantaneous, might involve copying the frame buffer around.
98 void flip(const Region& dirty) const;
99
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 int getWidth() const;
101 int getHeight() const;
102 PixelFormat getFormat() const;
103 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700104
Mathias Agopiana4912602012-07-12 14:25:33 -0700105 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700106
Mathias Agopian13127d82013-03-05 17:47:11 -0800107 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
108 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700109 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700110 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700111
Mathias Agopian28947d72012-08-08 18:51:15 -0700112 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700113 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700114 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700115
Mathias Agopian1b031492012-06-20 17:51:20 -0700116 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700117 uint32_t getOrientationTransform() const;
Mathias Agopian1b031492012-06-20 17:51:20 -0700118 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800119 const Rect getViewport() const { return mViewport; }
120 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700121 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700122 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700123
Mathias Agopian87baae12012-07-31 12:38:26 -0700124 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700125 int32_t getDisplayType() const { return mType; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700126 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700127 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700128
Dan Stoza71433162014-02-04 16:22:36 -0800129 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
130 // machine happy without actually queueing a buffer if nothing has changed
131 status_t beginFrame(bool mustRecompose) const;
Jesse Hall38efe862013-04-06 23:12:29 -0700132 status_t prepareFrame(const HWComposer& hwc) const;
133
Mathias Agopianda27af92012-09-13 18:17:13 -0700134 void swapBuffers(HWComposer& hwc) const;
Mathias Agopian74faca22009-09-17 16:18:16 -0700135 status_t compositionComplete() const;
Jesse Hall01e29052013-02-19 16:13:35 -0800136
Mathias Agopianda27af92012-09-13 18:17:13 -0700137 // called after h/w composer has completed its set() call
138 void onSwapBuffersCompleted(HWComposer& hwc) const;
139
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700140 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700141 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700143 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700145 void setDisplayName(const String8& displayName);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700146 const String8& getDisplayName() const { return mDisplayName; }
147
Mathias Agopian875d8e12013-06-07 15:35:48 -0700148 EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
149 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700150
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700151 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700152 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700153 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700154 int getPowerMode() const;
155 void setPowerMode(int mode);
156 bool isDisplayOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700157
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700158 /* ------------------------------------------------------------------------
159 * Display active config management.
160 */
161 int getActiveConfig() const;
162 void setActiveConfig(int mode);
163
Jesse Hall02d86562013-03-25 14:43:23 -0700164 // release HWC resources (if any) for removable displays
165 void disconnect(HWComposer& hwc);
166
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700167 /* ------------------------------------------------------------------------
168 * Debugging
169 */
170 uint32_t getPageFlipCount() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200171 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700172
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700174 /*
175 * Constants, set during initialization
176 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700177 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700178 DisplayType mType;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700179 int32_t mHwcDisplayId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700180 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700181
Mathias Agopiana4912602012-07-12 14:25:33 -0700182 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700183 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700184 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700185
Michael Lentine47e45402014-07-18 15:34:25 -0700186 EGLConfig mConfig;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 EGLDisplay mDisplay;
188 EGLSurface mSurface;
Mathias Agopian1b031492012-06-20 17:51:20 -0700189 int mDisplayWidth;
190 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191 PixelFormat mFormat;
192 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700193 mutable uint32_t mPageFlipCount;
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700194 String8 mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700195 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700196
Mathias Agopiana4912602012-07-12 14:25:33 -0700197 /*
198 * Can only accessed from the main thread, these members
199 * don't need synchronization.
200 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700201
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700202 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800203 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700204
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700205 // Whether we have a visible secure layer on this display
206 bool mSecureLayerVisible;
207
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700208
209 /*
210 * Transaction state
211 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700212 static status_t orientationToTransfrom(int orientation,
213 int w, int h, Transform* tr);
214
Mathias Agopian87baae12012-07-31 12:38:26 -0700215 uint32_t mLayerStack;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700216 int mOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700217 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700218 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700219 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700220 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700221 // pre-computed scissor to apply to the display
222 Rect mScissor;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700223 Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700224 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700225 // Current power mode
226 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700227 // Current active config
228 int mActiveConfig;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800229};
230
231}; // namespace android
232
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700233#endif // ANDROID_DISPLAY_DEVICE_H