blob: 4afca58f7f078aac3df7cee3fb8eaf093f56bc11 [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 Agopiand3ee2312012-08-02 14:01:42 -070042class 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,
54 DISPLAY_ID_HDMI = 1
55 };
56
57 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070058 PARTIAL_UPDATES = 0x00020000, // video driver feature
59 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 };
61
Mathias Agopian92a979a2012-08-02 18:32:23 -070062 DisplayDevice();
63
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070064 DisplayDevice(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070066 int dpy,
Mathias Agopiand8552d72012-08-04 21:39:11 -070067 const sp<ANativeWindow>& surface,
Mathias Agopiana4912602012-07-12 14:25:33 -070068 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069
Mathias Agopiand3ee2312012-08-02 14:01:42 -070070 ~DisplayDevice();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071
Mathias Agopian92a979a2012-08-02 18:32:23 -070072 // must be called when this object is no longer needed. this will
73 // render the associated EGLSurface invalid.
74 void terminate();
75
76 // whether this is a valid object. An invalid DisplayDevice is returned
77 // when an non existing id is requested
78 bool isValid() const;
79
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 // Flip the front and back buffers if the back buffer is "dirty". Might
81 // be instantaneous, might involve copying the frame buffer around.
82 void flip(const Region& dirty) const;
83
84 float getDpiX() const;
85 float getDpiY() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 float getDensity() const;
87 int getWidth() const;
88 int getHeight() const;
89 PixelFormat getFormat() const;
90 uint32_t getFlags() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070091
Mathias Agopiana4912602012-07-12 14:25:33 -070092 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070093
94 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
95 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
96 bool getSecureLayerVisible() const;
97
Mathias Agopian1b031492012-06-20 17:51:20 -070098 status_t setOrientation(int orientation);
99 int getOrientation() const { return mOrientation; }
100 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700101 uint32_t getLayerStack() const { return mLayerStack; }
102
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 Agopian0f2f5ff2012-07-31 23:09:07 -0700110 static void makeCurrent(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 Agopiand3ee2312012-08-02 14:01:42 -0700138
Mathias Agopiana4912602012-07-12 14:25:33 -0700139 // ANativeWindow this display is rendering into
Mathias Agopiand8552d72012-08-04 21:39:11 -0700140 sp<ANativeWindow> mNativeWindow;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700141
Mathias Agopiana4912602012-07-12 14:25:33 -0700142 // set if mNativeWindow is a FramebufferSurface
143 sp<FramebufferSurface> mFramebufferSurface;
144
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 EGLDisplay mDisplay;
146 EGLSurface mSurface;
147 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148 float mDpiX;
149 float mDpiY;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700151 int mDisplayWidth;
152 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 PixelFormat mFormat;
154 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700155 mutable uint32_t mPageFlipCount;
Mathias Agopian03e40722012-04-26 16:11:59 -0700156
Mathias Agopiana4912602012-07-12 14:25:33 -0700157 /*
158 * Can only accessed from the main thread, these members
159 * don't need synchronization.
160 */
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700161
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700162 // list of visible layers on that display
163 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700164
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700165 // Whether we have a visible secure layer on this display
166 bool mSecureLayerVisible;
167
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700168 // Whether the screen is blanked;
169 mutable int mScreenAcquired;
Mathias Agopiana350ff92010-08-10 17:14:02 -0700170
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700171
172 /*
173 * Transaction state
174 */
Mathias Agopian1b031492012-06-20 17:51:20 -0700175 static status_t orientationToTransfrom(int orientation, int w, int h,
176 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700177 Transform mGlobalTransform;
178 int mOrientation;
Mathias Agopian87baae12012-07-31 12:38:26 -0700179 uint32_t mLayerStack;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800180};
181
182}; // namespace android
183
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700184#endif // ANDROID_DISPLAY_DEVICE_H