1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved. 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" 23 24 #define NUM_RENDER_BUFFERS 3 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 30 31 namespace qhwc { 32 33 class CopyBit { 34 public: 35 CopyBit(hwc_context_t *ctx, const int& dpy); 36 ~CopyBit(); 37 // API to get copybit engine(non static) 38 struct copybit_device_t *getCopyBitDevice(); 39 //Sets up members and prepares copybit if conditions are met 40 bool prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, 41 int dpy); 42 //Draws layer if the layer is set for copybit in prepare 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(); 47 48 private_handle_t * getCurrentRenderBuffer(); 49 50 void setReleaseFd(int fd); 51 52 private: 53 // holds the copybit device 54 struct copybit_device_t *mEngine; 55 // Helper functions for copybit composition 56 int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer, 57 private_handle_t *renderBuffer, bool isFG); 58 int fillColorUsingCopybit(hwc_layer_1_t *layer, 59 private_handle_t *renderBuffer); 60 bool canUseCopybitForYUV (hwc_context_t *ctx); 61 bool canUseCopybitForRGB (hwc_context_t *ctx, 62 hwc_display_contents_1_t *list, int dpy); 63 bool validateParams (hwc_context_t *ctx, 64 const hwc_display_contents_1_t *list); 65 //Flags if this feature is on. 66 bool mIsModeOn; 67 // flag that indicates whether CopyBit composition is enabled for this cycle 68 bool mCopyBitDraw; 69 70 unsigned int getRGBRenderingArea 71 (const hwc_display_contents_1_t *list); 72 73 void getLayerResolution(const hwc_layer_1_t* layer, 74 unsigned int &width, unsigned int& height); 75 76 int allocRenderBuffers(int w, int h, int f); 77 78 void freeRenderBuffers(); 79 80 int clear (private_handle_t* hnd, hwc_rect_t& rect); 81 82 private_handle_t* mRenderBuffer[NUM_RENDER_BUFFERS]; 83 84 // Index of the current intermediate render buffer 85 int mCurRenderBufferIndex; 86 87 // Release FDs of the intermediate render buffer 88 int mRelFd[NUM_RENDER_BUFFERS]; 89 90 //Dynamic composition threshold for deciding copybit usage. 91 double mDynThreshold; 92 int mAlignedFBWidth; 93 int mAlignedFBHeight; 94 }; 95 96 }; //namespace qhwc 97 98 #endif //HWC_COPYBIT_H 99