hwc_utils.h revision 1e396eddac16f39d5bd09dc9f6f8a704b468c2d3
1/*
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
21#define HWC_REMOVE_DEPRECATED_VERSIONS 1
22#include <hardware/hwcomposer.h>
23#include <gralloc_priv.h>
24
25#define ALIGN_TO(x, align)     (((x) + ((align)-1)) & ~((align)-1))
26#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
27#define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
28#define FINAL_TRANSFORM_MASK 0x000F
29#define MAX_NUM_DISPLAYS 4 //Yes, this is ambitious
30
31//Fwrd decls
32struct hwc_context_t;
33struct framebuffer_device_t;
34
35namespace overlay {
36class Overlay;
37}
38
39namespace qhwc {
40//fwrd decl
41class QueuedBufferStore;
42class ExternalDisplay;
43class CopybitEngine;
44
45struct MDPInfo {
46    int version;
47    char panel;
48    bool hasOverlay;
49};
50
51enum external_display_type {
52    EXT_TYPE_NONE,
53    EXT_TYPE_HDMI,
54    EXT_TYPE_WIFI
55};
56enum HWCCompositionType {
57    HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by
58                                   //                 Surfaceflinger
59    HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay
60    HWC_USE_COPYBIT                // This layer is to be handled by copybit
61};
62
63enum {
64    HWC_MDPCOMP = 0x00000002,
65    HWC_LAYER_RESERVED_0 = 0x00000004,
66    HWC_LAYER_RESERVED_1 = 0x00000008
67};
68
69
70// -----------------------------------------------------------------------------
71// Utility functions - implemented in hwc_utils.cpp
72void dumpLayer(hwc_layer_1_t const* l);
73void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list);
74void initContext(hwc_context_t *ctx);
75void closeContext(hwc_context_t *ctx);
76//Crops source buffer against destination and FB boundaries
77void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
78        const int fbWidth, const int fbHeight);
79
80// Waits for the fb_post to be called
81void wait4fbPost(hwc_context_t* ctx);
82
83// Waits for the fb_post to finish PAN (primary commit)
84void wait4Pan(hwc_context_t* ctx);
85
86// Inline utility functions
87static inline bool isSkipLayer(const hwc_layer_1_t* l) {
88    return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
89}
90
91// Returns true if the buffer is yuv
92static inline bool isYuvBuffer(const private_handle_t* hnd) {
93    return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
94}
95
96// Returns true if the buffer is secure
97static inline bool isSecureBuffer(const private_handle_t* hnd) {
98    return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags));
99}
100//Return true if buffer is marked locked
101static inline bool isBufferLocked(const private_handle_t* hnd) {
102    return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
103}
104
105//Return true if buffer is for external display only
106static inline bool isExtOnly(const private_handle_t* hnd) {
107    return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY));
108}
109
110//Return true if buffer is for external display only with a BLOCK flag.
111static inline bool isExtBlock(const private_handle_t* hnd) {
112    return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_BLOCK));
113}
114
115//Return true if buffer is for external display only with a Close Caption flag.
116static inline bool isExtCC(const private_handle_t* hnd) {
117    return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_CC));
118}
119
120// Initialize uevent thread
121void init_uevent_thread(hwc_context_t* ctx);
122
123inline void getLayerResolution(const hwc_layer_1_t* layer,
124                                         int& width, int& height)
125{
126    hwc_rect_t displayFrame  = layer->displayFrame;
127    width = displayFrame.right - displayFrame.left;
128    height = displayFrame.bottom - displayFrame.top;
129}
130}; //qhwc namespace
131
132// -----------------------------------------------------------------------------
133// HWC context
134// This structure contains overall state
135struct hwc_context_t {
136    hwc_composer_device_1_t device;
137    const hwc_procs_t* proc;
138    int numHwLayers;
139    int overlayInUse;
140    hwc_display_t dpys[MAX_NUM_DISPLAYS];
141
142    //Framebuffer device
143    framebuffer_device_t *mFbDev;
144
145    //Copybit Engine
146    qhwc::CopybitEngine* mCopybitEngine;
147
148    //Overlay object - NULL for non overlay devices
149    overlay::Overlay *mOverlay;
150
151    //QueuedBufferStore to hold buffers for overlay
152    qhwc::QueuedBufferStore *qbuf;
153
154    // External display related information
155    qhwc::ExternalDisplay *mExtDisplay;
156
157    qhwc::MDPInfo mMDP;
158
159    bool isPoweredDown;
160};
161
162#endif //HWC_UTILS_H
163