blob: 184d96787912d988c6bfb12d8547d32dcd1c6055 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07004 *
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 Ahmed5b6708a2012-08-02 13:46:08 -070021#define HWC_REMOVE_DEPRECATED_VERSIONS 1
Naseer Ahmed29a26812012-06-14 00:56:20 -070022#include <hardware/hwcomposer.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070023#include <gralloc_priv.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070024
Naseer Ahmed31da0b12012-07-31 18:55:33 -070025#define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1))
Naseer Ahmed29a26812012-06-14 00:56:20 -070026#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
27#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
Naseer Ahmed31da0b12012-07-31 18:55:33 -070028#define FINAL_TRANSFORM_MASK 0x000F
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070029#define MAX_NUM_DISPLAYS 4 //Yes, this is ambitious
Naseer Ahmed29a26812012-06-14 00:56:20 -070030
Naseer Ahmed72cf9762012-07-21 12:17:13 -070031//Fwrd decls
Naseer Ahmed29a26812012-06-14 00:56:20 -070032struct hwc_context_t;
Naseer Ahmed72cf9762012-07-21 12:17:13 -070033struct framebuffer_device_t;
34
Saurabh Shah56f610d2012-08-07 15:27:06 -070035namespace qService {
36class QService;
37}
38
Naseer Ahmed72cf9762012-07-21 12:17:13 -070039namespace overlay {
40class Overlay;
41}
42
Naseer Ahmed29a26812012-06-14 00:56:20 -070043namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070044//fwrd decl
45class QueuedBufferStore;
Naseer Ahmed96c4c952012-07-25 18:27:14 -070046class ExternalDisplay;
47class CopybitEngine;
48
49struct MDPInfo {
50 int version;
51 char panel;
52 bool hasOverlay;
53};
Naseer Ahmed29a26812012-06-14 00:56:20 -070054
Naseer Ahmed31da0b12012-07-31 18:55:33 -070055enum external_display_type {
56 EXT_TYPE_NONE,
57 EXT_TYPE_HDMI,
58 EXT_TYPE_WIFI
59};
60enum HWCCompositionType {
61 HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by
62 // Surfaceflinger
63 HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay
64 HWC_USE_COPYBIT // This layer is to be handled by copybit
65};
66
Naseer Ahmed7c958d42012-07-31 18:57:03 -070067enum {
68 HWC_MDPCOMP = 0x00000002,
69 HWC_LAYER_RESERVED_0 = 0x00000004,
70 HWC_LAYER_RESERVED_1 = 0x00000008
71};
72
Naseer Ahmed31da0b12012-07-31 18:55:33 -070073
Naseer Ahmed29a26812012-06-14 00:56:20 -070074// -----------------------------------------------------------------------------
75// Utility functions - implemented in hwc_utils.cpp
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070076void dumpLayer(hwc_layer_1_t const* l);
77void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070078void initContext(hwc_context_t *ctx);
79void closeContext(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070080//Crops source buffer against destination and FB boundaries
81void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
82 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070083
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070084// Waits for the fb_post to be called
85void wait4fbPost(hwc_context_t* ctx);
86
87// Waits for the fb_post to finish PAN (primary commit)
88void wait4Pan(hwc_context_t* ctx);
89
Naseer Ahmed29a26812012-06-14 00:56:20 -070090// Inline utility functions
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070091static inline bool isSkipLayer(const hwc_layer_1_t* l) {
Naseer Ahmed29a26812012-06-14 00:56:20 -070092 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
93}
94
95// Returns true if the buffer is yuv
96static inline bool isYuvBuffer(const private_handle_t* hnd) {
97 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
98}
99
Saurabh Shahf395d092012-08-27 12:33:42 -0700100// Returns true if the buffer is secure
101static inline bool isSecureBuffer(const private_handle_t* hnd) {
102 return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags));
103}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700104//Return true if buffer is marked locked
105static inline bool isBufferLocked(const private_handle_t* hnd) {
106 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
107}
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700108
Naseer Ahmed4c588a22012-07-31 19:12:17 -0700109//Return true if buffer is for external display only
110static inline bool isExtOnly(const private_handle_t* hnd) {
111 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY));
112}
113
114//Return true if buffer is for external display only with a BLOCK flag.
115static inline bool isExtBlock(const private_handle_t* hnd) {
116 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_BLOCK));
117}
118
119//Return true if buffer is for external display only with a Close Caption flag.
120static inline bool isExtCC(const private_handle_t* hnd) {
121 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_CC));
122}
123
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700124// Initialize uevent thread
125void init_uevent_thread(hwc_context_t* ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700127inline void getLayerResolution(const hwc_layer_1_t* layer,
Naseer Ahmed7c958d42012-07-31 18:57:03 -0700128 int& width, int& height)
129{
130 hwc_rect_t displayFrame = layer->displayFrame;
131 width = displayFrame.right - displayFrame.left;
132 height = displayFrame.bottom - displayFrame.top;
133}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700134}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136// -----------------------------------------------------------------------------
137// HWC context
138// This structure contains overall state
139struct hwc_context_t {
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700140 hwc_composer_device_1_t device;
Jesse Hall3be78d92012-08-21 15:12:23 -0700141 const hwc_procs_t* proc;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700142 int numHwLayers;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700143 int overlayInUse;
Naseer Ahmed5b6708a2012-08-02 13:46:08 -0700144 hwc_display_t dpys[MAX_NUM_DISPLAYS];
Naseer Ahmed29a26812012-06-14 00:56:20 -0700145
146 //Framebuffer device
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700147 framebuffer_device_t *mFbDev;
Naseer Ahmed31da0b12012-07-31 18:55:33 -0700148
149 //Copybit Engine
150 qhwc::CopybitEngine* mCopybitEngine;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151
152 //Overlay object - NULL for non overlay devices
153 overlay::Overlay *mOverlay;
154
155 //QueuedBufferStore to hold buffers for overlay
156 qhwc::QueuedBufferStore *qbuf;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700157
Saurabh Shah56f610d2012-08-07 15:27:06 -0700158 //QService object
159 qService::QService *mQService;
160
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700161 // External display related information
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700162 qhwc::ExternalDisplay *mExtDisplay;
163
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700164 qhwc::MDPInfo mMDP;
165
Saurabh Shahaa537df2012-09-12 13:21:11 -0700166 bool isPoweredDown;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700167
168 //Securing in progress indicator
169 bool mSecuring;
170
171 //Display in secure mode indicator
172 bool mSecureMode;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173};
174
Naseer Ahmed29a26812012-06-14 00:56:20 -0700175#endif //HWC_UTILS_H