blob: 3da9f163b6ddbf450c6f7fed0f3cec2f4352f2e1 [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 Agopian1f7bec62010-06-25 18:02:21 -070030#include "GLExtensions.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070031#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070032
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include "DisplayHardware/DisplayHardwareBase.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070034#include "DisplayHardware/HWComposer.h"
35#include "DisplayHardware/PowerHAL.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
Mathias Agopian3e876012012-06-07 17:52:54 -070039class FramebufferSurface;
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 COPY_BITS_EXTENSION = 0x00000008,
Mathias Agopian1f7bec62010-06-25 18:02:21 -070056 PARTIAL_UPDATES = 0x00020000, // video driver feature
57 SLOW_CONFIG = 0x00040000, // software
58 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 };
60
61 DisplayHardware(
62 const sp<SurfaceFlinger>& flinger,
63 uint32_t displayIndex);
64
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 Agopianca99fb82010-04-14 16:43:44 -070082 uint32_t getMaxTextureSize() const;
83 uint32_t getMaxViewportDims() const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080084 nsecs_t getRefreshPeriod() const;
85 nsecs_t getRefreshTimestamp() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070086 void makeCurrent() const;
87
Mathias Agopian1b031492012-06-20 17:51:20 -070088 status_t setOrientation(int orientation);
89 int getOrientation() const { return mOrientation; }
90 const Transform& getTransform() const { return mGlobalTransform; }
91 int getUserWidth() const { return mUserDisplayWidth; }
92 int getUserHeight() const { return mUserDisplayHeight; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070093
94 void setVSyncHandler(const sp<VSyncHandler>& handler);
95
Mathias Agopian03e40722012-04-26 16:11:59 -070096 enum {
97 EVENT_VSYNC = HWC_EVENT_VSYNC
98 };
99
100 void eventControl(int event, int enabled);
101
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800102
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopian3094df32012-06-18 18:06:45 -0700105 EGLConfig getEGLConfig() const { return mConfig; }
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 Agopian3eb38cb2012-04-03 22:09:52 -0700120 virtual void onVSyncReceived(int dpy, nsecs_t timestamp);
Mathias Agopian1b031492012-06-20 17:51:20 -0700121 void init(uint32_t displayIndex);
122 void fini();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700124 sp<SurfaceFlinger> mFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125 EGLDisplay mDisplay;
126 EGLSurface mSurface;
127 EGLContext mContext;
128 EGLConfig mConfig;
129 float mDpiX;
130 float mDpiY;
131 float mRefreshRate;
132 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700133 int mDisplayWidth;
134 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 PixelFormat mFormat;
136 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700137 mutable uint32_t mPageFlipCount;
Mathias Agopian3d64e732011-04-18 15:59:24 -0700138 GLint mMaxViewportDims[2];
Mathias Agopianca99fb82010-04-14 16:43:44 -0700139 GLint mMaxTextureSize;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800140
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800141 nsecs_t mRefreshPeriod;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800142 mutable nsecs_t mLastHwVSync;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800143
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700144 // constant once set
Mathias Agopiana350ff92010-08-10 17:14:02 -0700145 HWComposer* mHwc;
Mathias Agopian03e40722012-04-26 16:11:59 -0700146 PowerHAL mPowerHAL;
147
Mathias Agopiana350ff92010-08-10 17:14:02 -0700148
Mathias Agopian1b031492012-06-20 17:51:20 -0700149 // this used to be in GraphicPlane
150 static status_t orientationToTransfrom(int orientation, int w, int h,
151 Transform* tr);
152 Transform mGlobalTransform;
153 Transform mDisplayTransform;
154 int mOrientation;
155 int mLogicalDisplayWidth;
156 int mLogicalDisplayHeight;
157 int mUserDisplayWidth;
158 int mUserDisplayHeight;
159
160
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700161 mutable Mutex mLock;
162
163 // protected by mLock
164 wp<VSyncHandler> mVSyncHandler;
165
Mathias Agopian3e876012012-06-07 17:52:54 -0700166 sp<FramebufferSurface> mNativeWindow;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167};
168
169}; // namespace android
170
171#endif // ANDROID_DISPLAY_HARDWARE_H