blob: b67e1b89fa75c4a77863591729123be4c08ac030 [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
Dileep Kumar Reddi05e59bc2015-03-18 18:51:11 +053031#define INVALID_DIMENSION -1
32#define NO_UPDATING_LAYER -2
Naseer Ahmed31da0b12012-07-31 18:55:33 -070033namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070034
Naseer Ahmed31da0b12012-07-31 18:55:33 -070035class CopyBit {
36public:
Saurabh Shah220a30c2013-10-29 16:12:12 -070037 CopyBit(hwc_context_t *ctx, const int& dpy);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038 ~CopyBit();
39 // API to get copybit engine(non static)
40 struct copybit_device_t *getCopyBitDevice();
Naseer Ahmed31da0b12012-07-31 18:55:33 -070041 //Sets up members and prepares copybit if conditions are met
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080042 bool prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list,
43 int dpy);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070044 //Draws layer if the layer is set for copybit in prepare
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080045 bool draw(hwc_context_t *ctx, hwc_display_contents_1_t *list,
46 int dpy, int* fd);
47 // resets the values
48 void reset();
Naseer Ahmed64b81212013-02-14 10:29:47 -050049
50 private_handle_t * getCurrentRenderBuffer();
51
52 void setReleaseFd(int fd);
53
Sushil Chauhandefd3522014-05-13 18:17:12 -070054 void setReleaseFdSync(int fd);
55
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070056 bool prepareOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Sushil Chauhandefd3522014-05-13 18:17:12 -070057
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070058 int drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list);
Sushil Chauhandefd3522014-05-13 18:17:12 -070059
Naseer Ahmed31da0b12012-07-31 18:55:33 -070060private:
Ramakant Singh21cec722014-03-07 19:11:45 +053061 /* cached data */
62 struct LayerCache {
63 int layerCount;
64 buffer_handle_t hnd[MAX_NUM_APP_LAYERS];
Dileep Kumar Reddiaa488882014-12-16 11:19:45 +053065 hwc_rect_t displayFrame[MAX_NUM_APP_LAYERS];
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +053066 bool drop[MAX_NUM_APP_LAYERS];
Ramakant Singh21cec722014-03-07 19:11:45 +053067 /* c'tor */
68 LayerCache();
69 /* clear caching info*/
70 void reset();
71 void updateCounts(hwc_context_t *ctx, hwc_display_contents_1_t *list,
72 int dpy);
73 };
74 /* framebuffer cache*/
75 struct FbCache {
76 hwc_rect_t FbdirtyRect[NUM_RENDER_BUFFERS];
Ramakant Singh19ead272015-03-18 14:11:31 +053077 hwc_rect_t FbdisplayRect[NUM_RENDER_BUFFERS];
Ramakant Singh21cec722014-03-07 19:11:45 +053078 int FbIndex;
79 FbCache();
80 void reset();
Ramakant Singh19ead272015-03-18 14:11:31 +053081 void insertAndUpdateFbCache(hwc_rect_t dirtyRect,
82 hwc_rect_t displayRect);
83 int getUnchangedFbDRCount(hwc_rect_t dirtyRect,
84 hwc_rect_t displayRect);
Ramakant Singh21cec722014-03-07 19:11:45 +053085 };
86
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080087 // holds the copybit device
88 struct copybit_device_t *mEngine;
Ramakant Singh0def28c2014-03-28 20:43:13 +053089 bool drawUsingAppBufferComposition(hwc_context_t *ctx,
90 hwc_display_contents_1_t *list,
Ramakant Singh467759f2014-04-16 11:09:40 +053091 int dpy, int *fd);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080092 // Helper functions for copybit composition
93 int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -080094 private_handle_t *renderBuffer, bool isFG);
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070095 // Helper function to draw copybit layer for PTOR comp
Sushil Chauhandefd3522014-05-13 18:17:12 -070096 int drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -070097 private_handle_t *renderBuffer, hwc_rect_t overlap,
98 hwc_rect_t destRect);
Sushil Chauhan943797c2013-10-21 17:35:55 -070099 int fillColorUsingCopybit(hwc_layer_1_t *layer,
100 private_handle_t *renderBuffer);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800101 bool canUseCopybitForYUV (hwc_context_t *ctx);
102 bool canUseCopybitForRGB (hwc_context_t *ctx,
103 hwc_display_contents_1_t *list, int dpy);
104 bool validateParams (hwc_context_t *ctx,
105 const hwc_display_contents_1_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700106 //Flags if this feature is on.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800107 bool mIsModeOn;
108 // flag that indicates whether CopyBit composition is enabled for this cycle
109 bool mCopyBitDraw;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700110
Dileep Kumar Reddi4070e932014-09-30 09:00:57 +0530111 unsigned int getRGBRenderingArea (const hwc_context_t *ctx,
112 const hwc_display_contents_1_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700113
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800114 void getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed45a99602012-07-31 19:15:24 -0700115 unsigned int &width, unsigned int& height);
Naseer Ahmed64b81212013-02-14 10:29:47 -0500116
117 int allocRenderBuffers(int w, int h, int f);
118
119 void freeRenderBuffers();
120
Naseer Ahmed183939d2013-03-14 20:44:17 -0400121 int clear (private_handle_t* hnd, hwc_rect_t& rect);
122
Naseer Ahmed64b81212013-02-14 10:29:47 -0500123 private_handle_t* mRenderBuffer[NUM_RENDER_BUFFERS];
124
125 // Index of the current intermediate render buffer
126 int mCurRenderBufferIndex;
127
Prabhanjan Kandula5719da42013-11-01 00:14:04 +0530128 // Release FDs of the intermediate render buffer
129 int mRelFd[NUM_RENDER_BUFFERS];
Prabhanjan Kandula73030ba2013-03-15 22:33:39 +0530130
131 //Dynamic composition threshold for deciding copybit usage.
132 double mDynThreshold;
Ramakant Singh21cec722014-03-07 19:11:45 +0530133 bool mSwapRectEnable;
Sushil Chauhandefd3522014-05-13 18:17:12 -0700134 int mAlignedWidth;
135 int mAlignedHeight;
Ramakant Singh21cec722014-03-07 19:11:45 +0530136 int mDirtyLayerIndex;
137 LayerCache mLayerCache;
138 FbCache mFbCache;
Dileep Kumar Reddif7b72052014-12-16 11:25:11 +0530139 hwc_rect_t mDirtyRect;
Ramakant Singh21cec722014-03-07 19:11:45 +0530140 int getLayersChanging(hwc_context_t *ctx, hwc_display_contents_1_t *list,
141 int dpy);
142 int checkDirtyRect(hwc_context_t *ctx, hwc_display_contents_1_t *list,
143 int dpy);
Dileep Kumar Reddi9dab73a2015-02-24 16:15:53 +0530144 bool isLayerChanging(hwc_context_t *ctx,
145 hwc_display_contents_1_t *list, int k);
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700146};
147
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700148}; //namespace qhwc
149
150#endif //HWC_COPYBIT_H