blob: a1a4764fc12bc6046db8ceffa92863b063008d0b [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
17#ifndef ANDROID_DISPLAY_HARDWARE_H
18#define ANDROID_DISPLAY_HARDWARE_H
19
20#include <stdlib.h>
21
22#include <ui/PixelFormat.h>
23#include <ui/Region.h>
24
Mathias Agopian076b1cc2009-04-10 14:24:30 -070025#include <GLES/gl.h>
26#include <GLES/glext.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <EGL/egl.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <EGL/eglext.h>
29
Mathias Agopian1b031492012-06-20 17:51:20 -070030#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070031
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "DisplayHardware/DisplayHardwareBase.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070033#include "DisplayHardware/HWComposer.h"
34#include "DisplayHardware/PowerHAL.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036namespace android {
37
Mathias Agopian3e876012012-06-07 17:52:54 -070038class FramebufferSurface;
Mathias Agopiana4912602012-07-12 14:25:33 -070039class SurfaceTextureClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070041class DisplayHardware :
42 public DisplayHardwareBase,
43 public HWComposer::EventHandler
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044{
45public:
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070046
47 class VSyncHandler : virtual public RefBase {
48 friend class DisplayHardware;
49 virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0;
50 protected:
51 virtual ~VSyncHandler() {}
52 };
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 enum {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070055 PARTIAL_UPDATES = 0x00020000, // video driver feature
Mathias Agopian1f7bec62010-06-25 18:02:21 -070056 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 };
58
59 DisplayHardware(
60 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070061 int dpy,
62 const sp<SurfaceTextureClient>& surface,
63 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070065 virtual ~DisplayHardware();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066
67 void releaseScreen() const;
68 void acquireScreen() const;
69
70 // Flip the front and back buffers if the back buffer is "dirty". Might
71 // be instantaneous, might involve copying the frame buffer around.
72 void flip(const Region& dirty) const;
73
74 float getDpiX() const;
75 float getDpiY() const;
76 float getRefreshRate() const;
77 float getDensity() const;
78 int getWidth() const;
79 int getHeight() const;
80 PixelFormat getFormat() const;
81 uint32_t getFlags() const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080082 nsecs_t getRefreshPeriod() const;
83 nsecs_t getRefreshTimestamp() 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;
90
Mathias Agopian1b031492012-06-20 17:51:20 -070091 status_t setOrientation(int orientation);
92 int getOrientation() const { return mOrientation; }
93 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070094
95 void setVSyncHandler(const sp<VSyncHandler>& handler);
96
Mathias Agopian03e40722012-04-26 16:11:59 -070097 enum {
98 EVENT_VSYNC = HWC_EVENT_VSYNC
99 };
100
101 void eventControl(int event, int enabled);
102
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800103
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700106
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800107 void dump(String8& res) const;
108
Mathias Agopiana350ff92010-08-10 17:14:02 -0700109 // Hardware Composer
110 HWComposer& getHwComposer() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
Mathias Agopian74faca22009-09-17 16:18:16 -0700112 status_t compositionComplete() const;
113
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700114 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700115 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700117 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118
119private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700120 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121
Mathias Agopiana4912602012-07-12 14:25:33 -0700122 virtual void onVSyncReceived(int dpy, nsecs_t timestamp);
123
124 /*
125 * Constants, set during initialization
126 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700127 sp<SurfaceFlinger> mFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -0700128 int mDisplayId;
129 HWComposer* mHwc;
130 PowerHAL mPowerHAL;
131 // ANativeWindow this display is rendering into
132 sp<SurfaceTextureClient> mNativeWindow;
133 // set if mNativeWindow is a FramebufferSurface
134 sp<FramebufferSurface> mFramebufferSurface;
135
136
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800137 EGLDisplay mDisplay;
138 EGLSurface mSurface;
139 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 float mDpiX;
141 float mDpiY;
142 float mRefreshRate;
143 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700144 int mDisplayWidth;
145 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 PixelFormat mFormat;
147 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700148 mutable uint32_t mPageFlipCount;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800149
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800150 nsecs_t mRefreshPeriod;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800151 mutable nsecs_t mLastHwVSync;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800152
Mathias Agopian03e40722012-04-26 16:11:59 -0700153
Mathias Agopiana4912602012-07-12 14:25:33 -0700154 /*
155 * Can only accessed from the main thread, these members
156 * don't need synchronization.
157 */
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700158 // list of visible layers on that display
159 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
160 // Whether we have a visible secure layer on this display
161 bool mSecureLayerVisible;
162
Mathias Agopiana350ff92010-08-10 17:14:02 -0700163
Mathias Agopian1b031492012-06-20 17:51:20 -0700164 // this used to be in GraphicPlane
165 static status_t orientationToTransfrom(int orientation, int w, int h,
166 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700167 Transform mGlobalTransform;
168 int mOrientation;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700169
Mathias Agopiana4912602012-07-12 14:25:33 -0700170 /*
171 * protected by mLock
172 */
Mathias Agopian98a121a2012-07-24 21:08:59 -0700173 mutable Mutex mLock;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700174 wp<VSyncHandler> mVSyncHandler;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175};
176
177}; // namespace android
178
179#endif // ANDROID_DISPLAY_HARDWARE_H