blob: ea56d90aff662d2782cb59382ca59418f711c766 [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;
Mathias Agopian3e876012012-06-07 17:52:54 -070040class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070041class LayerBase;
42class SurfaceFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian028a7572012-08-05 01:23:51 -070044class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045{
46public:
Mathias Agopian87baae12012-07-31 12:38:26 -070047 // region in layer-stack space
48 mutable Region dirtyRegion;
49 // region in screen space
50 mutable Region swapRegion;
51 // region in screen space
52 Region undefinedRegion;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070053
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 enum {
Mathias Agopianf4358632012-08-22 17:16:19 -070055 DISPLAY_ID_MAIN = HWC_DISPLAY_PRIMARY,
56 DISPLAY_ID_HDMI = HWC_DISPLAY_EXTERNAL,
57 DISPLAY_ID_COUNT = HWC_NUM_DISPLAY_TYPES
Mathias Agopian92a979a2012-08-02 18:32:23 -070058 };
59
60 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070061 PARTIAL_UPDATES = 0x00020000, // video driver feature
62 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 };
64
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070065 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 const sp<SurfaceFlinger>& flinger,
Mathias Agopiane60b0682012-08-21 23:34:09 -070067 int32_t dpy, int32_t hwcDisplayId,
Jamie Gennis1a4d8832012-08-02 20:11:05 -070068 const sp<ANativeWindow>& nativeWindow,
69 const sp<FramebufferSurface>& framebufferSurface,
Mathias Agopiana4912602012-07-12 14:25:33 -070070 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071
Mathias Agopian028a7572012-08-05 01:23:51 -070072 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070073
74 // whether this is a valid object. An invalid DisplayDevice is returned
75 // when an non existing id is requested
76 bool isValid() const;
77
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 // Flip the front and back buffers if the back buffer is "dirty". Might
79 // be instantaneous, might involve copying the frame buffer around.
80 void flip(const Region& dirty) const;
81
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 int getWidth() const;
83 int getHeight() const;
84 PixelFormat getFormat() const;
85 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070086
Mathias Agopiana4912602012-07-12 14:25:33 -070087 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070088
89 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
90 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
91 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -070092 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070093
Mathias Agopian1b031492012-06-20 17:51:20 -070094 status_t setOrientation(int orientation);
Mathias Agopian28947d72012-08-08 18:51:15 -070095 void setLayerStack(uint32_t stack);
96
Mathias Agopian1b031492012-06-20 17:51:20 -070097 int getOrientation() const { return mOrientation; }
98 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian87baae12012-07-31 12:38:26 -070099 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian1e260872012-08-08 18:35:12 -0700100 int32_t getDisplayId() const { return mId; }
Mathias Agopiane60b0682012-08-21 23:34:09 -0700101 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700102
Mathias Agopian74faca22009-09-17 16:18:16 -0700103 status_t compositionComplete() const;
104
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700105 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700106 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700108 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
Mathias Agopian42977342012-08-05 00:40:46 -0700110 static void makeCurrent(const sp<const DisplayDevice>& hw, EGLContext ctx);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700111
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700112 /* ------------------------------------------------------------------------
113 * blank / unplank management
114 */
115 void releaseScreen() const;
116 void acquireScreen() const;
117 bool isScreenAcquired() const;
118 bool canDraw() const;
119
120 /* ------------------------------------------------------------------------
121 * Debugging
122 */
123 uint32_t getPageFlipCount() const;
124 void dump(String8& res) const;
125
Mathias Agopian92a979a2012-08-02 18:32:23 -0700126 inline bool operator < (const DisplayDevice& rhs) const {
127 return mId < rhs.mId;
128 }
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700129
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700131 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132
Mathias Agopiana4912602012-07-12 14:25:33 -0700133 /*
134 * Constants, set during initialization
135 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700136 sp<SurfaceFlinger> mFlinger;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700137 int32_t mId;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700138 int32_t mHwcDisplayId;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700139
Mathias Agopiana4912602012-07-12 14:25:33 -0700140 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700141 sp<ANativeWindow> mNativeWindow;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700142
Mathias Agopiana4912602012-07-12 14:25:33 -0700143 // set if mNativeWindow is a FramebufferSurface
144 sp<FramebufferSurface> mFramebufferSurface;
145
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 EGLDisplay mDisplay;
147 EGLSurface mSurface;
148 EGLContext mContext;
Mathias Agopian1b031492012-06-20 17:51:20 -0700149 int mDisplayWidth;
150 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151 PixelFormat mFormat;
152 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700153 mutable uint32_t mPageFlipCount;
Mathias Agopian03e40722012-04-26 16:11:59 -0700154
Mathias Agopiana4912602012-07-12 14:25:33 -0700155 /*
156 * Can only accessed from the main thread, these members
157 * don't need synchronization.
158 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700159
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700160 // list of visible layers on that display
161 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700162
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700163 // Whether we have a visible secure layer on this display
164 bool mSecureLayerVisible;
165
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700166 // Whether the screen is blanked;
167 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700168
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700169
170 /*
171 * Transaction state
172 */
Mathias Agopian1b031492012-06-20 17:51:20 -0700173 static status_t orientationToTransfrom(int orientation, int w, int h,
174 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700175 Transform mGlobalTransform;
176 int mOrientation;
Mathias Agopian87baae12012-07-31 12:38:26 -0700177 uint32_t mLayerStack;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800178};
179
180}; // namespace android
181
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700182#endif // ANDROID_DISPLAY_DEVICE_H