blob: 38241d994b6ba2318880e6f8f02e4d5a8c3614de [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
Dan Stoza9e56aa02015-11-02 13:00:03 -080020#include "Transform.h"
21
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <stdlib.h>
23
Dan Stoza9e56aa02015-11-02 13:00:03 -080024#ifndef USE_HWC2
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <ui/PixelFormat.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080026#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <ui/Region.h>
28
29#include <EGL/egl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030#include <EGL/eglext.h>
31
Dan Stoza9e56aa02015-11-02 13:00:03 -080032#ifdef USE_HWC2
33#include <binder/IBinder.h>
34#include <utils/RefBase.h>
35#endif
Mathias Agopian86303202012-07-24 22:46:10 -070036#include <utils/Mutex.h>
Mathias Agopian4f4f0942013-08-19 17:26:18 -070037#include <utils/String8.h>
Mathias Agopian86303202012-07-24 22:46:10 -070038#include <utils/Timers.h>
39
Mathias Agopianf4358632012-08-22 17:16:19 -070040#include <hardware/hwcomposer_defs.h>
41
Dan Stoza9e56aa02015-11-02 13:00:03 -080042#ifdef USE_HWC2
43#include <memory>
44#endif
Mathias Agopian1f7bec62010-06-25 18:02:21 -070045
Mathias Agopiand8552d72012-08-04 21:39:11 -070046struct ANativeWindow;
47
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048namespace android {
49
Jesse Hall646f5412014-08-07 22:19:07 -070050struct DisplayInfo;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070051class DisplaySurface;
Dan Stoza9e56aa02015-11-02 13:00:03 -080052#ifdef USE_HWC2
53class Fence;
54#endif
Jesse Hall9e663de2013-08-16 14:28:37 -070055class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080056class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070057class SurfaceFlinger;
Mathias Agopianda27af92012-09-13 18:17:13 -070058class HWComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059
Mathias Agopian028a7572012-08-05 01:23:51 -070060class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061{
62public:
Mathias Agopian87baae12012-07-31 12:38:26 -070063 // region in layer-stack space
64 mutable Region dirtyRegion;
65 // region in screen space
66 mutable Region swapRegion;
67 // region in screen space
68 Region undefinedRegion;
Jesse Hallb7a05492014-08-14 15:45:06 -070069 bool lastCompositionHadVisibleLayers;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070070
Mathias Agopian3ee454a2012-08-27 16:28:24 -070071 enum DisplayType {
72 DISPLAY_ID_INVALID = -1,
73 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
74 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
Jesse Hall9e663de2013-08-16 14:28:37 -070075 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
76 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
Mathias Agopian92a979a2012-08-02 18:32:23 -070077 };
78
79 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070080 PARTIAL_UPDATES = 0x00020000, // video driver feature
81 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 };
83
Jesse Hall01e29052013-02-19 16:13:35 -080084 enum {
85 NO_LAYER_STACK = 0xFFFFFFFF,
86 };
87
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070088 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070090 DisplayType type,
Dan Stoza9e56aa02015-11-02 13:00:03 -080091 int32_t hwcId,
92#ifndef USE_HWC2
Jesse Hall19e87292013-12-23 21:02:15 -080093 int format,
Dan Stoza9e56aa02015-11-02 13:00:03 -080094#endif
Jamie Gennisdd3cb842012-10-19 18:19:11 -070095 bool isSecure,
96 const wp<IBinder>& displayToken,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070097 const sp<DisplaySurface>& displaySurface,
Mathias Agopiandb89edc2013-08-02 01:40:18 -070098 const sp<IGraphicBufferProducer>& producer,
Mathias Agopiana4912602012-07-12 14:25:33 -070099 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100
Mathias Agopian028a7572012-08-05 01:23:51 -0700101 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -0700102
103 // whether this is a valid object. An invalid DisplayDevice is returned
104 // when an non existing id is requested
105 bool isValid() const;
106
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700107 // isSecure indicates whether this display can be trusted to display
108 // secure surfaces.
109 bool isSecure() const { return mIsSecure; }
110
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 // Flip the front and back buffers if the back buffer is "dirty". Might
112 // be instantaneous, might involve copying the frame buffer around.
113 void flip(const Region& dirty) const;
114
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115 int getWidth() const;
116 int getHeight() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800117#ifndef USE_HWC2
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 PixelFormat getFormat() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800119#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700121
Mathias Agopiana4912602012-07-12 14:25:33 -0700122 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700123
Mathias Agopian13127d82013-03-05 17:47:11 -0800124 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
125 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700126 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700127
Mathias Agopian28947d72012-08-08 18:51:15 -0700128 void setLayerStack(uint32_t stack);
Michael Lentine47e45402014-07-18 15:34:25 -0700129 void setDisplaySize(const int newWidth, const int newHeight);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700130 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700131
Mathias Agopian1b031492012-06-20 17:51:20 -0700132 int getOrientation() const { return mOrientation; }
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700133 uint32_t getOrientationTransform() const;
Mathias Agopian1b031492012-06-20 17:51:20 -0700134 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800135 const Rect getViewport() const { return mViewport; }
136 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700137 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700138 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700139
Mathias Agopian87baae12012-07-31 12:38:26 -0700140 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700141 int32_t getDisplayType() const { return mType; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700142 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700143 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700144
Dan Stoza71433162014-02-04 16:22:36 -0800145 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
146 // machine happy without actually queueing a buffer if nothing has changed
147 status_t beginFrame(bool mustRecompose) const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800148#ifdef USE_HWC2
149 status_t prepareFrame(HWComposer& hwc);
150#else
Jesse Hall38efe862013-04-06 23:12:29 -0700151 status_t prepareFrame(const HWComposer& hwc) const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800152#endif
Jesse Hall38efe862013-04-06 23:12:29 -0700153
Mathias Agopianda27af92012-09-13 18:17:13 -0700154 void swapBuffers(HWComposer& hwc) const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800155#ifndef USE_HWC2
Mathias Agopian74faca22009-09-17 16:18:16 -0700156 status_t compositionComplete() const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800157#endif
Jesse Hall01e29052013-02-19 16:13:35 -0800158
Mathias Agopianda27af92012-09-13 18:17:13 -0700159 // called after h/w composer has completed its set() call
Dan Stoza9e56aa02015-11-02 13:00:03 -0800160#ifdef USE_HWC2
161 void onSwapBuffersCompleted() const;
162#else
Mathias Agopianda27af92012-09-13 18:17:13 -0700163 void onSwapBuffersCompleted(HWComposer& hwc) const;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800164#endif
Mathias Agopianda27af92012-09-13 18:17:13 -0700165
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700166 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700167 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700169 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700171 void setDisplayName(const String8& displayName);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700172 const String8& getDisplayName() const { return mDisplayName; }
173
Mathias Agopian875d8e12013-06-07 15:35:48 -0700174 EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
175 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700176
Dan Stoza9e56aa02015-11-02 13:00:03 -0800177#ifdef USE_HWC2
178 const sp<Fence>& getClientTargetAcquireFence() const;
179#endif
180
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700181 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700182 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700183 */
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700184 int getPowerMode() const;
185 void setPowerMode(int mode);
186 bool isDisplayOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700187
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700188 /* ------------------------------------------------------------------------
189 * Display active config management.
190 */
191 int getActiveConfig() const;
192 void setActiveConfig(int mode);
193
Jesse Hall02d86562013-03-25 14:43:23 -0700194 // release HWC resources (if any) for removable displays
195 void disconnect(HWComposer& hwc);
196
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700197 /* ------------------------------------------------------------------------
198 * Debugging
199 */
200 uint32_t getPageFlipCount() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200201 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700202
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700204 /*
205 * Constants, set during initialization
206 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700207 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700208 DisplayType mType;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700209 int32_t mHwcDisplayId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700210 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700211
Mathias Agopiana4912602012-07-12 14:25:33 -0700212 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700213 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700214 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700215
Michael Lentine47e45402014-07-18 15:34:25 -0700216 EGLConfig mConfig;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800217 EGLDisplay mDisplay;
218 EGLSurface mSurface;
Mathias Agopian1b031492012-06-20 17:51:20 -0700219 int mDisplayWidth;
220 int mDisplayHeight;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800221#ifndef USE_HWC2
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 PixelFormat mFormat;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800223#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800224 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700225 mutable uint32_t mPageFlipCount;
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700226 String8 mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700227 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700228
Mathias Agopiana4912602012-07-12 14:25:33 -0700229 /*
230 * Can only accessed from the main thread, these members
231 * don't need synchronization.
232 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700233
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700234 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800235 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700236
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700237 /*
238 * Transaction state
239 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700240 static status_t orientationToTransfrom(int orientation,
241 int w, int h, Transform* tr);
242
Mathias Agopian87baae12012-07-31 12:38:26 -0700243 uint32_t mLayerStack;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700244 int mOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700245 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700246 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700247 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700248 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700249 // pre-computed scissor to apply to the display
250 Rect mScissor;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700251 Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700252 bool mNeedsFiltering;
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700253 // Current power mode
254 int mPowerMode;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700255 // Current active config
256 int mActiveConfig;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800257};
258
259}; // namespace android
260
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700261#endif // ANDROID_DISPLAY_DEVICE_H