/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HDI_BACKEND_HDI_OUTPUT_H #define HDI_BACKEND_HDI_OUTPUT_H #include #include #include #include #include "graphic_error.h" #include "surface_type.h" #include "hdi_layer.h" #include "hdi_framebuffer_surface.h" #include "hdi_screen.h" #include "vsync_sampler.h" namespace OHOS { namespace Rosen { using LayerPtr = std::shared_ptr; static constexpr uint32_t LAYER_COMPOSITION_CAPACITY_INVALID = 0; // dump layer struct LayerDumpInfo { uint64_t nodeId; uint64_t surfaceId; LayerPtr layer; }; class HdiOutput { public: HdiOutput(uint32_t screenId); virtual ~HdiOutput(); static constexpr uint32_t COMPOSITION_RECORDS_NUM = HdiLayer::FRAME_RECORDS_NUM; /* for RS begin */ void SetLayerInfo(const std::vector &layerInfos); void SetOutputDamages(const std::vector &outputDamages); uint32_t GetScreenId() const; void SetLayerCompCapacity(uint32_t layerCompositionCapacity); uint32_t GetLayerCompCapacity() const; // only used when composer_host dead void ResetDevice() { device_ = nullptr; } bool IsDeviceValid() const { return device_ != nullptr; } /* for RS end */ static std::shared_ptr CreateHdiOutput(uint32_t screenId); RosenError Init(); void GetLayerInfos(std::vector& layerInfos); void GetComposeClientLayers(std::vector& clientLayers); const std::vector& GetOutputDamages(); sptr GetFrameBufferSurface(); std::unique_ptr GetFramebuffer(); void Dump(std::string &result) const; void DumpFps(std::string &result, const std::string &arg) const; void DumpHitchs(std::string &result, const std::string &arg) const; void ClearFpsDump(std::string &result, const std::string &arg); void SetDirectClientCompEnableStatus(bool enableStatus); bool GetDirectClientCompEnableStatus() const; GSError ClearFrameBuffer(); RosenError InitDevice(); /* only used for mock tests */ RosenError SetHdiOutputDevice(HdiDevice* device); int32_t PreProcessLayersComp(); int32_t UpdateLayerCompType(); int32_t FlushScreen(std::vector &compClientLayers); int32_t SetScreenClientInfo(const FrameBufferEntry &fbEntry); int32_t Commit(sptr &fbFence); int32_t CommitAndGetReleaseFence(sptr &fbFence, int32_t &skipState, bool &needFlush, bool isValidated); int32_t UpdateInfosAfterCommit(sptr fbFence); int32_t ReleaseFramebuffer(const sptr& releaseFence); std::map> GetLayersReleaseFence(); int32_t StartVSyncSampler(bool forceReSample = false); void SetPendingMode(int64_t period, int64_t timestamp); void ReleaseLayers(sptr& releaseFence); int32_t GetBufferCacheSize(); void SetVsyncSamplerEnabled(bool enabled); bool GetVsyncSamplerEnabled(); private: HdiDevice *device_ = nullptr; sptr sampler_ = nullptr; std::vector> historicalPresentfences_; sptr thirdFrameAheadPresentFence_ = SyncFence::InvalidFence(); int32_t presentFenceIndex_ = 0; sptr currFrameBuffer_ = nullptr; sptr lastFrameBuffer_ = nullptr; std::array compositionTimeRecords_ = {}; uint32_t compTimeRcdIndex_ = 0; sptr fbSurface_ = nullptr; // layerId -- layer ptr std::unordered_map layerIdMap_; // surface unique id -- layer ptr std::unordered_map surfaceIdMap_; uint32_t screenId_; uint32_t layerCompCapacity_ = LAYER_COMPOSITION_CAPACITY_INVALID; std::vector outputDamages_; bool directClientCompositionEnabled_ = true; std::vector > bufferCache_; uint32_t bufferCacheCountMax_ = 0; mutable std::mutex mutex_; std::vector layersId_; std::vector> fences_; // DISPLAYENGINE bool arsrPreEnabled_ = false; bool arsrPreEnabledForVm_ = false; std::string vmArsrWhiteList_ = ""; int32_t CreateLayerLocked(uint64_t surfaceId, const LayerInfoPtr &layerInfo); void DeletePrevLayersLocked(); void ResetLayerStatusLocked(); void ReorderLayerInfoLocked(std::vector &dumpLayerInfos) const; void UpdatePrevLayerInfoLocked(); void ReleaseSurfaceBuffer(sptr& releaseFence); void RecordCompositionTime(int64_t timeStamp); inline bool CheckFbSurface(); bool CheckAndUpdateClientBufferCahce(sptr buffer, uint32_t& index); // DISPLAY ENGINE bool CheckIfDoArsrPre(const LayerInfoPtr &layerInfo); bool CheckIfDoArsrPreForVm(const LayerInfoPtr &layerInfo); bool CheckSupportArsrPreMetadata(); void ClearBufferCache(); std::map> GetLayersReleaseFenceLocked(); std::atomic enableVsyncSample_ = true; }; } // namespace Rosen } // namespace OHOS #endif // HDI_BACKEND_HDI_OUTPUT_H