blob: 80d20cb9bd2729268435d8aa6da55bfc449d1729 [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 Agopian86303202012-07-24 22:46:10 -070030#include <utils/Mutex.h>
31#include <utils/Timers.h>
32
Mathias Agopian1b031492012-06-20 17:51:20 -070033#include "Transform.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070034
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include "DisplayHardware/DisplayHardwareBase.h"
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037namespace android {
38
Mathias Agopianc666cae2012-07-25 18:56:13 -070039class DisplayInfo;
Mathias Agopian3e876012012-06-07 17:52:54 -070040class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070041class LayerBase;
42class SurfaceFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -070043class SurfaceTextureClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Mathias Agopian86303202012-07-24 22:46:10 -070045class DisplayHardware : public DisplayHardwareBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046{
47public:
Mathias Agopian87baae12012-07-31 12:38:26 -070048 // region in layer-stack space
49 mutable Region dirtyRegion;
50 // region in screen space
51 mutable Region swapRegion;
52 // region in screen space
53 Region undefinedRegion;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070054
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 enum {
Mathias Agopian87baae12012-07-31 12:38:26 -070056 PARTIAL_UPDATES = 0x00020000, // video driver feature
57 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 };
59
60 DisplayHardware(
61 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070062 int dpy,
63 const sp<SurfaceTextureClient>& surface,
64 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070066 virtual ~DisplayHardware();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 // Flip the front and back buffers if the back buffer is "dirty". Might
69 // be instantaneous, might involve copying the frame buffer around.
70 void flip(const Region& dirty) const;
71
Mathias Agopian86303202012-07-24 22:46:10 -070072 void onVSyncReceived(nsecs_t timestamp);
73
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 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 Agopianc666cae2012-07-25 18:56:13 -070084 status_t getInfo(DisplayInfo* info) const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070085
Mathias Agopiana4912602012-07-12 14:25:33 -070086 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070087
88 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
89 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
90 bool getSecureLayerVisible() const;
91
Mathias Agopian1b031492012-06-20 17:51:20 -070092 status_t setOrientation(int orientation);
93 int getOrientation() const { return mOrientation; }
94 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian87baae12012-07-31 12:38:26 -070095 uint32_t getLayerStack() const { return mLayerStack; }
96
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070097
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700100
Erik Gilling1d21a9c2010-12-01 16:38:01 -0800101 void dump(String8& res) const;
102
Mathias Agopian74faca22009-09-17 16:18:16 -0700103 status_t compositionComplete() const;
104
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700105 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -0700106 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700108 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
110private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700111 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112
Mathias Agopiana4912602012-07-12 14:25:33 -0700113 /*
114 * Constants, set during initialization
115 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700116 sp<SurfaceFlinger> mFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -0700117 int mDisplayId;
Mathias Agopiana4912602012-07-12 14:25:33 -0700118 // ANativeWindow this display is rendering into
119 sp<SurfaceTextureClient> mNativeWindow;
120 // set if mNativeWindow is a FramebufferSurface
121 sp<FramebufferSurface> mFramebufferSurface;
122
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124 EGLDisplay mDisplay;
125 EGLSurface mSurface;
126 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127 float mDpiX;
128 float mDpiY;
129 float mRefreshRate;
130 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700131 int mDisplayWidth;
132 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 PixelFormat mFormat;
134 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700135 mutable uint32_t mPageFlipCount;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800136
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800137 nsecs_t mRefreshPeriod;
Mathias Agopian03e40722012-04-26 16:11:59 -0700138
Mathias Agopiana4912602012-07-12 14:25:33 -0700139 /*
140 * Can only accessed from the main thread, these members
141 * don't need synchronization.
142 */
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700143 // list of visible layers on that display
144 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
145 // Whether we have a visible secure layer on this display
146 bool mSecureLayerVisible;
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);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700152 Transform mGlobalTransform;
153 int mOrientation;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700154
Mathias Agopian87baae12012-07-31 12:38:26 -0700155 uint32_t mLayerStack;
156
157
Mathias Agopiana4912602012-07-12 14:25:33 -0700158 /*
159 * protected by mLock
160 */
Mathias Agopian98a121a2012-07-24 21:08:59 -0700161 mutable Mutex mLock;
Mathias Agopian86303202012-07-24 22:46:10 -0700162 mutable nsecs_t mLastHwVSync;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163};
164
165}; // namespace android
166
167#endif // ANDROID_DISPLAY_HARDWARE_H