• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_LIST_H
17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_LIST_H
18 
19 #include <atomic>
20 #include <memory>
21 #include <mutex>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "common/rs_common_def.h"
26 #include "common/rs_macros.h"
27 #include <parcel.h>
28 
29 class SkCanvas;
30 class SkSurface;
31 struct SkRect;
32 namespace OHOS {
33 namespace Rosen {
34 class OpItem;
35 class RSPaintFilterCanvas;
36 
37 class RSB_EXPORT DrawCmdList : public Parcelable {
38 public:
39     DrawCmdList(int w, int h);
40     DrawCmdList& operator=(DrawCmdList&& that);
41     virtual ~DrawCmdList();
42 
43     void AddOp(std::unique_ptr<OpItem>&& op);
44     void ClearOp();
45 
46     void Playback(SkCanvas& canvas, const SkRect* rect = nullptr) const;
47     void Playback(RSPaintFilterCanvas& canvas, const SkRect* rect = nullptr) const;
48 
49     int GetSize() const;
50     int GetWidth() const;
51     int GetHeight() const;
52 
53     void GenerateCache(SkSurface* surface);
54     void ClearCache();
55 
56     bool Marshalling(Parcel& parcel) const override;
57     static RSB_EXPORT DrawCmdList* Unmarshalling(Parcel& parcel);
58 
59 private:
60     std::vector<std::unique_ptr<OpItem>> ops_;
61     mutable std::mutex mutex_;
62     int width_;
63     int height_;
64 
65     std::unordered_map<int, std::unique_ptr<OpItem>> opReplacedByCache_;
66 #ifdef ROSEN_OHOS
67     bool isCached_ = false;
68 #endif
69 };
70 
71 using DrawCmdListPtr = std::shared_ptr<DrawCmdList>;
72 
73 class RS_EXPORT DrawCmdListManager {
74 public:
75     static DrawCmdListManager& Instance();
76 
77     void RegisterDrawCmdList(NodeId id, std::shared_ptr<DrawCmdList> drawCmdList);
78     void ClearDrawCmdList(NodeId id);
79 
80     void MarkForceClear(bool flag);
81 
82     DrawCmdListManager() = default;
83     ~DrawCmdListManager();
84 
85 private:
86     DrawCmdListManager(const DrawCmdListManager&) = delete;
87     DrawCmdListManager(const DrawCmdListManager&&) = delete;
88     DrawCmdListManager& operator=(const DrawCmdListManager&) = delete;
89     DrawCmdListManager& operator=(const DrawCmdListManager&&) = delete;
90 
91     std::atomic_bool forceClear_ = true;
92 
93     std::mutex listsMutex_;
94     std::unordered_map<NodeId, std::vector<std::weak_ptr<DrawCmdList>>> lists_;
95 };
96 } // namespace Rosen
97 } // namespace OHOS
98 
99 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_LIST_H
100