blob: 1e405f71f3290b925bf435dec9198e3a04c3e2c9 [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 Ahmed29a26812012-06-14 00:56:20 -070040
Naseer Ahmed31da0b12012-07-31 18:55:33 -070041enum external_display_type {
42 EXT_TYPE_NONE,
43 EXT_TYPE_HDMI,
44 EXT_TYPE_WIFI
45};
46enum HWCCompositionType {
47 HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by
48 // Surfaceflinger
49 HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay
50 HWC_USE_COPYBIT // This layer is to be handled by copybit
51};
52
53
Naseer Ahmed72cf9762012-07-21 12:17:13 -070054class ExternalDisplay;
55class CopybitEngine;
Naseer Ahmed29a26812012-06-14 00:56:20 -070056// -----------------------------------------------------------------------------
57// Utility functions - implemented in hwc_utils.cpp
58void dumpLayer(hwc_layer_t const* l);
59void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
Naseer Ahmed29a26812012-06-14 00:56:20 -070060void initContext(hwc_context_t *ctx);
61void closeContext(hwc_context_t *ctx);
Naseer Ahmedf48aef62012-07-20 09:05:53 -070062//Crops source buffer against destination and FB boundaries
63void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
64 const int fbWidth, const int fbHeight);
Naseer Ahmed29a26812012-06-14 00:56:20 -070065
66// Inline utility functions
67static inline bool isSkipLayer(const hwc_layer_t* l) {
68 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
69}
70
71// Returns true if the buffer is yuv
72static inline bool isYuvBuffer(const private_handle_t* hnd) {
73 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
74}
75
76//Return true if buffer is marked locked
77static inline bool isBufferLocked(const private_handle_t* hnd) {
78 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
79}
Naseer Ahmed31da0b12012-07-31 18:55:33 -070080
Naseer Ahmed72cf9762012-07-21 12:17:13 -070081// Initialize uevent thread
82void init_uevent_thread(hwc_context_t* ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070083
Naseer Ahmedf48aef62012-07-20 09:05:53 -070084}; //qhwc namespace
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
Naseer Ahmed29a26812012-06-14 00:56:20 -070086// -----------------------------------------------------------------------------
87// HWC context
88// This structure contains overall state
89struct hwc_context_t {
90 hwc_composer_device_t device;
Naseer Ahmed29a26812012-06-14 00:56:20 -070091 int numHwLayers;
Naseer Ahmeda87da602012-07-01 23:54:19 -070092 int mdpVersion;
93 bool hasOverlay;
Naseer Ahmedf48aef62012-07-20 09:05:53 -070094 int overlayInUse;
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
96 //Framebuffer device
Naseer Ahmed72cf9762012-07-21 12:17:13 -070097 framebuffer_device_t *mFbDev;
Naseer Ahmed31da0b12012-07-31 18:55:33 -070098
99 //Copybit Engine
100 qhwc::CopybitEngine* mCopybitEngine;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101
102 //Overlay object - NULL for non overlay devices
103 overlay::Overlay *mOverlay;
104
105 //QueuedBufferStore to hold buffers for overlay
106 qhwc::QueuedBufferStore *qbuf;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700107
108 // External display related information
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700109 qhwc::ExternalDisplay *mExtDisplay;
110
Naseer Ahmed29a26812012-06-14 00:56:20 -0700111};
112
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113#endif //HWC_UTILS_H