/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #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& 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 m_visibleRegion; bool m_visible; HWC2::Transform m_transform; const hwc2_display_t m_displayId; std::vector m_surfaceDamage; // overlay #ifdef OVERLAY buffer_handle_t m_lastOverlayBuffer; std::unique_ptr m_overlay; #endif hwc_color_t m_color; std::queue 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