Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * Copyright (C) 2012, Code Aurora Forum. 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 | #include <EGL/egl.h> |
| 24 | #include <EGL/eglext.h> |
| 25 | #include <gralloc_priv.h> |
| 26 | #include <gr.h> |
| 27 | #include <dlfcn.h> |
| 28 | |
| 29 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 30 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 31 | |
| 32 | namespace qhwc { |
| 33 | //Feature for using Copybit to display RGB layers. |
| 34 | class CopyBit { |
| 35 | public: |
| 36 | //Sets up members and prepares copybit if conditions are met |
| 37 | static bool prepare(hwc_context_t *ctx, hwc_layer_list_t *list); |
| 38 | //Draws layer if the layer is set for copybit in prepare |
| 39 | static bool draw(hwc_context_t *ctx, hwc_layer_list_t *list, EGLDisplay dpy, |
| 40 | EGLSurface sur); |
| 41 | //Receives data from hwc |
| 42 | static void setStats(int yuvCount, int yuvLayerIndex, bool isYuvLayerSkip); |
| 43 | |
| 44 | static void updateEglHandles(void*); |
| 45 | static int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_t *layer, |
| 46 | EGLDisplay dpy, EGLSurface surface, |
| 47 | functype_eglGetRenderBufferANDROID& LINK_eglGetRenderBufferANDROID, |
| 48 | functype_eglGetCurrentSurface LINK_eglGetCurrentSurface); |
| 49 | static bool canUseCopybit(hwc_context_t* ctx, const hwc_layer_list_t* list, |
| 50 | const int numYUVBuffers); |
| 51 | static void closeEglLib(); |
| 52 | static void openEglLibAndGethandle(); |
| 53 | private: |
| 54 | //Marks layer flags if this feature is used |
| 55 | static void markFlags(hwc_layer_t *layer); |
| 56 | //returns yuv count |
| 57 | static int getYuvCount(); |
| 58 | |
| 59 | //Number of yuv layers in this drawing round |
| 60 | static int sYuvCount; |
| 61 | //Index of YUV layer, relevant only if count is 1 |
| 62 | static int sYuvLayerIndex; |
| 63 | //Flags if a yuv layer is animating or below something that is animating |
| 64 | static bool sIsLayerSkip; |
| 65 | //Flags if this feature is on. |
| 66 | static bool sIsModeOn; |
| 67 | //handle for adreno lib |
| 68 | static void* egl_lib; |
| 69 | |
| 70 | static functype_eglGetRenderBufferANDROID LINK_eglGetRenderBufferANDROID; |
| 71 | static functype_eglGetCurrentSurface LINK_eglGetCurrentSurface; |
| 72 | |
| 73 | static void getLayerResolution(const hwc_layer_t* layer, int& width, |
| 74 | int& height); |
| 75 | |
| 76 | }; |
| 77 | |
| 78 | inline void CopyBit::setStats(int yuvCount, int yuvLayerIndex, |
| 79 | bool isYuvLayerSkip) { |
| 80 | sYuvCount = yuvCount; |
| 81 | sYuvLayerIndex = yuvLayerIndex; |
| 82 | sIsLayerSkip = isYuvLayerSkip; |
| 83 | } |
| 84 | |
| 85 | inline int CopyBit::getYuvCount() { return sYuvCount; } |
| 86 | |
| 87 | |
| 88 | }; //namespace qhwc |
| 89 | |
| 90 | #endif //HWC_COPYBIT_H |