• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef RS_CORE_PIPELINE_HPAE_OFFLINE_PROCESSOR_H
17 #define RS_CORE_PIPELINE_HPAE_OFFLINE_PROCESSOR_H
18 #include "feature/hwc/hpae_offline/rs_hpae_offline_layer.h"
19 #include "feature/hwc/hpae_offline/rs_hpae_offline_thread_manager.h"
20 #include "feature/hwc/hpae_offline/rs_hpae_offline_process_syncer.h"
21 #include "feature/hwc/hpae_offline/rs_hpae_offline_result.h"
22 #include "feature/hwc/rs_uni_hwc_prevalidate_common.h"
23 
24 #include <cstdint>
25 #include <atomic>
26 #include <buffer_handle.h>
27 
28 namespace OHOS {
29 namespace Rosen {
30 struct OfflineProcessInputInfo {
31     uint64_t id;
32     BufferHandle* srcHandle = nullptr;
33     BufferHandle* dstHandle = nullptr;
34     RequestRect srcRect;
35     RequestRect dstRect;
36     uint32_t transform = 0;
37     int32_t acquireFence = 0;
38     bool timeout = false;
39 };
40 
41 struct OfflineBufferConfig {
42     int32_t width = 0;
43     int32_t height = 0;
44     int32_t strideAlignment = 0;
45     int32_t format = 0;
46     uint64_t usage = 0;
47     int32_t timeout = 0;
48     int32_t colorGamut = 0;
49     int32_t transform = 0;
50 };
51 
52 struct OfflineProcessOutputInfo {
53     OfflineBufferConfig bufferConfig;
54     RequestRect outRect;
55 };
56 
57 using ProcessOfflineFunc = int32_t (*)(const OfflineProcessInputInfo &);
58 using GetOfflineConfigFunc = int32_t (*)(OfflineProcessOutputInfo &);
59 
60 class RSHpaeOfflineProcessor : public std::enable_shared_from_this<RSHpaeOfflineProcessor> {
61 public:
62     static RSHpaeOfflineProcessor& GetOfflineProcessor();
63     ~RSHpaeOfflineProcessor();
64 
65     bool PostProcessOfflineTask(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable>& surfaceDrawable,
66         uint64_t taskId);
67     bool PostProcessOfflineTask(std::shared_ptr<RSSurfaceRenderNode>& node, uint64_t taskId);
68     bool IsRSHpaeOfflineProcessorReady();
69     void CheckAndPostClearOfflineResourceTask();
70     bool WaitForProcessOfflineResult(uint64_t taskId, std::chrono::milliseconds timeout,
71         ProcessOfflineResult& processOfflineResult);
72 
73 private:
74     RSHpaeOfflineProcessor();
75     RSHpaeOfflineProcessor(const RSHpaeOfflineProcessor&) = delete;
76     RSHpaeOfflineProcessor(const RSHpaeOfflineProcessor&&) = delete;
77     RSHpaeOfflineProcessor& operator=(const RSHpaeOfflineProcessor&) = delete;
78     RSHpaeOfflineProcessor& operator=(const RSHpaeOfflineProcessor&&) = delete;
79     bool LoadPreProcessHandle();
80     bool InitForOfflineProcess();
81     void CheckAndPostPreAllocBuffersTask();
82     bool GetOfflineProcessInput(RSSurfaceRenderParams& params, OfflineProcessInputInfo& inputInfo,
83         sptr<SurfaceBuffer>& dstSurfaceBuffer, int32_t& releaseFence);
84     void FlushAndReleaseOfflineLayer(sptr<SurfaceBuffer>& dstSurfaceBuffer);
85     void OfflineTaskFunc(RSRenderParams* paramsPtr, std::shared_ptr<ProcessOfflineFuture>& futurePtr);
86     bool DoProcessOffline(RSSurfaceRenderParams& params, ProcessOfflineResult& processOfflineResult);
87     void CheckAndHandleTimeoutEvent(std::shared_ptr<ProcessOfflineFuture>& futurePtr);
88 
89     // so handler
90     bool loadSuccess_ = false;
91     void* preProcessHandle_ = nullptr;
92     ProcessOfflineFunc preProcessFunc_ = nullptr;
93     GetOfflineConfigFunc getConfigFunc_ = nullptr;
94     RSHpaeOfflineProcessSyncer offlineResultSync_;
95     RSHpaeOfflineThreadManager offlineThreadManager_;
96 
97     // surface
98     RSHpaeOfflineLayer offlineLayer_{"DeviceOfflineLayer", INVALID_NODEID};
99     BufferFlushConfig flushConfig_;
100     std::atomic<bool> preAllocBufferSucc_ = false;
101     // offline config
102     std::mutex offlineConfigMutex_;
103     BufferRequestConfig layerConfig_;
104     RequestRect offlineRect_;
105     // status
106     std::atomic<size_t> invalidFrames_ = 0;
107     std::atomic<bool> isBusy_ = false;
108     std::atomic<bool> timeout_ = false;
109 };
110 } // Rosen
111 } // OHOS
112 #endif // RS_CORE_PIPELINE_HPAE_OFFLINE_PROCESSOR_H