hwc_utils.cpp revision a87da60090f55b823ee999930b381daa3dbda67e
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#include "hwc_utils.h"
19#include "mdp_version.h"
20
21namespace qhwc {
22void initContext(hwc_context_t *ctx)
23{
24    //XXX: target specific initializations here
25    openFramebufferDevice(ctx);
26    ctx->mOverlay = overlay::Overlay::getInstance();
27    ctx->qbuf = new QueuedBufferStore();
28    ctx->mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
29    ctx->hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
30    ALOGI("MDP version: %d",ctx->mdpVersion);
31
32}
33
34void closeContext(hwc_context_t *ctx)
35{
36    if(ctx->mOverlay) {
37        delete ctx->mOverlay;
38        ctx->mOverlay = NULL;
39    }
40    if(ctx->fbDev) {
41        framebuffer_close(ctx->fbDev);
42        ctx->fbDev = NULL;
43    }
44
45    if(ctx->qbuf) {
46        delete ctx->qbuf;
47        ctx->qbuf = NULL;
48    }
49}
50
51// Opens Framebuffer device
52void openFramebufferDevice(hwc_context_t *ctx) {
53    hw_module_t const *module;
54    if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) {
55        framebuffer_open(module, &(ctx->fbDev));
56    }
57}
58
59void dumpLayer(hwc_layer_t const* l)
60{
61    ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}"
62          ", {%d,%d,%d,%d}",
63          l->compositionType, l->flags, l->handle, l->transform, l->blending,
64          l->sourceCrop.left,
65          l->sourceCrop.top,
66          l->sourceCrop.right,
67          l->sourceCrop.bottom,
68          l->displayFrame.left,
69          l->displayFrame.top,
70          l->displayFrame.right,
71          l->displayFrame.bottom);
72}
73
74void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list)
75{
76    int yuvBufCount = 0;
77    int layersNotUpdatingCount = 0;
78    for (size_t i=0 ; i<list->numHwLayers; i++) {
79        private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
80        if (isYuvBuffer(hnd)) {
81            yuvBufCount++;
82        }
83    }
84    // Number of video/camera layers drawable with overlay
85    ctx->yuvBufferCount = yuvBufCount;
86    ctx->numHwLayers = list->numHwLayers;
87    return;
88}
89
90void handleYUV(hwc_context_t *ctx, hwc_layer_t *layer)
91{
92    private_handle_t *hnd =
93                   (private_handle_t *)layer->handle;
94    //XXX: Handle targets not using overlay
95    if(prepareOverlay(ctx, layer)) {
96        layer->compositionType = HWC_OVERLAY;
97        layer->hints |= HWC_HINT_CLEAR_FB;
98    }
99}
100};//namespace
101