blob: ea2fe66e403c94e853599590bb7c94d1233c8b89 [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#include "hwc_utils.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070019#include "mdp_version.h"
Naseer Ahmedf48aef62012-07-20 09:05:53 -070020#include "hwc_video.h"
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070021#include "hwc_ext_observer.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070022namespace qhwc {
23void initContext(hwc_context_t *ctx)
24{
25 //XXX: target specific initializations here
26 openFramebufferDevice(ctx);
27 ctx->mOverlay = overlay::Overlay::getInstance();
28 ctx->qbuf = new QueuedBufferStore();
Naseer Ahmeda87da602012-07-01 23:54:19 -070029 ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
30 ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
31 ALOGI("MDP version: %d",ctx->mdpVersion);
Naseer Ahmed29a26812012-06-14 00:56:20 -070032
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070033 ctx->mExtDisplayObserver = ExtDisplayObserver::getInstance();
34 ctx->mExtDisplayObserver->setHwcContext(ctx);
Naseer Ahmed29a26812012-06-14 00:56:20 -070035}
36
37void closeContext(hwc_context_t *ctx)
38{
39 if(ctx->mOverlay) {
40 delete ctx->mOverlay;
41 ctx->mOverlay = NULL;
42 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -070043
Naseer Ahmed29a26812012-06-14 00:56:20 -070044 if(ctx->fbDev) {
45 framebuffer_close(ctx->fbDev);
46 ctx->fbDev = NULL;
47 }
48
49 if(ctx->qbuf) {
50 delete ctx->qbuf;
51 ctx->qbuf = NULL;
52 }
53}
54
55// Opens Framebuffer device
56void openFramebufferDevice(hwc_context_t *ctx) {
57 hw_module_t const *module;
58 if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
59 framebuffer_open(module, &(ctx->fbDev));
60 }
61}
62
63void dumpLayer(hwc_layer_t const* l)
64{
65 ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
66 ", {%d,%d,%d,%d}",
67 l->compositionType, l->flags, l->handle, l->transform, l->blending,
68 l->sourceCrop.left,
69 l->sourceCrop.top,
70 l->sourceCrop.right,
71 l->sourceCrop.bottom,
72 l->displayFrame.left,
73 l->displayFrame.top,
74 l->displayFrame.right,
75 l->displayFrame.bottom);
76}
77
78void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
79{
Naseer Ahmedf48aef62012-07-20 09:05:53 -070080 //Video specific stats
81 int yuvCount = 0;
82 int yuvLayerIndex = -1;
83 bool isYuvLayerSkip = false;
84
85 for (size_t i = 0; i < list->numHwLayers; i++) {
86 private_handle_t *hnd =
87 (private_handle_t *)list->hwLayers[i].handle;
88
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 if (isYuvBuffer(hnd)) {
Naseer Ahmedf48aef62012-07-20 09:05:53 -070090 yuvCount++;
91 yuvLayerIndex = i;
92 //Animating
93 if (isSkipLayer(&list->hwLayers[i])) {
94 isYuvLayerSkip = true;
95 }
96 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups
97 //If video layer is below a skip layer
98 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) {
99 isYuvLayerSkip = true;
100 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 }
102 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700103
104 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip);
105
Naseer Ahmed29a26812012-06-14 00:56:20 -0700106 ctx->numHwLayers = list->numHwLayers;
107 return;
108}
109
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700110//Crops source buffer against destination and FB boundaries
111void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
112 const int fbWidth, const int fbHeight) {
113
114 int& crop_x = crop.left;
115 int& crop_y = crop.top;
116 int& crop_r = crop.right;
117 int& crop_b = crop.bottom;
118 int crop_w = crop.right - crop.left;
119 int crop_h = crop.bottom - crop.top;
120
121 int& dst_x = dst.left;
122 int& dst_y = dst.top;
123 int& dst_r = dst.right;
124 int& dst_b = dst.bottom;
125 int dst_w = dst.right - dst.left;
126 int dst_h = dst.bottom - dst.top;
127
128 if(dst_x < 0) {
129 float scale_x = crop_w * 1.0f / dst_w;
130 float diff_factor = (scale_x * abs(dst_x));
131 crop_x = crop_x + (int)diff_factor;
132 crop_w = crop_r - crop_x;
133
134 dst_x = 0;
135 dst_w = dst_r - dst_x;;
136 }
137 if(dst_r > fbWidth) {
138 float scale_x = crop_w * 1.0f / dst_w;
139 float diff_factor = scale_x * (dst_r - fbWidth);
140 crop_r = crop_r - diff_factor;
141 crop_w = crop_r - crop_x;
142
143 dst_r = fbWidth;
144 dst_w = dst_r - dst_x;
145 }
146 if(dst_y < 0) {
147 float scale_y = crop_h * 1.0f / dst_h;
148 float diff_factor = scale_y * abs(dst_y);
149 crop_y = crop_y + diff_factor;
150 crop_h = crop_b - crop_y;
151
152 dst_y = 0;
153 dst_h = dst_b - dst_y;
154 }
155 if(dst_b > fbHeight) {
156 float scale_y = crop_h * 1.0f / dst_h;
157 float diff_factor = scale_y * (dst_b - fbHeight);
158 crop_b = crop_b - diff_factor;
159 crop_h = crop_b - crop_y;
160
161 dst_b = fbHeight;
162 dst_h = dst_b - dst_y;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700163 }
164}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700165
Naseer Ahmed29a26812012-06-14 00:56:20 -0700166};//namespace