blob: 8390968df224320f9db261432d6627300d49824c [file] [log] [blame]
Naseer Ahmed31da0b12012-07-31 18:55:33 -07001/*
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
32namespace qhwc {
33//Feature for using Copybit to display RGB layers.
Naseer Ahmed72cf9762012-07-21 12:17:13 -070034typedef EGLClientBuffer (*functype_eglGetRenderBufferANDROID) (
35 EGLDisplay dpy,
36 EGLSurface draw);
37typedef EGLSurface (*functype_eglGetCurrentSurface)(EGLint readdraw);
38
Naseer Ahmed31da0b12012-07-31 18:55:33 -070039class CopyBit {
40public:
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);
Naseer Ahmed45a99602012-07-31 19:15:24 -070054 static bool canUseCopybitForYUV (hwc_context_t *ctx);
55 static bool canUseCopybitForRGB (hwc_context_t *ctx,
56 hwc_layer_list_t *list);
57 static bool validateParams (hwc_context_t *ctx,
58 const hwc_layer_list_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070059 static void closeEglLib();
60 static void openEglLibAndGethandle();
61private:
62 //Marks layer flags if this feature is used
63 static void markFlags(hwc_layer_t *layer);
64 //returns yuv count
65 static int getYuvCount();
66
67 //Number of yuv layers in this drawing round
68 static int sYuvCount;
69 //Index of YUV layer, relevant only if count is 1
70 static int sYuvLayerIndex;
71 //Flags if a yuv layer is animating or below something that is animating
72 static bool sIsLayerSkip;
73 //Flags if this feature is on.
74 static bool sIsModeOn;
75 //handle for adreno lib
76 static void* egl_lib;
77
78 static functype_eglGetRenderBufferANDROID LINK_eglGetRenderBufferANDROID;
79 static functype_eglGetCurrentSurface LINK_eglGetCurrentSurface;
80
Naseer Ahmed45a99602012-07-31 19:15:24 -070081 static unsigned int getRGBRenderingArea (const hwc_layer_list_t *list);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070082
Naseer Ahmed45a99602012-07-31 19:15:24 -070083 static void getLayerResolution(const hwc_layer_t* layer,
84 unsigned int &width, unsigned int& height);
Naseer Ahmed31da0b12012-07-31 18:55:33 -070085};
86
Naseer Ahmed72cf9762012-07-21 12:17:13 -070087class CopybitEngine {
88public:
89 ~CopybitEngine();
90 // API to get copybit engine(non static)
91 struct copybit_device_t *getEngine();
92 // API to get singleton
93 static CopybitEngine* getInstance();
94private:
95 CopybitEngine();
96 struct copybit_device_t *sEngine;
97 static CopybitEngine* sInstance; // singleton
98};
99
100
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700101inline void CopyBit::setStats(int yuvCount, int yuvLayerIndex,
102 bool isYuvLayerSkip) {
103 sYuvCount = yuvCount;
104 sYuvLayerIndex = yuvLayerIndex;
105 sIsLayerSkip = isYuvLayerSkip;
106}
107
108inline int CopyBit::getYuvCount() { return sYuvCount; }
109
110
111}; //namespace qhwc
112
113#endif //HWC_COPYBIT_H