1 /* Copyright 2013 Mozilla Foundation and Mozilla contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GONKDISPLAYJB_H
17 #define GONKDISPLAYJB_H
18 
19 #include "DisplaySurface.h"
20 #include "GonkDisplay.h"
21 #include "hardware/hwcomposer.h"
22 #include "hardware/power.h"
23 #include "ui/Fence.h"
24 #include "utils/RefBase.h"
25 
26 namespace mozilla {
27 
28 class MOZ_EXPORT GonkDisplayJB : public GonkDisplay {
29 public:
30     GonkDisplayJB();
31     ~GonkDisplayJB();
32 
33     virtual void SetEnabled(bool enabled);
34 
35     virtual void OnEnabled(OnEnabledCallbackType callback);
36 
37     virtual void* GetHWCDevice();
38 
39     virtual bool SwapBuffers(EGLDisplay dpy, EGLSurface sur);
40 
41     virtual ANativeWindowBuffer* DequeueBuffer();
42 
43     virtual bool QueueBuffer(ANativeWindowBuffer* buf);
44 
45     virtual void UpdateDispSurface(EGLDisplay dpy, EGLSurface sur);
46 
47     bool Post(buffer_handle_t buf, int fence);
48 
49     virtual NativeData GetNativeData(
50         GonkDisplay::DisplayType aDisplayType,
51         android::IGraphicBufferProducer* aSink = nullptr);
52 
53     virtual void NotifyBootAnimationStopped();
54 
55 private:
56     void CreateFramebufferSurface(android::sp<ANativeWindow>& aNativeWindow,
57                                   android::sp<android::DisplaySurface>& aDisplaySurface,
58                                   uint32_t aWidth, uint32_t aHeight);
59     void CreateVirtualDisplaySurface(android::IGraphicBufferProducer* aSink,
60                                      android::sp<ANativeWindow>& aNativeWindow,
61                                      android::sp<android::DisplaySurface>& aDisplaySurface);
62 
63     void PowerOnDisplay(int aDpy);
64 
65     int DoQueueBuffer(ANativeWindowBuffer* buf);
66 
67     hw_module_t const*        mModule;
68     hw_module_t const*        mFBModule;
69     hwc_composer_device_1_t*  mHwc;
70     framebuffer_device_t*     mFBDevice;
71     power_module_t*           mPowerModule;
72     android::sp<android::DisplaySurface> mDispSurface;
73     android::sp<ANativeWindow> mSTClient;
74     android::sp<android::DisplaySurface> mBootAnimDispSurface;
75     android::sp<ANativeWindow> mBootAnimSTClient;
76     android::sp<android::IGraphicBufferAlloc> mAlloc;
77     hwc_display_contents_1_t* mList;
78     uint32_t mWidth;
79     uint32_t mHeight;
80     OnEnabledCallbackType mEnabledCallback;
81 };
82 
83 }
84 
85 #endif /* GONKDISPLAYJB_H */
86