hwc_utils.h revision f48aef64b218d42bd2ede62dcb03a3d7831ebbf9
129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Copyright (C) 2010 The Android Open Source Project
329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Copyright (C) 2012, Code Aurora Forum. All rights reserved.
429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *
529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Licensed under the Apache License, Version 2.0 (the "License");
629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * you may not use this file except in compliance with the License.
729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * You may obtain a copy of the License at
829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *
929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *      http://www.apache.org/licenses/LICENSE-2.0
1029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *
1129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Unless required by applicable law or agreed to in writing, software
1229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * distributed under the License is distributed on an "AS IS" BASIS,
1329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * See the License for the specific language governing permissions and
1529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * limitations under the License.
1629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed */
1729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
1829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#ifndef HWC_UTILS_H
1929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define HWC_UTILS_H
2029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <cutils/log.h>
2129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <gralloc_priv.h>
2229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <hardware/hwcomposer.h>
2329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <hardware/hardware.h>
2429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <hardware/gralloc.h>
2529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <stdlib.h>
2629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <string.h>
2729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <fb_priv.h>
2829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <overlay.h>
2929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <genlock.h>
3029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include "hwc_qbuf.h"
3129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
3229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define ALIGN(x, align)     (((x) + ((align)-1)) & ~((align)-1))
3329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define LIKELY( exp )       (__builtin_expect( (exp) != 0, true  ))
3429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))
3529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
3629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct hwc_context_t;
3729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmednamespace qhwc {
3829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
39a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmedenum external_display_type {
40a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed    EXT_TYPE_NONE,
41a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed    EXT_TYPE_HDMI,
42a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed    EXT_TYPE_WIFI
43a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed};
44a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed
45a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed
4629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// -----------------------------------------------------------------------------
4729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Utility functions - implemented in hwc_utils.cpp
4829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid dumpLayer(hwc_layer_t const* l);
4929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list);
5029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid initContext(hwc_context_t *ctx);
5129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid closeContext(hwc_context_t *ctx);
5229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedvoid openFramebufferDevice(hwc_context_t *ctx);
53f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed//Crops source buffer against destination and FB boundaries
54f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmedvoid calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
55f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed        const int fbWidth, const int fbHeight);
5629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
5729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Inline utility functions
5829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic inline bool isSkipLayer(const hwc_layer_t* l) {
5929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
6029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
6129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// Returns true if the buffer is yuv
6329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic inline bool isYuvBuffer(const private_handle_t* hnd) {
6429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO));
6529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
6629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
6729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed//Return true if buffer is marked locked
6829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstatic inline bool isBufferLocked(const private_handle_t* hnd) {
6929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags));
7029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed}
7129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
72f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed}; //qhwc namespace
7329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
7429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
7529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// -----------------------------------------------------------------------------
7629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// HWC context
7729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed// This structure contains overall state
7829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct hwc_context_t {
7929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    hwc_composer_device_t device;
8029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int hdmiEnabled;
8129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int numHwLayers;
82a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed    int mdpVersion;
83a87da60090f55b823ee999930b381daa3dbda67eNaseer Ahmed    bool hasOverlay;
84f48aef64b218d42bd2ede62dcb03a3d7831ebbf9Naseer Ahmed    int overlayInUse;
8529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //Framebuffer device
8729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    framebuffer_device_t *fbDev;
8829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
8929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //Overlay object - NULL for non overlay devices
9029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    overlay::Overlay *mOverlay;
9129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
9229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    //QueuedBufferStore to hold buffers for overlay
9329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    qhwc::QueuedBufferStore *qbuf;
9429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
9529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
9629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#endif //HWC_UTILS_H
97