blob: 88a8c0d07d2b33ba6c6974442f05751a54f0e1e8 [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 Agopian3e876012012-06-07 17:52:54 -070039class FramebufferSurface;
Mathias Agopian86303202012-07-24 22:46:10 -070040class LayerBase;
41class SurfaceFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -070042class SurfaceTextureClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Mathias Agopian86303202012-07-24 22:46:10 -070044class DisplayHardware : public DisplayHardwareBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045{
46public:
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070047
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048 enum {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070049 PARTIAL_UPDATES = 0x00020000, // video driver feature
Mathias Agopian1f7bec62010-06-25 18:02:21 -070050 SWAP_RECTANGLE = 0x00080000,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 };
52
53 DisplayHardware(
54 const sp<SurfaceFlinger>& flinger,
Mathias Agopiana4912602012-07-12 14:25:33 -070055 int dpy,
56 const sp<SurfaceTextureClient>& surface,
57 EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070059 virtual ~DisplayHardware();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 // Flip the front and back buffers if the back buffer is "dirty". Might
62 // be instantaneous, might involve copying the frame buffer around.
63 void flip(const Region& dirty) const;
64
Mathias Agopian86303202012-07-24 22:46:10 -070065 void onVSyncReceived(nsecs_t timestamp);
66
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 float getDpiX() const;
68 float getDpiY() const;
69 float getRefreshRate() const;
70 float getDensity() const;
71 int getWidth() const;
72 int getHeight() const;
73 PixelFormat getFormat() const;
74 uint32_t getFlags() const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080075 nsecs_t getRefreshPeriod() const;
76 nsecs_t getRefreshTimestamp() const;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070077
Mathias Agopiana4912602012-07-12 14:25:33 -070078 EGLSurface getEGLSurface() const;
Mathias Agopian3b1d2b62012-07-11 13:48:17 -070079
80 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers);
81 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const;
82 bool getSecureLayerVisible() const;
83
Mathias Agopian1b031492012-06-20 17:51:20 -070084 status_t setOrientation(int orientation);
85 int getOrientation() const { return mOrientation; }
86 const Transform& getTransform() const { return mGlobalTransform; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070087
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 uint32_t getPageFlipCount() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 EGLDisplay getEGLDisplay() const { return mDisplay; }
Mathias Agopiana350ff92010-08-10 17:14:02 -070090
Erik Gilling1d21a9c2010-12-01 16:38:01 -080091 void dump(String8& res) const;
92
Mathias Agopian74faca22009-09-17 16:18:16 -070093 status_t compositionComplete() const;
94
Mathias Agopian9c6e2972011-09-20 17:21:56 -070095 Rect getBounds() const {
Mathias Agopian1b031492012-06-20 17:51:20 -070096 return Rect(mDisplayWidth, mDisplayHeight);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 }
Mathias Agopian9c6e2972011-09-20 17:21:56 -070098 inline Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099
100private:
Mathias Agopiana4912602012-07-12 14:25:33 -0700101 void init(EGLConfig config);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102
Mathias Agopiana4912602012-07-12 14:25:33 -0700103 /*
104 * Constants, set during initialization
105 */
Mathias Agopianc7d14e22011-08-01 16:32:21 -0700106 sp<SurfaceFlinger> mFlinger;
Mathias Agopiana4912602012-07-12 14:25:33 -0700107 int mDisplayId;
Mathias Agopiana4912602012-07-12 14:25:33 -0700108 // ANativeWindow this display is rendering into
109 sp<SurfaceTextureClient> mNativeWindow;
110 // set if mNativeWindow is a FramebufferSurface
111 sp<FramebufferSurface> mFramebufferSurface;
112
113
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114 EGLDisplay mDisplay;
115 EGLSurface mSurface;
116 EGLContext mContext;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 float mDpiX;
118 float mDpiY;
119 float mRefreshRate;
120 float mDensity;
Mathias Agopian1b031492012-06-20 17:51:20 -0700121 int mDisplayWidth;
122 int mDisplayHeight;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123 PixelFormat mFormat;
124 uint32_t mFlags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700125 mutable uint32_t mPageFlipCount;
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800126
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800127 nsecs_t mRefreshPeriod;
Mathias Agopian03e40722012-04-26 16:11:59 -0700128
Mathias Agopiana4912602012-07-12 14:25:33 -0700129 /*
130 * Can only accessed from the main thread, these members
131 * don't need synchronization.
132 */
Mathias Agopian3b1d2b62012-07-11 13:48:17 -0700133 // list of visible layers on that display
134 Vector< sp<LayerBase> > mVisibleLayersSortedByZ;
135 // Whether we have a visible secure layer on this display
136 bool mSecureLayerVisible;
137
Mathias Agopiana350ff92010-08-10 17:14:02 -0700138
Mathias Agopian1b031492012-06-20 17:51:20 -0700139 // this used to be in GraphicPlane
140 static status_t orientationToTransfrom(int orientation, int w, int h,
141 Transform* tr);
Mathias Agopian98a121a2012-07-24 21:08:59 -0700142 Transform mGlobalTransform;
143 int mOrientation;
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700144
Mathias Agopiana4912602012-07-12 14:25:33 -0700145 /*
146 * protected by mLock
147 */
Mathias Agopian98a121a2012-07-24 21:08:59 -0700148 mutable Mutex mLock;
Mathias Agopian86303202012-07-24 22:46:10 -0700149 mutable nsecs_t mLastHwVSync;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150};
151
152}; // namespace android
153
154#endif // ANDROID_DISPLAY_HARDWARE_H