blob: 31662dd0428f16b4c27bec3e542f462cf14e6c33 [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"
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "DisplayHardware/DisplayHardwareBase.h"
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070033#include "HWComposer.h"
Mathias Agopian03e40722012-04-26 16:11:59 -070034#include "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;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070040class DisplayHardware :
41 public DisplayHardwareBase,
42 public HWComposer::EventHandler
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043{
44public:
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070045
46 class VSyncHandler : virtual public RefBase {
47 friend class DisplayHardware;
48 virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0;
49 protected:
50 virtual ~VSyncHandler() {}
51 };
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 enum {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070054 COPY_BITS_EXTENSION = 0x00000008,
Mathias Agopian1f7bec62010-06-25 18:02:21 -070055 PARTIAL_UPDATES = 0x00020000, // video driver feature
56 SLOW_CONFIG = 0x00040000, // software
57 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 };
59
60 DisplayHardware(
61 const sp<SurfaceFlinger>& flinger,
62 uint32_t displayIndex);
63
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070064 virtual ~DisplayHardware();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
66 void releaseScreen() const;
67 void acquireScreen() const;
68
69 // Flip the front and back buffers if the back buffer is "dirty". Might
70 // be instantaneous, might involve copying the frame buffer around.
71 void flip(const Region& dirty) const;
72
73 float getDpiX() const;
74 float getDpiY() const;
75 float getRefreshRate() const;
76 float getDensity() const;
77 int getWidth() const;
78 int getHeight() const;
79 PixelFormat getFormat() const;
80 uint32_t getFlags() const;
Mathias Agopianca99fb82010-04-14 16:43:44 -070081 uint32_t getMaxTextureSize() const;
82 uint32_t getMaxViewportDims() const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080083 nsecs_t getRefreshPeriod() const;
84 nsecs_t getRefreshTimestamp() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070085 void makeCurrent() const;
86
87
88 void setVSyncHandler(const sp<VSyncHandler>& handler);
89
Mathias Agopian03e40722012-04-26 16:11:59 -070090 enum {
91 EVENT_VSYNC = HWC_EVENT_VSYNC
92 };
93
94 void eventControl(int event, int enabled);
95
Mathias Agopiand0566bc2011-11-17 17:49:17 -080096
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopian3094df32012-06-18 18:06:45 -070099 EGLConfig getEGLConfig() const { return mConfig; }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700100
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800101 void dump(String8& res) const;
102
Mathias Agopiana350ff92010-08-10 17:14:02 -0700103 // Hardware Composer
104 HWComposer& getHwComposer() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105
Mathias Agopian74faca22009-09-17 16:18:16 -0700106 status_t compositionComplete() const;
107
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700108 Rect getBounds() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 return Rect(mWidth, mHeight);
110 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700111 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112
113private:
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700114 virtual void onVSyncReceived(int dpy, nsecs_t timestamp);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115 void init(uint32_t displayIndex) __attribute__((noinline));
116 void fini() __attribute__((noinline));
117
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700118 sp<SurfaceFlinger> mFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 EGLDisplay mDisplay;
120 EGLSurface mSurface;
121 EGLContext mContext;
122 EGLConfig mConfig;
123 float mDpiX;
124 float mDpiY;
125 float mRefreshRate;
126 float mDensity;
127 int mWidth;
128 int mHeight;
129 PixelFormat mFormat;
130 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700131 mutable uint32_t mPageFlipCount;
Mathias Agopian3d64e732011-04-18 15:59:24 -0700132 GLint mMaxViewportDims[2];
Mathias Agopianca99fb82010-04-14 16:43:44 -0700133 GLint mMaxTextureSize;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800134
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800135 nsecs_t mRefreshPeriod;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800136 mutable nsecs_t mLastHwVSync;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800137
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700138 // constant once set
Mathias Agopiana350ff92010-08-10 17:14:02 -0700139 HWComposer* mHwc;
Mathias Agopian03e40722012-04-26 16:11:59 -0700140 PowerHAL mPowerHAL;
141
Mathias Agopiana350ff92010-08-10 17:14:02 -0700142
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700143 mutable Mutex mLock;
144
145 // protected by mLock
146 wp<VSyncHandler> mVSyncHandler;
147
Mathias Agopian3e876012012-06-07 17:52:54 -0700148 sp<FramebufferSurface> mNativeWindow;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149};
150
151}; // namespace android
152
153#endif // ANDROID_DISPLAY_HARDWARE_H