blob: 14b194fb114dd58e61f5aa49bb52d7b1032d9d07 [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 Agopian1b031492012-06-20 17:51:20 -070031#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070032
Mathias Agopiand8552d72012-08-04 21:39:11 -070033struct ANativeWindow;
34
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035namespace android {
36
Mathias Agopianc666cae2012-07-25 18:56:13 -070037class DisplayInfo;
Mathias Agopian3e876012012-06-07 17:52:54 -070038class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070039class LayerBase;
40class SurfaceFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Mathias Agopian028a7572012-08-05 01:23:51 -070042class DisplayDevice : public LightRefBase<DisplayDevice>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043{
44public:
Mathias Agopian87baae12012-07-31 12:38:26 -070045 // region in layer-stack space
46 mutable Region dirtyRegion;
47 // region in screen space
48 mutable Region swapRegion;
49 // region in screen space
50 Region undefinedRegion;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070051
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 enum {
Mathias Agopian92a979a2012-08-02 18:32:23 -070053 DISPLAY_ID_MAIN = 0,
Mathias Agopiane57f2922012-08-09 16:29:12 -070054 DISPLAY_ID_HDMI = 1,
55 DISPLAY_ID_COUNT
Mathias Agopian92a979a2012-08-02 18:32:23 -070056 };
57
58 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070059 PARTIAL_UPDATES = 0x00020000, // video driver feature
60 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 };
62
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070063 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 const sp<SurfaceFlinger>& flinger,
Mathias Agopiane60b0682012-08-21 23:34:09 -070065 int32_t dpy, int32_t hwcDisplayId,
Jamie Gennis1a4d8832012-08-02 20:11:05 -070066 const sp<ANativeWindow>& nativeWindow,
67 const sp<FramebufferSurface>& framebufferSurface,
Mathias Agopiana4912602012-07-12 14:25:33 -070068 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069
Mathias Agopian028a7572012-08-05 01:23:51 -070070 ~DisplayDevice();
Mathias Agopian92a979a2012-08-02 18:32:23 -070071
72 // whether this is a valid object. An invalid DisplayDevice is returned
73 // when an non existing id is requested
74 bool isValid() const;
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 // Flip the front and back buffers if the back buffer is "dirty". Might
77 // be instantaneous, might involve copying the frame buffer around.
78 void flip(const Region& dirty) const;
79
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 int getWidth() const;
81 int getHeight() const;
82 PixelFormat getFormat() const;
83 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070084
Mathias Agopiana4912602012-07-12 14:25:33 -070085 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070086
87 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
88 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
89 bool getSecureLayerVisible() const;
Mathias Agopiancd60f992012-08-16 16:28:27 -070090 Region getDirtyRegion(bool repaintEverything) const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070091
Mathias Agopian1b031492012-06-20 17:51:20 -070092 status_t setOrientation(int orientation);
Mathias Agopian28947d72012-08-08 18:51:15 -070093 void setLayerStack(uint32_t stack);
94
Mathias Agopian1b031492012-06-20 17:51:20 -070095 int getOrientation() const { return mOrientation; }
96 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian87baae12012-07-31 12:38:26 -070097 uint32_t getLayerStack() const { return mLayerStack; }
Mathias Agopian1e260872012-08-08 18:35:12 -070098 int32_t getDisplayId() const { return mId; }
Mathias Agopiane60b0682012-08-21 23:34:09 -070099 int32_t getHwcDisplayId() const { return mHwcDisplayId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700100
Mathias Agopian74faca22009-09-17 16:18:16 -0700101 status_t compositionComplete() const;
102
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700103 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700104 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700106 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107
Mathias Agopian42977342012-08-05 00:40:46 -0700108 static void makeCurrent(const sp<const DisplayDevice>& hw, EGLContext ctx);
Mathias Agopian52bbb1a2012-07-31 19:01:53 -0700109
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700110 /* ------------------------------------------------------------------------
111 * blank / unplank management
112 */
113 void releaseScreen() const;
114 void acquireScreen() const;
115 bool isScreenAcquired() const;
116 bool canDraw() const;
117
118 /* ------------------------------------------------------------------------
119 * Debugging
120 */
121 uint32_t getPageFlipCount() const;
122 void dump(String8& res) const;
123
Mathias Agopian92a979a2012-08-02 18:32:23 -0700124 inline bool operator < (const DisplayDevice& rhs) const {
125 return mId < rhs.mId;
126 }
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700127
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700129 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130
Mathias Agopiana4912602012-07-12 14:25:33 -0700131 /*
132 * Constants, set during initialization
133 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700134 sp<SurfaceFlinger> mFlinger;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700135 int32_t mId;
Mathias Agopiane60b0682012-08-21 23:34:09 -0700136 int32_t mHwcDisplayId;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700137
Mathias Agopiana4912602012-07-12 14:25:33 -0700138 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700139 sp<ANativeWindow> mNativeWindow;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700140
Mathias Agopiana4912602012-07-12 14:25:33 -0700141 // set if mNativeWindow is a FramebufferSurface
142 sp<FramebufferSurface> mFramebufferSurface;
143
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 EGLDisplay mDisplay;
145 EGLSurface mSurface;
146 EGLContext mContext;
Mathias Agopian1b031492012-06-20 17:51:20 -0700147 int mDisplayWidth;
148 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149 PixelFormat mFormat;
150 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700151 mutable uint32_t mPageFlipCount;
Mathias Agopian03e40722012-04-26 16:11:59 -0700152
Mathias Agopiana4912602012-07-12 14:25:33 -0700153 /*
154 * Can only accessed from the main thread, these members
155 * don't need synchronization.
156 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700157
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700158 // list of visible layers on that display
159 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700160
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700161 // Whether we have a visible secure layer on this display
162 bool mSecureLayerVisible;
163
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700164 // Whether the screen is blanked;
165 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700166
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700167
168 /*
169 * Transaction state
170 */
Mathias Agopian1b031492012-06-20 17:51:20 -0700171 static status_t orientationToTransfrom(int orientation, int w, int h,
172 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700173 Transform mGlobalTransform;
174 int mOrientation;
Mathias Agopian87baae12012-07-31 12:38:26 -0700175 uint32_t mLayerStack;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176};
177
178}; // namespace android
179
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700180#endif // ANDROID_DISPLAY_DEVICE_H