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. |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame^] | 34 | typedef EGLClientBuffer (*functype_eglGetRenderBufferANDROID) ( |
| 35 | EGLDisplay dpy, |
| 36 | EGLSurface draw); |
| 37 | typedef EGLSurface (*functype_eglGetCurrentSurface)(EGLint readdraw); |
| 38 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 39 | class CopyBit { |
| 40 | public: |
| 41 | //Sets up members and prepares copybit if conditions are met |
| 42 | static bool prepare(hwc_context_t *ctx, hwc_layer_list_t *list); |
| 43 | //Draws layer if the layer is set for copybit in prepare |
| 44 | static bool draw(hwc_context_t *ctx, hwc_layer_list_t *list, EGLDisplay dpy, |
| 45 | EGLSurface sur); |
| 46 | //Receives data from hwc |
| 47 | static void setStats(int yuvCount, int yuvLayerIndex, bool isYuvLayerSkip); |
| 48 | |
| 49 | static void updateEglHandles(void*); |
| 50 | static int drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_t *layer, |
| 51 | EGLDisplay dpy, EGLSurface surface, |
| 52 | functype_eglGetRenderBufferANDROID& LINK_eglGetRenderBufferANDROID, |
| 53 | functype_eglGetCurrentSurface LINK_eglGetCurrentSurface); |
| 54 | static bool canUseCopybit(hwc_context_t* ctx, const hwc_layer_list_t* list, |
| 55 | const int numYUVBuffers); |
| 56 | static void closeEglLib(); |
| 57 | static void openEglLibAndGethandle(); |
| 58 | private: |
| 59 | //Marks layer flags if this feature is used |
| 60 | static void markFlags(hwc_layer_t *layer); |
| 61 | //returns yuv count |
| 62 | static int getYuvCount(); |
| 63 | |
| 64 | //Number of yuv layers in this drawing round |
| 65 | static int sYuvCount; |
| 66 | //Index of YUV layer, relevant only if count is 1 |
| 67 | static int sYuvLayerIndex; |
| 68 | //Flags if a yuv layer is animating or below something that is animating |
| 69 | static bool sIsLayerSkip; |
| 70 | //Flags if this feature is on. |
| 71 | static bool sIsModeOn; |
| 72 | //handle for adreno lib |
| 73 | static void* egl_lib; |
| 74 | |
| 75 | static functype_eglGetRenderBufferANDROID LINK_eglGetRenderBufferANDROID; |
| 76 | static functype_eglGetCurrentSurface LINK_eglGetCurrentSurface; |
| 77 | |
| 78 | static void getLayerResolution(const hwc_layer_t* layer, int& width, |
| 79 | int& height); |
| 80 | |
| 81 | }; |
| 82 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame^] | 83 | class CopybitEngine { |
| 84 | public: |
| 85 | ~CopybitEngine(); |
| 86 | // API to get copybit engine(non static) |
| 87 | struct copybit_device_t *getEngine(); |
| 88 | // API to get singleton |
| 89 | static CopybitEngine* getInstance(); |
| 90 | private: |
| 91 | CopybitEngine(); |
| 92 | struct copybit_device_t *sEngine; |
| 93 | static CopybitEngine* sInstance; // singleton |
| 94 | }; |
| 95 | |
| 96 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 97 | inline void CopyBit::setStats(int yuvCount, int yuvLayerIndex, |
| 98 | bool isYuvLayerSkip) { |
| 99 | sYuvCount = yuvCount; |
| 100 | sYuvLayerIndex = yuvLayerIndex; |
| 101 | sIsLayerSkip = isYuvLayerSkip; |
| 102 | } |
| 103 | |
| 104 | inline int CopyBit::getYuvCount() { return sYuvCount; } |
| 105 | |
| 106 | |
| 107 | }; //namespace qhwc |
| 108 | |
| 109 | #endif //HWC_COPYBIT_H |