blob: 9ce0815dfd1fa2f02f64a5348e8152dc35f6ee3d [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
Naseer Ahmed72cf9762012-07-21 12:17:13 -070020
Naseer Ahmed29a26812012-06-14 00:56:20 -070021#include <hardware/hwcomposer.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070022#include <gralloc_priv.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070023
Naseer Ahmed31da0b12012-07-31 18:55:33 -070024#define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1))
Naseer Ahmed29a26812012-06-14 00:56:20 -070025#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
26#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
Naseer Ahmed31da0b12012-07-31 18:55:33 -070027#define FINAL_TRANSFORM_MASK 0x000F
Naseer Ahmed29a26812012-06-14 00:56:20 -070028
Naseer Ahmed72cf9762012-07-21 12:17:13 -070029//Fwrd decls
Naseer Ahmed29a26812012-06-14 00:56:20 -070030struct hwc_context_t;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070031struct framebuffer_device_t;
32
33namespace overlay {
34class Overlay;
35}
36
Naseer Ahmed29a26812012-06-14 00:56:20 -070037namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070038//fwrd decl
39class QueuedBufferStore;
Naseer Ahmed96c4c952012-07-25 18:27:14 -070040class ExternalDisplay;
41class CopybitEngine;
42
43struct MDPInfo {
44 int version;
45 char panel;
46 bool hasOverlay;
47};
Naseer Ahmed29a26812012-06-14 00:56:20 -070048
Naseer Ahmed31da0b12012-07-31 18:55:33 -070049enum external_display_type {
50 EXT_TYPE_NONE,
51 EXT_TYPE_HDMI,
52 EXT_TYPE_WIFI
53};
54enum HWCCompositionType {
55 HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by
56 // Surfaceflinger
57 HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay
58 HWC_USE_COPYBIT // This layer is to be handled by copybit
59};
60
Naseer Ahmed7c958d42012-07-31 18:57:03 -070061enum {
62 HWC_MDPCOMP = 0x00000002,
63 HWC_LAYER_RESERVED_0 = 0x00000004,
64 HWC_LAYER_RESERVED_1 = 0x00000008
65};
66
Naseer Ahmed31da0b12012-07-31 18:55:33 -070067
Naseer Ahmed29a26812012-06-14 00:56:20 -070068// -----------------------------------------------------------------------------
69// Utility functions - implemented in hwc_utils.cpp
70void dumpLayer(hwc_layer_t const* l);
71void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070072void initContext(hwc_context_t *ctx);
73void closeContext(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074//Crops source buffer against destination and FB boundaries
75void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
76 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070077
78// Inline utility functions
79static inline bool isSkipLayer(const hwc_layer_t* l) {
80 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
81}
82
83// Returns true if the buffer is yuv
84static inline bool isYuvBuffer(const private_handle_t* hnd) {
85 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
86}
87
88//Return true if buffer is marked locked
89static inline bool isBufferLocked(const private_handle_t* hnd) {
90 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
91}
Naseer Ahmed31da0b12012-07-31 18:55:33 -070092
Naseer Ahmed72cf9762012-07-21 12:17:13 -070093// Initialize uevent thread
94void init_uevent_thread(hwc_context_t* ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
Naseer Ahmed7c958d42012-07-31 18:57:03 -070096inline void getLayerResolution(const hwc_layer_t* layer,
97 int& width, int& height)
98{
99 hwc_rect_t displayFrame = layer->displayFrame;
100 width = displayFrame.right - displayFrame.left;
101 height = displayFrame.bottom - displayFrame.top;
102}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104
Naseer Ahmed29a26812012-06-14 00:56:20 -0700105// -----------------------------------------------------------------------------
106// HWC context
107// This structure contains overall state
108struct hwc_context_t {
109 hwc_composer_device_t device;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110 int numHwLayers;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700111 int overlayInUse;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700112
113 //Framebuffer device
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700114 framebuffer_device_t *mFbDev;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700115
116 //Copybit Engine
117 qhwc::CopybitEngine* mCopybitEngine;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700118
119 //Overlay object - NULL for non overlay devices
120 overlay::Overlay *mOverlay;
121
122 //QueuedBufferStore to hold buffers for overlay
123 qhwc::QueuedBufferStore *qbuf;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700124
125 // External display related information
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700126 qhwc::ExternalDisplay *mExtDisplay;
127
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700128 qhwc::MDPInfo mMDP;
129
Naseer Ahmed29a26812012-06-14 00:56:20 -0700130};
131
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132#endif //HWC_UTILS_H