blob: 0a828b3dcfb0ffb88ceadb488a7b28d817996f1d [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian1473f462009-04-10 14:24:30 -070025#include <GLES/gl.h>
26#include <GLES/glext.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <EGL/egl.h>
Mathias Agopian1473f462009-04-10 14:24:30 -070028#include <EGL/eglext.h>
29
Mathias Agopian781953d2010-06-25 18:02:21 -070030#include "GLExtensions.h"
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032#include "DisplayHardware/DisplayHardwareBase.h"
Mathias Agopian79f39eb2011-11-17 17:49:17 -080033#include "DisplayHardware/VSyncBarrier.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035namespace android {
36
Mathias Agopian1473f462009-04-10 14:24:30 -070037class FramebufferNativeWindow;
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070038class HWComposer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40class DisplayHardware : public DisplayHardwareBase
41{
42public:
43 enum {
Mathias Agopian781953d2010-06-25 18:02:21 -070044 COPY_BITS_EXTENSION = 0x00000008,
45 BUFFER_PRESERVED = 0x00010000,
46 PARTIAL_UPDATES = 0x00020000, // video driver feature
47 SLOW_CONFIG = 0x00040000, // software
48 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 };
50
51 DisplayHardware(
52 const sp<SurfaceFlinger>& flinger,
53 uint32_t displayIndex);
54
55 ~DisplayHardware();
56
57 void releaseScreen() const;
58 void acquireScreen() const;
59
60 // Flip the front and back buffers if the back buffer is "dirty". Might
61 // be instantaneous, might involve copying the frame buffer around.
62 void flip(const Region& dirty) const;
63
64 float getDpiX() const;
65 float getDpiY() const;
66 float getRefreshRate() const;
67 float getDensity() const;
68 int getWidth() const;
69 int getHeight() const;
70 PixelFormat getFormat() const;
71 uint32_t getFlags() const;
72 void makeCurrent() const;
Mathias Agopian967dce32010-04-14 16:43:44 -070073 uint32_t getMaxTextureSize() const;
74 uint32_t getMaxViewportDims() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
Mathias Agopian79f39eb2011-11-17 17:49:17 -080076 // waits for the next vsync and returns the timestamp of when it happened
Mathias Agopian1d997952012-01-19 18:34:40 -080077 nsecs_t waitForRefresh() const;
78 nsecs_t getRefreshPeriod() const;
79 nsecs_t getRefreshTimestamp() const;
Mathias Agopian79f39eb2011-11-17 17:49:17 -080080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 uint32_t getPageFlipCount() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070083
Erik Gilling94720d72010-12-01 16:38:01 -080084 void dump(String8& res) const;
85
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070086 // Hardware Composer
87 HWComposer& getHwComposer() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Mathias Agopianb1a18742009-09-17 16:18:16 -070089 status_t compositionComplete() const;
90
Mathias Agopian88cde072011-09-20 17:21:56 -070091 Rect getBounds() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 return Rect(mWidth, mHeight);
93 }
Mathias Agopian88cde072011-09-20 17:21:56 -070094 inline Rect bounds() const { return getBounds(); }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
96private:
97 void init(uint32_t displayIndex) __attribute__((noinline));
98 void fini() __attribute__((noinline));
Mathias Agopian79f39eb2011-11-17 17:49:17 -080099 int32_t getDelayToNextVSyncUs(nsecs_t* timestamp) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
Mathias Agopiana0bd0d82011-08-01 16:32:21 -0700101 sp<SurfaceFlinger> mFlinger;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 EGLDisplay mDisplay;
103 EGLSurface mSurface;
104 EGLContext mContext;
105 EGLConfig mConfig;
106 float mDpiX;
107 float mDpiY;
108 float mRefreshRate;
109 float mDensity;
110 int mWidth;
111 int mHeight;
112 PixelFormat mFormat;
113 uint32_t mFlags;
Mathias Agopian1473f462009-04-10 14:24:30 -0700114 mutable uint32_t mPageFlipCount;
Mathias Agopianc94dce52011-04-18 15:59:24 -0700115 GLint mMaxViewportDims[2];
Mathias Agopian967dce32010-04-14 16:43:44 -0700116 GLint mMaxTextureSize;
Mathias Agopian79f39eb2011-11-17 17:49:17 -0800117 VSyncBarrier mVSync;
118
119 mutable Mutex mFakeVSyncMutex;
120 mutable nsecs_t mNextFakeVSync;
121 nsecs_t mRefreshPeriod;
Mathias Agopian1d997952012-01-19 18:34:40 -0800122 mutable nsecs_t mLastHwVSync;
Mathias Agopian79f39eb2011-11-17 17:49:17 -0800123
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -0700124 HWComposer* mHwc;
125
Mathias Agopian1473f462009-04-10 14:24:30 -0700126 sp<FramebufferNativeWindow> mNativeWindow;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127};
128
129}; // namespace android
130
131#endif // ANDROID_DISPLAY_HARDWARE_H