Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 4 | * |
| 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 Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 23 | |
Xiaoming Zhou | b49438c | 2013-07-02 19:17:59 -0400 | [diff] [blame] | 24 | #define NUM_RENDER_BUFFERS 3 |
Terence Hampson | 6b0a427 | 2013-11-06 16:04:51 -0500 | [diff] [blame] | 25 | //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 Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 30 | #define MAX_LAYERS_FOR_ABC 2 |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 31 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 32 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 33 | class CopyBit { |
| 34 | public: |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 35 | CopyBit(hwc_context_t *ctx, const int& dpy); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 36 | ~CopyBit(); |
| 37 | // API to get copybit engine(non static) |
| 38 | struct copybit_device_t *getCopyBitDevice(); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 39 | //Sets up members and prepares copybit if conditions are met |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 40 | bool prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 41 | int dpy); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 42 | //Draws layer if the layer is set for copybit in prepare |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 43 | 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 Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 47 | |
| 48 | private_handle_t * getCurrentRenderBuffer(); |
| 49 | |
| 50 | void setReleaseFd(int fd); |
| 51 | |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 52 | void setReleaseFdSync(int fd); |
| 53 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 54 | bool prepareOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 55 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 56 | int drawOverlap(hwc_context_t *ctx, hwc_display_contents_1_t *list); |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 57 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 58 | private: |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 59 | /* cached data */ |
| 60 | struct LayerCache { |
| 61 | int layerCount; |
| 62 | buffer_handle_t hnd[MAX_NUM_APP_LAYERS]; |
| 63 | /* c'tor */ |
| 64 | LayerCache(); |
| 65 | /* clear caching info*/ |
| 66 | void reset(); |
| 67 | void updateCounts(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 68 | int dpy); |
| 69 | }; |
| 70 | /* framebuffer cache*/ |
| 71 | struct FbCache { |
| 72 | hwc_rect_t FbdirtyRect[NUM_RENDER_BUFFERS]; |
| 73 | int FbIndex; |
| 74 | FbCache(); |
| 75 | void reset(); |
| 76 | void insertAndUpdateFbCache(hwc_rect_t dirtyRect); |
| 77 | int getUnchangedFbDRCount(hwc_rect_t dirtyRect); |
| 78 | }; |
| 79 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 80 | // holds the copybit device |
| 81 | struct copybit_device_t *mEngine; |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 82 | bool drawUsingAppBufferComposition(hwc_context_t *ctx, |
| 83 | hwc_display_contents_1_t *list, |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 84 | int dpy, int *fd); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 85 | // Helper functions for copybit composition |
| 86 | int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 87 | private_handle_t *renderBuffer, bool isFG); |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 88 | // Helper function to draw copybit layer for PTOR comp |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 89 | int drawRectUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 90 | private_handle_t *renderBuffer, hwc_rect_t overlap, |
| 91 | hwc_rect_t destRect); |
Sushil Chauhan | 943797c | 2013-10-21 17:35:55 -0700 | [diff] [blame] | 92 | int fillColorUsingCopybit(hwc_layer_1_t *layer, |
| 93 | private_handle_t *renderBuffer); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 94 | bool canUseCopybitForYUV (hwc_context_t *ctx); |
| 95 | bool canUseCopybitForRGB (hwc_context_t *ctx, |
| 96 | hwc_display_contents_1_t *list, int dpy); |
| 97 | bool validateParams (hwc_context_t *ctx, |
| 98 | const hwc_display_contents_1_t *list); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 99 | //Flags if this feature is on. |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 100 | bool mIsModeOn; |
| 101 | // flag that indicates whether CopyBit composition is enabled for this cycle |
| 102 | bool mCopyBitDraw; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 103 | |
Dileep Kumar Reddi | 4070e93 | 2014-09-30 09:00:57 +0530 | [diff] [blame^] | 104 | unsigned int getRGBRenderingArea (const hwc_context_t *ctx, |
| 105 | const hwc_display_contents_1_t *list); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 106 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 107 | void getLayerResolution(const hwc_layer_1_t* layer, |
Naseer Ahmed | 45a9960 | 2012-07-31 19:15:24 -0700 | [diff] [blame] | 108 | unsigned int &width, unsigned int& height); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 109 | |
| 110 | int allocRenderBuffers(int w, int h, int f); |
| 111 | |
| 112 | void freeRenderBuffers(); |
| 113 | |
Naseer Ahmed | 183939d | 2013-03-14 20:44:17 -0400 | [diff] [blame] | 114 | int clear (private_handle_t* hnd, hwc_rect_t& rect); |
| 115 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 116 | private_handle_t* mRenderBuffer[NUM_RENDER_BUFFERS]; |
| 117 | |
| 118 | // Index of the current intermediate render buffer |
| 119 | int mCurRenderBufferIndex; |
| 120 | |
Prabhanjan Kandula | 5719da4 | 2013-11-01 00:14:04 +0530 | [diff] [blame] | 121 | // Release FDs of the intermediate render buffer |
| 122 | int mRelFd[NUM_RENDER_BUFFERS]; |
Prabhanjan Kandula | 73030ba | 2013-03-15 22:33:39 +0530 | [diff] [blame] | 123 | |
| 124 | //Dynamic composition threshold for deciding copybit usage. |
| 125 | double mDynThreshold; |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 126 | bool mSwapRectEnable; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 127 | int mAlignedWidth; |
| 128 | int mAlignedHeight; |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 129 | int mDirtyLayerIndex; |
| 130 | LayerCache mLayerCache; |
| 131 | FbCache mFbCache; |
| 132 | int getLayersChanging(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 133 | int dpy); |
| 134 | int checkDirtyRect(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 135 | int dpy); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 138 | }; //namespace qhwc |
| 139 | |
| 140 | #endif //HWC_COPYBIT_H |