blob: 2ee71883a9fc12bdf49a942cedf82c303bb69677 [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 Ahmed0c8b7b52012-07-20 09:06:13 -070039class ExtDisplayObserver;
Naseer Ahmed29a26812012-06-14 00:56:20 -070040// -----------------------------------------------------------------------------
41// Utility functions - implemented in hwc_utils.cpp
42void dumpLayer(hwc_layer_t const* l);
43void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070044void initContext(hwc_context_t *ctx);
45void closeContext(hwc_context_t *ctx);
46void openFramebufferDevice(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070047//Crops source buffer against destination and FB boundaries
48void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
49 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070050
51// Inline utility functions
52static inline bool isSkipLayer(const hwc_layer_t* l) {
53 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
54}
55
56// Returns true if the buffer is yuv
57static inline bool isYuvBuffer(const private_handle_t* hnd) {
58 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
59}
60
61//Return true if buffer is marked locked
62static inline bool isBufferLocked(const private_handle_t* hnd) {
63 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
64}
65
Naseer Ahmedf48aef62012-07-20 09:05:53 -070066}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -070067
68
69// -----------------------------------------------------------------------------
70// HWC context
71// This structure contains overall state
72struct hwc_context_t {
73 hwc_composer_device_t device;
Naseer Ahmed29a26812012-06-14 00:56:20 -070074 int numHwLayers;
Naseer Ahmeda87da602012-07-01 23:54:19 -070075 int mdpVersion;
76 bool hasOverlay;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070077 int overlayInUse;
Naseer Ahmed29a26812012-06-14 00:56:20 -070078
79 //Framebuffer device
80 framebuffer_device_t *fbDev;
81
82 //Overlay object - NULL for non overlay devices
83 overlay::Overlay *mOverlay;
84
85 //QueuedBufferStore to hold buffers for overlay
86 qhwc::QueuedBufferStore *qbuf;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070087
88 // External display related information
89 qhwc::ExtDisplayObserver*mExtDisplayObserver;
Naseer Ahmed29a26812012-06-14 00:56:20 -070090};
91
Naseer Ahmed29a26812012-06-14 00:56:20 -070092#endif //HWC_UTILS_H