1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  * Copyright (C) 2012, The Linux Foundation. All rights reserved.
4  *
5  * Not a Contribution, Apache license notifications and license are
6  * retained for attribution purposes only.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef HWC_FBUPDATE_H
21 #define HWC_FBUPDATE_H
22 #include "hwc_utils.h"
23 #include "overlay.h"
24 
25 #define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
26 #define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
27 
28 namespace overlay {
29     class Rotator;
30 }
31 
32 namespace qhwc {
33 namespace ovutils = overlay::utils;
34 
35 //Framebuffer update Interface
36 class IFBUpdate {
37 public:
38     explicit IFBUpdate(hwc_context_t *ctx, const int& dpy);
~IFBUpdate()39     virtual ~IFBUpdate() {};
40     // Sets up members and prepares overlay if conditions are met
41     virtual bool prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
42             hwc_rect_t fbUpdatingRect, int fbZorder) = 0;
43     virtual bool prepareAndValidate(hwc_context_t *ctx,
44             hwc_display_contents_1 *list, int fbZorder);
45     // Draws layer
46     virtual bool draw(hwc_context_t *ctx, private_handle_t *hnd) = 0;
47     //Reset values
48     virtual void reset();
49     //Factory method that returns a low-res or high-res version
50     static IFBUpdate *getObject(hwc_context_t *ctx, const int& dpy);
51 
52 protected:
53     const int mDpy; // display to update
54     bool mModeOn; // if prepare happened
55     overlay::Rotator *mRot;
56     int mAlignedFBWidth;
57     int mAlignedFBHeight;
58     int mTileEnabled;
59 };
60 
61 //Non-Split panel handler.
62 class FBUpdateNonSplit : public IFBUpdate {
63 public:
64     explicit FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy);
~FBUpdateNonSplit()65     virtual ~FBUpdateNonSplit() {};
66     bool prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
67             hwc_rect_t fbUpdatingRect, int fbZorder);
68     bool draw(hwc_context_t *ctx, private_handle_t *hnd);
69     void reset();
70 private:
71     bool configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
72             hwc_rect_t fbUpdatingRect, int fbZorder);
73     bool preRotateExtDisplay(hwc_context_t *ctx,
74                                  hwc_layer_1_t *layer,
75                                  ovutils::Whf &info,
76                                  hwc_rect_t& sourceCrop,
77                                  ovutils::eMdpFlags& mdpFlags,
78                                  int& rotFlags);
79     ovutils::eDest mDest; //pipe to draw on
80 };
81 
82 //Split panel handler.
83 class FBUpdateSplit : public IFBUpdate {
84 public:
85     explicit FBUpdateSplit(hwc_context_t *ctx, const int& dpy);
~FBUpdateSplit()86     virtual ~FBUpdateSplit() {};
87     bool prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
88             hwc_rect_t fbUpdatingRect, int fbZorder);
89     bool draw(hwc_context_t *ctx, private_handle_t *hnd);
90     void reset();
91 
92 protected:
93     virtual bool configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
94             hwc_rect_t fbUpdatingRect, int fbZorder);
95     ovutils::eDest mDestLeft; //left pipe to draw on
96     ovutils::eDest mDestRight; //right pipe to draw on
97 };
98 
99 //Source Split Handler
100 class FBSrcSplit : public FBUpdateSplit {
101 public:
102     explicit FBSrcSplit(hwc_context_t *ctx, const int& dpy);
~FBSrcSplit()103     virtual ~FBSrcSplit() {};
104 private:
105     bool configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
106             hwc_rect_t fbUpdatingRect, int fbZorder);
107 };
108 
109 }; //namespace qhwc
110 
111 #endif //HWC_FBUPDATE_H
112