blob: 8e24df757b92ec241b9c939a61a319b1059ed26b [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;
Jesse Hall9e663de2013-08-16 14:28:37 -070041class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080042class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070043class SurfaceFlinger;
Mathias Agopianda27af92012-09-13 18:17:13 -070044class HWComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
Mathias Agopian028a7572012-08-05 01:23:51 -070046class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047{
48public:
Mathias Agopian87baae12012-07-31 12:38:26 -070049 // region in layer-stack space
50 mutable Region dirtyRegion;
51 // region in screen space
52 mutable Region swapRegion;
53 // region in screen space
54 Region undefinedRegion;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070055
Mathias Agopian3ee454a2012-08-27 16:28:24 -070056 enum DisplayType {
57 DISPLAY_ID_INVALID = -1,
58 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY,
59 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL,
Jesse Hall9e663de2013-08-16 14:28:37 -070060 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL,
61 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES,
Mathias Agopian92a979a2012-08-02 18:32:23 -070062 };
63
64 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070065 PARTIAL_UPDATES = 0x00020000, // video driver feature
66 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 };
68
Jesse Hall01e29052013-02-19 16:13:35 -080069 enum {
70 NO_LAYER_STACK = 0xFFFFFFFF,
71 };
72
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070073 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 const sp<SurfaceFlinger>& flinger,
Jamie Gennisdd3cb842012-10-19 18:19:11 -070075 DisplayType type,
Jesse Hallffe1f192013-03-22 15:13:48 -070076 int32_t hwcId, // negative for non-HWC-composited displays
Jamie Gennisdd3cb842012-10-19 18:19:11 -070077 bool isSecure,
78 const wp<IBinder>& displayToken,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070079 const sp<DisplaySurface>& displaySurface,
Mathias Agopiandb89edc2013-08-02 01:40:18 -070080 const sp<IGraphicBufferProducer>& producer,
Mathias Agopiana4912602012-07-12 14:25:33 -070081 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082
Mathias Agopian028a7572012-08-05 01:23:51 -070083 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070084
85 // whether this is a valid object. An invalid DisplayDevice is returned
86 // when an non existing id is requested
87 bool isValid() const;
88
Jamie Gennisdd3cb842012-10-19 18:19:11 -070089 // isSecure indicates whether this display can be trusted to display
90 // secure surfaces.
91 bool isSecure() const { return mIsSecure; }
92
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 // Flip the front and back buffers if the back buffer is "dirty". Might
94 // be instantaneous, might involve copying the frame buffer around.
95 void flip(const Region& dirty) const;
96
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 int getWidth() const;
98 int getHeight() const;
99 PixelFormat getFormat() const;
100 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700101
Mathias Agopiana4912602012-07-12 14:25:33 -0700102 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700103
Mathias Agopian13127d82013-03-05 17:47:11 -0800104 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
105 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700106 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -0700107 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700108
Mathias Agopian28947d72012-08-08 18:51:15 -0700109 void setLayerStack(uint32_t stack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700110 void setProjection(int orientation, const Rect& viewport, const Rect& frame);
Mathias Agopian28947d72012-08-08 18:51:15 -0700111
Mathias Agopian1b031492012-06-20 17:51:20 -0700112 int getOrientation() const { return mOrientation; }
113 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800114 const Rect getViewport() const { return mViewport; }
115 const Rect getFrame() const { return mFrame; }
Mathias Agopian766dc492012-10-30 18:08:06 -0700116 const Rect& getScissor() const { return mScissor; }
Mathias Agopianeba8c682012-09-19 23:14:45 -0700117 bool needsFiltering() const { return mNeedsFiltering; }
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700118
Mathias Agopian87baae12012-07-31 12:38:26 -0700119 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700120 int32_t getDisplayType() const { return mType; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700121 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700122 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700123
Jesse Hall38efe862013-04-06 23:12:29 -0700124 status_t prepareFrame(const HWComposer& hwc) const;
125
Mathias Agopianda27af92012-09-13 18:17:13 -0700126 void swapBuffers(HWComposer& hwc) const;
Mathias Agopian74faca22009-09-17 16:18:16 -0700127 status_t compositionComplete() const;
Jesse Hall01e29052013-02-19 16:13:35 -0800128
Mathias Agopianda27af92012-09-13 18:17:13 -0700129 // called after h/w composer has completed its set() call
130 void onSwapBuffersCompleted(HWComposer& hwc) const;
131
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700132 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700133 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700135 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700137 void setDisplayName(const String8& displayName);
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700138 const String8& getDisplayName() const { return mDisplayName; }
139
Mathias Agopian875d8e12013-06-07 15:35:48 -0700140 EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const;
141 void setViewportAndProjection() const;
Mathias Agopianbae92d02012-09-28 01:00:47 -0700142
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700143 /* ------------------------------------------------------------------------
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700144 * blank / unblank management
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700145 */
146 void releaseScreen() const;
147 void acquireScreen() const;
148 bool isScreenAcquired() const;
149 bool canDraw() const;
150
Jesse Hall02d86562013-03-25 14:43:23 -0700151 // release HWC resources (if any) for removable displays
152 void disconnect(HWComposer& hwc);
153
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700154 /* ------------------------------------------------------------------------
155 * Debugging
156 */
157 uint32_t getPageFlipCount() const;
Mathias Agopian74d211a2013-04-22 16:55:35 +0200158 void dump(String8& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700159
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700161 /*
162 * Constants, set during initialization
163 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700164 sp<SurfaceFlinger> mFlinger;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700165 DisplayType mType;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700166 int32_t mHwcDisplayId;
Mathias Agopian3ee454a2012-08-27 16:28:24 -0700167 wp<IBinder> mDisplayToken;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700168
Mathias Agopiana4912602012-07-12 14:25:33 -0700169 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700170 sp<ANativeWindow> mNativeWindow;
Jesse Hall99c7dbb2013-03-14 14:29:29 -0700171 sp<DisplaySurface> mDisplaySurface;
Mathias Agopiana4912602012-07-12 14:25:33 -0700172
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173 EGLDisplay mDisplay;
174 EGLSurface mSurface;
Mathias Agopian1b031492012-06-20 17:51:20 -0700175 int mDisplayWidth;
176 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800177 PixelFormat mFormat;
178 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700179 mutable uint32_t mPageFlipCount;
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700180 String8 mDisplayName;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700181 bool mIsSecure;
Mathias Agopian03e40722012-04-26 16:11:59 -0700182
Mathias Agopiana4912602012-07-12 14:25:33 -0700183 /*
184 * Can only accessed from the main thread, these members
185 * don't need synchronization.
186 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700187
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700188 // list of visible layers on that display
Mathias Agopian13127d82013-03-05 17:47:11 -0800189 Vector< sp<Layer> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700190
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700191 // Whether we have a visible secure layer on this display
192 bool mSecureLayerVisible;
193
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700194 // Whether the screen is blanked;
195 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700196
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700197
198 /*
199 * Transaction state
200 */
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700201 static status_t orientationToTransfrom(int orientation,
202 int w, int h, Transform* tr);
203
Mathias Agopian87baae12012-07-31 12:38:26 -0700204 uint32_t mLayerStack;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700205 int mOrientation;
Mathias Agopian766dc492012-10-30 18:08:06 -0700206 // user-provided visible area of the layer stack
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700207 Rect mViewport;
Mathias Agopian766dc492012-10-30 18:08:06 -0700208 // user-provided rectangle where mViewport gets mapped to
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700209 Rect mFrame;
Mathias Agopian766dc492012-10-30 18:08:06 -0700210 // pre-computed scissor to apply to the display
211 Rect mScissor;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700212 Transform mGlobalTransform;
Mathias Agopianeba8c682012-09-19 23:14:45 -0700213 bool mNeedsFiltering;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214};
215
216}; // namespace android
217
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700218#endif // ANDROID_DISPLAY_DEVICE_H