blob: 0bf30c99c8d296cb3e877f6a73200e941cfb6b49 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef HWC_UTILS_H
19#define HWC_UTILS_H
20#include <cutils/log.h>
21#include <gralloc_priv.h>
22#include <hardware/hwcomposer.h>
23#include <hardware/hardware.h>
24#include <hardware/gralloc.h>
25#include <stdlib.h>
26#include <string.h>
27#include <fb_priv.h>
28#include <overlay.h>
Naseer Ahmed31da0b12012-07-31 18:55:33 -070029#include <copybit.h>
30#include <hwc_copybitEngine.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070031#include <genlock.h>
32#include "hwc_qbuf.h"
Naseer Ahmed31da0b12012-07-31 18:55:33 -070033#include <EGL/egl.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070034
Naseer Ahmed31da0b12012-07-31 18:55:33 -070035#define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1))
Naseer Ahmed29a26812012-06-14 00:56:20 -070036#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
37#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
Naseer Ahmed31da0b12012-07-31 18:55:33 -070038#define FINAL_TRANSFORM_MASK 0x000F
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
40struct hwc_context_t;
41namespace qhwc {
42
Naseer Ahmed31da0b12012-07-31 18:55:33 -070043enum external_display_type {
44 EXT_TYPE_NONE,
45 EXT_TYPE_HDMI,
46 EXT_TYPE_WIFI
47};
48enum HWCCompositionType {
49 HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by
50 // Surfaceflinger
51 HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay
52 HWC_USE_COPYBIT // This layer is to be handled by copybit
53};
54
55
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070056class ExtDisplayObserver;
Naseer Ahmed29a26812012-06-14 00:56:20 -070057// -----------------------------------------------------------------------------
58// Utility functions - implemented in hwc_utils.cpp
59void dumpLayer(hwc_layer_t const* l);
60void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070061void initContext(hwc_context_t *ctx);
62void closeContext(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070063//Crops source buffer against destination and FB boundaries
64void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
65 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070066
67// Inline utility functions
68static inline bool isSkipLayer(const hwc_layer_t* l) {
69 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
70}
71
72// Returns true if the buffer is yuv
73static inline bool isYuvBuffer(const private_handle_t* hnd) {
74 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
75}
76
77//Return true if buffer is marked locked
78static inline bool isBufferLocked(const private_handle_t* hnd) {
79 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
80}
Naseer Ahmed31da0b12012-07-31 18:55:33 -070081// -----------------------------------------------------------------------------
82// Copybit specific - inline or implemented in hwc_copybit.cpp
83typedef EGLClientBuffer (*functype_eglGetRenderBufferANDROID) (
84 EGLDisplay dpy,
85 EGLSurface draw);
86typedef EGLSurface (*functype_eglGetCurrentSurface)(EGLint readdraw);
87
88// -----------------------------------------------------------------------------
89// Singleton for Framebuffer device
90class FbDevice{
91public:
92 ~FbDevice();
93 // API to get Fb device(non static)
94 struct framebuffer_device_t *getFb();
95 // API to get singleton
96 static FbDevice* getInstance();
97
98private:
99 FbDevice();
100 struct framebuffer_device_t *sFb;
101 static FbDevice* sInstance; // singleton
102};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700104}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105
106
107// -----------------------------------------------------------------------------
108// HWC context
109// This structure contains overall state
110struct hwc_context_t {
111 hwc_composer_device_t device;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700112 int numHwLayers;
Naseer Ahmeda87da602012-07-01 23:54:19 -0700113 int mdpVersion;
114 bool hasOverlay;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700115 int overlayInUse;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700116
117 //Framebuffer device
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700118 qhwc::FbDevice* mFbDevice;
119
120 //Copybit Engine
121 qhwc::CopybitEngine* mCopybitEngine;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700122
123 //Overlay object - NULL for non overlay devices
124 overlay::Overlay *mOverlay;
125
126 //QueuedBufferStore to hold buffers for overlay
127 qhwc::QueuedBufferStore *qbuf;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700128
129 // External display related information
130 qhwc::ExtDisplayObserver*mExtDisplayObserver;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131};
132
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133#endif //HWC_UTILS_H