blob: 02be4dcba7fd8037c4999cf2c048c7a898fee719 [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
30#include <pixelflinger/pixelflinger.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
Mathias Agopian1f7bec62010-06-25 18:02:21 -070032#include "GLExtensions.h"
33
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include "DisplayHardware/DisplayHardwareBase.h"
Mathias Agopiand0566bc2011-11-17 17:49:17 -080035#include "DisplayHardware/VSyncBarrier.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 Agopian076b1cc2009-04-10 14:24:30 -070039class FramebufferNativeWindow;
Mathias Agopiana350ff92010-08-10 17:14:02 -070040class HWComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
42class DisplayHardware : public DisplayHardwareBase
43{
44public:
45 enum {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070046 COPY_BITS_EXTENSION = 0x00000008,
47 BUFFER_PRESERVED = 0x00010000,
48 PARTIAL_UPDATES = 0x00020000, // video driver feature
49 SLOW_CONFIG = 0x00040000, // software
50 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 };
52
53 DisplayHardware(
54 const sp<SurfaceFlinger>& flinger,
55 uint32_t displayIndex);
56
57 ~DisplayHardware();
58
59 void releaseScreen() const;
60 void acquireScreen() const;
61
62 // Flip the front and back buffers if the back buffer is "dirty". Might
63 // be instantaneous, might involve copying the frame buffer around.
64 void flip(const Region& dirty) const;
65
66 float getDpiX() const;
67 float getDpiY() const;
68 float getRefreshRate() const;
69 float getDensity() const;
70 int getWidth() const;
71 int getHeight() const;
72 PixelFormat getFormat() const;
73 uint32_t getFlags() const;
74 void makeCurrent() const;
Mathias Agopianca99fb82010-04-14 16:43:44 -070075 uint32_t getMaxTextureSize() const;
76 uint32_t getMaxViewportDims() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077
Mathias Agopiand0566bc2011-11-17 17:49:17 -080078 // waits for the next vsync and returns the timestamp of when it happened
Mathias Agopian82d7ab62012-01-19 18:34:40 -080079 nsecs_t waitForRefresh() const;
80 nsecs_t getRefreshPeriod() const;
81 nsecs_t getRefreshTimestamp() const;
Mathias Agopiand0566bc2011-11-17 17:49:17 -080082
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiana350ff92010-08-10 17:14:02 -070085
Erik Gilling1d21a9c2010-12-01 16:38:01 -080086 void dump(String8& res) const;
87
Mathias Agopiana350ff92010-08-10 17:14:02 -070088 // Hardware Composer
89 HWComposer& getHwComposer() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090
Mathias Agopian74faca22009-09-17 16:18:16 -070091 status_t compositionComplete() const;
92
Mathias Agopian9c6e2972011-09-20 17:21:56 -070093 Rect getBounds() const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 return Rect(mWidth, mHeight);
95 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -070096 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097
98private:
99 void init(uint32_t displayIndex) __attribute__((noinline));
100 void fini() __attribute__((noinline));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800101 int32_t getDelayToNextVSyncUs(nsecs_t* timestamp) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700103 sp<SurfaceFlinger> mFlinger;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 EGLDisplay mDisplay;
105 EGLSurface mSurface;
106 EGLContext mContext;
107 EGLConfig mConfig;
108 float mDpiX;
109 float mDpiY;
110 float mRefreshRate;
111 float mDensity;
112 int mWidth;
113 int mHeight;
114 PixelFormat mFormat;
115 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700116 mutable uint32_t mPageFlipCount;
Mathias Agopian3d64e732011-04-18 15:59:24 -0700117 GLint mMaxViewportDims[2];
Mathias Agopianca99fb82010-04-14 16:43:44 -0700118 GLint mMaxTextureSize;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800119 VSyncBarrier mVSync;
120
121 mutable Mutex mFakeVSyncMutex;
122 mutable nsecs_t mNextFakeVSync;
123 nsecs_t mRefreshPeriod;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800124 mutable nsecs_t mLastHwVSync;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800125
Mathias Agopiana350ff92010-08-10 17:14:02 -0700126 HWComposer* mHwc;
127
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700128 sp<FramebufferNativeWindow> mNativeWindow;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129};
130
131}; // namespace android
132
133#endif // ANDROID_DISPLAY_HARDWARE_H