blob: 98579b47aec7ce205328563a0951cdca3077b3ae [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 Agopian3eb38cb2012-04-03 22:09:52 -070048
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 enum {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070050 PARTIAL_UPDATES = 0x00020000, // video driver feature
Mathias Agopian1f7bec62010-06-25 18:02:21 -070051 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 };
53
54 DisplayHardware(
55 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070056 int dpy,
57 const sp<SurfaceTextureClient>& surface,
58 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070060 virtual ~DisplayHardware();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 // 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
Mathias Agopian86303202012-07-24 22:46:10 -070066 void onVSyncReceived(nsecs_t timestamp);
67
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 float getDpiX() const;
69 float getDpiY() const;
70 float getRefreshRate() const;
71 float getDensity() const;
72 int getWidth() const;
73 int getHeight() const;
74 PixelFormat getFormat() const;
75 uint32_t getFlags() const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080076 nsecs_t getRefreshPeriod() const;
77 nsecs_t getRefreshTimestamp() const;
Mathias Agopianc666cae2012-07-25 18:56:13 -070078 status_t getInfo(DisplayInfo* info) const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070079
Mathias Agopiana4912602012-07-12 14:25:33 -070080 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070081
82 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
83 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
84 bool getSecureLayerVisible() const;
85
Mathias Agopian1b031492012-06-20 17:51:20 -070086 status_t setOrientation(int orientation);
87 int getOrientation() const { return mOrientation; }
88 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070089
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiana350ff92010-08-10 17:14:02 -070092
Erik Gilling1d21a9c2010-12-01 16:38:01 -080093 void dump(String8& res) const;
94
Mathias Agopian74faca22009-09-17 16:18:16 -070095 status_t compositionComplete() const;
96
Mathias Agopian9c6e2972011-09-20 17:21:56 -070097 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -070098 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -0700100 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101
102private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700103 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104
Mathias Agopiana4912602012-07-12 14:25:33 -0700105 /*
106 * Constants, set during initialization
107 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700108 sp<SurfaceFlinger> mFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -0700109 int mDisplayId;
Mathias Agopiana4912602012-07-12 14:25:33 -0700110 // ANativeWindow this display is rendering into
111 sp<SurfaceTextureClient> mNativeWindow;
112 // set if mNativeWindow is a FramebufferSurface
113 sp<FramebufferSurface> mFramebufferSurface;
114
115
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 EGLDisplay mDisplay;
117 EGLSurface mSurface;
118 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 float mDpiX;
120 float mDpiY;
121 float mRefreshRate;
122 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700123 int mDisplayWidth;
124 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125 PixelFormat mFormat;
126 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700127 mutable uint32_t mPageFlipCount;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800128
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800129 nsecs_t mRefreshPeriod;
Mathias Agopian03e40722012-04-26 16:11:59 -0700130
Mathias Agopiana4912602012-07-12 14:25:33 -0700131 /*
132 * Can only accessed from the main thread, these members
133 * don't need synchronization.
134 */
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700135 // list of visible layers on that display
136 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
137 // Whether we have a visible secure layer on this display
138 bool mSecureLayerVisible;
139
Mathias Agopiana350ff92010-08-10 17:14:02 -0700140
Mathias Agopian1b031492012-06-20 17:51:20 -0700141 // this used to be in GraphicPlane
142 static status_t orientationToTransfrom(int orientation, int w, int h,
143 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700144 Transform mGlobalTransform;
145 int mOrientation;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700146
Mathias Agopiana4912602012-07-12 14:25:33 -0700147 /*
148 * protected by mLock
149 */
Mathias Agopian98a121a2012-07-24 21:08:59 -0700150 mutable Mutex mLock;
Mathias Agopian86303202012-07-24 22:46:10 -0700151 mutable nsecs_t mLastHwVSync;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800152};
153
154}; // namespace android
155
156#endif // ANDROID_DISPLAY_HARDWARE_H