blob: 94a4edba4101d91a4f13de4e570c5db456f6ff9b [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 Ahmed29a26812012-06-14 00:56:20 -070029#include <genlock.h>
30#include "hwc_qbuf.h"
31
32#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
33#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
34#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
35
36struct hwc_context_t;
37namespace qhwc {
38
Naseer Ahmeda87da602012-07-01 23:54:19 -070039enum external_display_type {
40 EXT_TYPE_NONE,
41 EXT_TYPE_HDMI,
42 EXT_TYPE_WIFI
43};
44
45
Naseer Ahmed29a26812012-06-14 00:56:20 -070046// -----------------------------------------------------------------------------
47// Utility functions - implemented in hwc_utils.cpp
48void dumpLayer(hwc_layer_t const* l);
49void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
50void handleYUV(hwc_context_t *ctx, hwc_layer_t *layer);
51void initContext(hwc_context_t *ctx);
52void closeContext(hwc_context_t *ctx);
53void openFramebufferDevice(hwc_context_t *ctx);
54
55// Inline utility functions
56static inline bool isSkipLayer(const hwc_layer_t* l) {
57 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
58}
59
60// Returns true if the buffer is yuv
61static inline bool isYuvBuffer(const private_handle_t* hnd) {
62 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
63}
64
65//Return true if buffer is marked locked
66static inline bool isBufferLocked(const private_handle_t* hnd) {
67 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
68}
69
70// -----------------------------------------------------------------------------
71// Overlay specific functions - inline or implemented in hwc_overlay.cpp
72bool prepareOverlay(hwc_context_t *ctx, hwc_layer_t *layer);
73//XXX: Refine draw functions
74bool drawLayerUsingOverlay(hwc_context_t *ctx, hwc_layer_t *layer);
75//XXX: Refine
76void cleanOverlays(hwc_context_t *ctx );
77void setOverlayState(hwc_context_t* ctx, ovutils::eOverlayState state);
78
79// -----------------------------------------------------------------------------
80// Copybit specific functions - inline or implemented in hwc_copybit.cpp
81
82
83
84// -----------------------------------------------------------------------------
85// HDMI specific functions - inline or implemented in hwc_hdmi.cpp
86
87
88
89} //qhwc namespace
90
91
92
93// -----------------------------------------------------------------------------
94// HWC context
95// This structure contains overall state
96struct hwc_context_t {
97 hwc_composer_device_t device;
98 // Layer variables
99 int yuvBufferCount;
100 int hdmiEnabled;
101 int numHwLayers;
Naseer Ahmeda87da602012-07-01 23:54:19 -0700102 int mdpVersion;
103 bool hasOverlay;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104 bool skipComposition;
105
106 //Framebuffer device
107 framebuffer_device_t *fbDev;
108
109 //Overlay object - NULL for non overlay devices
110 overlay::Overlay *mOverlay;
111
112 //QueuedBufferStore to hold buffers for overlay
113 qhwc::QueuedBufferStore *qbuf;
114};
115
116
117
118
119#endif //HWC_UTILS_H