• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
25 #include <GLES/gl.h>
26 #include <GLES/glext.h>
27 #include <EGL/egl.h>
28 #include <EGL/eglext.h>
29 
30 #include "GLExtensions.h"
31 
32 #include "DisplayHardware/DisplayHardwareBase.h"
33 #include "HWComposer.h"
34 #include "PowerHAL.h"
35 
36 namespace android {
37 
38 class FramebufferNativeWindow;
39 
40 class DisplayHardware :
41     public DisplayHardwareBase,
42     public HWComposer::EventHandler
43 {
44 public:
45 
46     class VSyncHandler : virtual public RefBase {
47         friend class DisplayHardware;
48         virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0;
49     protected:
~VSyncHandler()50         virtual ~VSyncHandler() {}
51     };
52 
53     enum {
54         COPY_BITS_EXTENSION         = 0x00000008,
55         PARTIAL_UPDATES             = 0x00020000,   // video driver feature
56         SLOW_CONFIG                 = 0x00040000,   // software
57         SWAP_RECTANGLE              = 0x00080000,
58     };
59 
60     DisplayHardware(
61             const sp<SurfaceFlinger>& flinger,
62             uint32_t displayIndex);
63 
64     virtual ~DisplayHardware();
65 
66     void releaseScreen() const;
67     void acquireScreen() const;
68 
69     // Flip the front and back buffers if the back buffer is "dirty".  Might
70     // be instantaneous, might involve copying the frame buffer around.
71     void flip(const Region& dirty) const;
72 
73     float       getDpiX() const;
74     float       getDpiY() const;
75     float       getRefreshRate() const;
76     float       getDensity() const;
77     int         getWidth() const;
78     int         getHeight() const;
79     PixelFormat getFormat() const;
80     uint32_t    getFlags() const;
81     uint32_t    getMaxTextureSize() const;
82     uint32_t    getMaxViewportDims() const;
83     nsecs_t     getRefreshPeriod() const;
84     nsecs_t     getRefreshTimestamp() const;
85     void        makeCurrent() const;
86 
87 
88     void setVSyncHandler(const sp<VSyncHandler>& handler);
89 
90     enum {
91         EVENT_VSYNC = HWC_EVENT_VSYNC
92     };
93 
94     void eventControl(int event, int enabled);
95 
96 
97     uint32_t getPageFlipCount() const;
getEGLDisplay()98     EGLDisplay getEGLDisplay() const { return mDisplay; }
99 
100     void dump(String8& res) const;
101 
102     // Hardware Composer
103     HWComposer& getHwComposer() const;
104 
105     status_t compositionComplete() const;
106 
getBounds()107     Rect getBounds() const {
108         return Rect(mWidth, mHeight);
109     }
bounds()110     inline Rect bounds() const { return getBounds(); }
111 
112 private:
113     virtual void onVSyncReceived(int dpy, nsecs_t timestamp);
114     void init(uint32_t displayIndex) __attribute__((noinline));
115     void fini() __attribute__((noinline));
116 
117     sp<SurfaceFlinger> mFlinger;
118     EGLDisplay      mDisplay;
119     EGLSurface      mSurface;
120     EGLContext      mContext;
121     EGLConfig       mConfig;
122     float           mDpiX;
123     float           mDpiY;
124     float           mRefreshRate;
125     float           mDensity;
126     int             mWidth;
127     int             mHeight;
128     PixelFormat     mFormat;
129     uint32_t        mFlags;
130     mutable uint32_t mPageFlipCount;
131     GLint           mMaxViewportDims[2];
132     GLint           mMaxTextureSize;
133 
134     nsecs_t         mRefreshPeriod;
135     mutable nsecs_t mLastHwVSync;
136 
137     // constant once set
138     HWComposer*     mHwc;
139     PowerHAL        mPowerHAL;
140 
141 
142     mutable Mutex   mLock;
143 
144     // protected by mLock
145     wp<VSyncHandler>    mVSyncHandler;
146 
147     sp<FramebufferNativeWindow> mNativeWindow;
148 };
149 
150 }; // namespace android
151 
152 #endif // ANDROID_DISPLAY_HARDWARE_H
153