blob: 377d924efd5f2133dcba728eb885bd3151731c17 [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>
29#include <utils/Timers.h>
30
Mathias Agopianf4358632012-08-22 17:16:19 -070031#include <hardware/hwcomposer_defs.h>
32
Mathias Agopian1b031492012-06-20 17:51:20 -070033#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070034
Mathias Agopiand8552d72012-08-04 21:39:11 -070035struct ANativeWindow;
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
Mathias Agopianc666cae2012-07-25 18:56:13 -070039class DisplayInfo;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070040class DisplaySurface;
Mathias Agopian13127d82013-03-05 17:47:11 -080041class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070042class SurfaceFlinger;
Mathias Agopianda27af92012-09-13 18:17:13 -070043class HWComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Mathias Agopian028a7572012-08-05 01:23:51 -070045class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046{
47public:
Mathias Agopian87baae12012-07-31 12:38:26 -070048 // 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;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070054
Mathias Agopian3ee454a2012-08-27 16:28:24 -070055 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
Mathias Agopian92a979a2012-08-02 18:32:23 -070061 };
62
63 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070064 PARTIAL_UPDATES = 0x00020000, // video driver feature
65 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 };
67
Jesse Hall01e29052013-02-19 16:13:35 -080068 enum {
69 NO_LAYER_STACK = 0xFFFFFFFF,
70 };
71
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070072 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070074 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070075 int32_t hwcId, // negative for non-HWC-composited displays
Jamie Gennisdd3cb842012-10-19 18:19:11 -070076 bool isSecure,
77 const wp<IBinder>& displayToken,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070078 const sp<DisplaySurface>& displaySurface,
Mathias Agopiana4912602012-07-12 14:25:33 -070079 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080
Mathias Agopian028a7572012-08-05 01:23:51 -070081 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070082
83 // whether this is a valid object. An invalid DisplayDevice is returned
84 // when an non existing id is requested
85 bool isValid() const;
86
Jamie Gennisdd3cb842012-10-19 18:19:11 -070087 // isSecure indicates whether this display can be trusted to display
88 // secure surfaces.
89 bool isSecure() const { return mIsSecure; }
90
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 // Flip the front and back buffers if the back buffer is "dirty". Might
92 // be instantaneous, might involve copying the frame buffer around.
93 void flip(const Region& dirty) const;
94
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 int getWidth() const;
96 int getHeight() const;
97 PixelFormat getFormat() const;
98 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070099
Mathias Agopiana4912602012-07-12 14:25:33 -0700100 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700101
Mathias Agopian13127d82013-03-05 17:47:11 -0800102 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
103 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700104 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700105 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700106
Mathias Agopian28947d72012-08-08 18:51:15 -0700107 void setLayerStack(uint32_t stack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700108 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700109
Mathias Agopian1b031492012-06-20 17:51:20 -0700110 int getOrientation() const { return mOrientation; }
111 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800112 const Rect getViewport() const { return mViewport; }
113 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700114 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700115 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700116
Mathias Agopian87baae12012-07-31 12:38:26 -0700117 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700118 int32_t getDisplayType() const { return mType; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700119 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700120 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700121
Mathias Agopianda27af92012-09-13 18:17:13 -0700122 void swapBuffers(HWComposer& hwc) const;
Mathias Agopian74faca22009-09-17 16:18:16 -0700123 status_t compositionComplete() const;
Jesse Hall01e29052013-02-19 16:13:35 -0800124
Mathias Agopianda27af92012-09-13 18:17:13 -0700125 // called after h/w composer has completed its set() call
126 void onSwapBuffersCompleted(HWComposer& hwc) const;
127
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700128 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700129 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700131 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700133 void setDisplayName(const String8& displayName);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700134 const String8& getDisplayName() const { return mDisplayName; }
135
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700136 static EGLBoolean makeCurrent(EGLDisplay dpy,
137 const sp<const DisplayDevice>& hw, EGLContext ctx);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700138
Mathias Agopianbae92d02012-09-28 01:00:47 -0700139 static void setViewportAndProjection(const sp<const DisplayDevice>& hw);
140
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700141 /* ------------------------------------------------------------------------
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700142 * blank / unblank management
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700143 */
144 void releaseScreen() const;
145 void acquireScreen() const;
146 bool isScreenAcquired() const;
147 bool canDraw() const;
148
Jesse Hall02d86562013-03-25 14:43:23 -0700149 // release HWC resources (if any) for removable displays
150 void disconnect(HWComposer& hwc);
151
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700152 /* ------------------------------------------------------------------------
153 * Debugging
154 */
155 uint32_t getPageFlipCount() const;
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700156 void dump(String8& result, char* buffer, size_t SIZE) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700157
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700159 /*
160 * Constants, set during initialization
161 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700162 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700163 DisplayType mType;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700164 int32_t mHwcDisplayId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700165 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700166
Mathias Agopiana4912602012-07-12 14:25:33 -0700167 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700168 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700169 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700170
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171 EGLDisplay mDisplay;
172 EGLSurface mSurface;
173 EGLContext mContext;
Mathias Agopian1b031492012-06-20 17:51:20 -0700174 int mDisplayWidth;
175 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176 PixelFormat mFormat;
177 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700178 mutable uint32_t mPageFlipCount;
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700179 String8 mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700180 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700181
Mathias Agopiana4912602012-07-12 14:25:33 -0700182 /*
183 * Can only accessed from the main thread, these members
184 * don't need synchronization.
185 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700186
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700187 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800188 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700189
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700190 // Whether we have a visible secure layer on this display
191 bool mSecureLayerVisible;
192
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700193 // Whether the screen is blanked;
194 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700195
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700196
197 /*
198 * Transaction state
199 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700200 static status_t orientationToTransfrom(int orientation,
201 int w, int h, Transform* tr);
202
Mathias Agopian87baae12012-07-31 12:38:26 -0700203 uint32_t mLayerStack;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700204 int mOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700205 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700206 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700207 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700208 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700209 // pre-computed scissor to apply to the display
210 Rect mScissor;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700211 Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700212 bool mNeedsFiltering;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213};
214
215}; // namespace android
216
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700217#endif // ANDROID_DISPLAY_DEVICE_H