blob: b664260005761e26d3df669484421eafe46a2815 [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);
Naseer Ahmed29a26812012-06-14 00:56:20 -070050void initContext(hwc_context_t *ctx);
51void closeContext(hwc_context_t *ctx);
52void openFramebufferDevice(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070053//Crops source buffer against destination and FB boundaries
54void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
55 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070056
57// Inline utility functions
58static inline bool isSkipLayer(const hwc_layer_t* l) {
59 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
60}
61
62// Returns true if the buffer is yuv
63static inline bool isYuvBuffer(const private_handle_t* hnd) {
64 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
65}
66
67//Return true if buffer is marked locked
68static inline bool isBufferLocked(const private_handle_t* hnd) {
69 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
70}
71
Naseer Ahmedf48aef62012-07-20 09:05:53 -070072}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -070073
74
75// -----------------------------------------------------------------------------
76// HWC context
77// This structure contains overall state
78struct hwc_context_t {
79 hwc_composer_device_t device;
Naseer Ahmed29a26812012-06-14 00:56:20 -070080 int hdmiEnabled;
81 int numHwLayers;
Naseer Ahmeda87da602012-07-01 23:54:19 -070082 int mdpVersion;
83 bool hasOverlay;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084 int overlayInUse;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
86 //Framebuffer device
87 framebuffer_device_t *fbDev;
88
89 //Overlay object - NULL for non overlay devices
90 overlay::Overlay *mOverlay;
91
92 //QueuedBufferStore to hold buffers for overlay
93 qhwc::QueuedBufferStore *qbuf;
94};
95
Naseer Ahmed29a26812012-06-14 00:56:20 -070096#endif //HWC_UTILS_H