blob: 4442afc8b4602c2c038582ad29d570e8c38bed3b [file] [log] [blame]
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08003 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed31da0b12012-07-31 18:55:33 -07004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * 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_COPYBIT_H
21#define HWC_COPYBIT_H
22#include "hwc_utils.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070023
Xiaoming Zhoub49438c2013-07-02 19:17:59 -040024#define NUM_RENDER_BUFFERS 3
Terence Hampson6b0a4272013-11-06 16:04:51 -050025//These scaling factors are specific for MDP3. Normally scaling factor
26//is only 4, but copybit will create temp buffer to let it run through
27//twice
28#define MAX_SCALE_FACTOR 16
29#define MIN_SCALE_FACTOR 0.0625
Ramakant Singh467759f2014-04-16 11:09:40 +053030#define MAX_LAYERS_FOR_ABC 2
Naseer Ahmed31da0b12012-07-31 18:55:33 -070031namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070032
Naseer Ahmed31da0b12012-07-31 18:55:33 -070033class CopyBit {
34public:
Saurabh Shah220a30c2013-10-29 16:12:12 -070035 CopyBit(hwc_context_t *ctx, const int& dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080036 ~CopyBit();
37 // API to get copybit engine(non static)
38 struct copybit_device_t *getCopyBitDevice();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070039 //Sets up members and prepares copybit if conditions are met
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080040 bool prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
41 int dpy);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070042 //Draws layer if the layer is set for copybit in prepare
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043 bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
44 int dpy, int* fd);
45 // resets the values
46 void reset();
Naseer Ahmed64b81212013-02-14 10:29:47 -050047
48 private_handle_t * getCurrentRenderBuffer();
49
50 void setReleaseFd(int fd);
51
Sushil Chauhandefd3522014-05-13 18:17:12 -070052 void setReleaseFdSync(int fd);
53
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070054 bool prepareOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Sushil Chauhandefd3522014-05-13 18:17:12 -070055
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070056 int drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Sushil Chauhandefd3522014-05-13 18:17:12 -070057
Naseer Ahmed31da0b12012-07-31 18:55:33 -070058private:
Ramakant Singh21cec722014-03-07 19:11:45 +053059 /* cached data */
60 struct LayerCache {
61 int layerCount;
62 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +053063 hwc_rect_t displayFrame[MAX_NUM_APP_LAYERS];
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +053064 bool drop[MAX_NUM_APP_LAYERS];
Ramakant Singh21cec722014-03-07 19:11:45 +053065 /* c'tor */
66 LayerCache();
67 /* clear caching info*/
68 void reset();
69 void updateCounts(hwc_context_t *ctx, hwc_display_contents_1_t *list,
70 int dpy);
71 };
72 /* framebuffer cache*/
73 struct FbCache {
74 hwc_rect_t FbdirtyRect[NUM_RENDER_BUFFERS];
75 int FbIndex;
76 FbCache();
77 void reset();
78 void insertAndUpdateFbCache(hwc_rect_t dirtyRect);
79 int getUnchangedFbDRCount(hwc_rect_t dirtyRect);
80 };
81
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080082 // holds the copybit device
83 struct copybit_device_t *mEngine;
Ramakant Singh0def28c2014-03-28 20:43:13 +053084 bool drawUsingAppBufferComposition(hwc_context_t *ctx,
85 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +053086 int dpy, int *fd);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080087 // Helper functions for copybit composition
88 int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -080089 private_handle_t *renderBuffer, bool isFG);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070090 // Helper function to draw copybit layer for PTOR comp
Sushil Chauhandefd3522014-05-13 18:17:12 -070091 int drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070092 private_handle_t *renderBuffer, hwc_rect_t overlap,
93 hwc_rect_t destRect);
Sushil Chauhan943797c2013-10-21 17:35:55 -070094 int fillColorUsingCopybit(hwc_layer_1_t *layer,
95 private_handle_t *renderBuffer);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080096 bool canUseCopybitForYUV (hwc_context_t *ctx);
97 bool canUseCopybitForRGB (hwc_context_t *ctx,
98 hwc_display_contents_1_t *list, int dpy);
99 bool validateParams (hwc_context_t *ctx,
100 const hwc_display_contents_1_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700101 //Flags if this feature is on.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800102 bool mIsModeOn;
103 // flag that indicates whether CopyBit composition is enabled for this cycle
104 bool mCopyBitDraw;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700105
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530106 unsigned int getRGBRenderingArea (const hwc_context_t *ctx,
107 const hwc_display_contents_1_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700108
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800109 void getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -0700110 unsigned int &width, unsigned int& height);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500111
112 int allocRenderBuffers(int w, int h, int f);
113
114 void freeRenderBuffers();
115
Naseer Ahmed183939d2013-03-14 20:44:17 -0400116 int clear (private_handle_t* hnd, hwc_rect_t& rect);
117
Naseer Ahmed64b81212013-02-14 10:29:47 -0500118 private_handle_t* mRenderBuffer[NUM_RENDER_BUFFERS];
119
120 // Index of the current intermediate render buffer
121 int mCurRenderBufferIndex;
122
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530123 // Release FDs of the intermediate render buffer
124 int mRelFd[NUM_RENDER_BUFFERS];
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530125
126 //Dynamic composition threshold for deciding copybit usage.
127 double mDynThreshold;
Ramakant Singh21cec722014-03-07 19:11:45 +0530128 bool mSwapRectEnable;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700129 int mAlignedWidth;
130 int mAlignedHeight;
Ramakant Singh21cec722014-03-07 19:11:45 +0530131 int mDirtyLayerIndex;
132 LayerCache mLayerCache;
133 FbCache mFbCache;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530134 hwc_rect_t mDirtyRect;
Ramakant Singh21cec722014-03-07 19:11:45 +0530135 int getLayersChanging(hwc_context_t *ctx, hwc_display_contents_1_t *list,
136 int dpy);
137 int checkDirtyRect(hwc_context_t *ctx, hwc_display_contents_1_t *list,
138 int dpy);
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530139 bool isLayerChanging(hwc_context_t *ctx,
140 hwc_display_contents_1_t *list, int k);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700141};
142
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700143}; //namespace qhwc
144
145#endif //HWC_COPYBIT_H