You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.3 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2016-2019. All rights reserved.
* Description: The smallest unit of hwc composition mainly realizes the attribute change of some individual layers
* Author: Hisilicon
* Created: 2016.08.12
*/
#ifndef HWC_LAYER_H
#define HWC_LAYER_H
#include <hardware/hwcomposer2.h>
#include <hardware/hwcomposer_defs.h>
#include <hardware/fb.h>
#include <cutils/native_handle.h>
#include <cutils/properties.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/NativeHandle.h>
#include <utils/StopWatch.h>
#include <utils/Trace.h>
#include <atomic>
#include <map>
#include <mutex>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "HWCCommon.h"
#include "gralloc_priv.h"
#ifdef OVERLAY
#include "OverlayAdapter.h"
#endif
namespace android {
using namespace HwcCommon;
class HWCLayer {
public:
explicit HWCLayer(hwc2_display_t displayId);
~HWCLayer();
uint32_t GetLayerZOrder() const
{
return m_zOrder;
}
hwc2_layer_t GetId() const
{
return m_id;
}
uint8_t GetPlaneAlpha() const
{
return m_planeAlpha;
}
HWC2::BlendMode GetBlendMode() const
{
return m_blendMode;
}
HWC2::Composition GetClientRequested() const
{
return m_clientRequested;
}
HWC2::Composition GetDeviceSelected() const
{
return m_deviceSelected;
}
HWC2::Transform GetTransform() const
{
return m_transform;
}
HWC2::Error SetLayerBlendMode(HWC2::BlendMode mode);
HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquireFence);
HWC2::Error SetLayerBufferReleaseFence(int32_t releaseFence);
HWC2::Error SetLayerColor(hwc_color_t color);
HWC2::Error SetLayerCompositionType(HWC2::Composition type);
HWC2::Error SetLayerDataspace(android_dataspace_t dataspace);
HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame);
HWC2::Error SetLayerPlaneAlpha(float alpha);
HWC2::Error SetLayerSourceCrop(hwc_frect_t crop);
HWC2::Error SetLayerSidebandStream(const native_handle_t *stream);
HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
HWC2::Error SetLayerTransform(HWC2::Transform transform);
HWC2::Error SetLayerVisibleRegion(hwc_region_t visibleReg);
void CloseAcquireFence();
void PushReleaseFence();
int32_t PopReleaseFence();
bool IsDimLayer() const;
HWC2::Error SetLayerZOrder(uint32_t z);
void UpdateClientCompositionType(HWC2::Composition type)
{
m_clientRequested = type;
}
void UpdateDeviceCompositionType(HWC2::Composition type)
{
m_deviceSelected = type;
}
const HWCBuffer& GetLayerBuffer() const;
const hwc_rect_t& GetDisplayFrame() const;
const hwc_rect_t& GetLayerSourceCrop() const;
const native_handle_t* GetLayerSidebandStream() const;
const std::vector<hwc_rect_t>& GetLayerVisibleRegion() const;
bool ForceGpuCompose(int &resizeNum, int &videoNum);
#ifdef OVERLAY
void PrepareOverlayIfNecessary();
void PresentOverlayIfNecessary();
void ClearOverlayIfNecessary();
#endif
void Dump();
private:
uint32_t m_zOrder = 0;
const hwc2_layer_t m_id;
HWCBuffer m_layerBuffer;
HWC2::BlendMode m_blendMode;
uint8_t m_planeAlpha;
hwc_rect_t m_displayFrame;
// Composition requested by client(SF)
HWC2::Composition m_clientRequested = HWC2::Composition::Device;
// Composition selected by HWC
HWC2::Composition m_deviceSelected = HWC2::Composition::Device;
hwc_rect_t m_sourceCrop;
const native_handle_t *m_sidebandStream;
std::vector<hwc_rect_t> m_visibleRegion;
bool m_visible;
HWC2::Transform m_transform;
const hwc2_display_t m_displayId;
std::vector<hwc_rect_t> m_surfaceDamage;
// overlay
#ifdef OVERLAY
buffer_handle_t m_lastOverlayBuffer;
std::unique_ptr<OverlayAdapter> m_overlay;
#endif
hwc_color_t m_color;
std::queue<int32_t> m_releaseFences;
bool UnsupportSizeByGfx2d(int &resizeNum, int &videoNum) const;
};
struct SortLayersByZ {
bool operator()(const HWCLayer *lhs, const HWCLayer *rhs) const
{
if (lhs == nullptr || rhs == nullptr) {
return (lhs == nullptr) && (rhs == nullptr);
}
return lhs->GetLayerZOrder() < rhs->GetLayerZOrder();
}
};
} // namespace android
#endif // HWC_LAYER_H