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 #ifndef USE_ROSEN_DRAWING 30 31 class SkCanvas; 32 class SkSurface; 33 struct SkRect; 34 namespace OHOS { 35 namespace Rosen { 36 class OpItem; 37 class RSPaintFilterCanvas; 38 enum RSOpType : uint16_t; 39 40 class RSB_EXPORT DrawCmdList : public Parcelable { 41 public: 42 DrawCmdList(int w, int h); 43 DrawCmdList& operator=(DrawCmdList&& that); 44 virtual ~DrawCmdList(); 45 46 void AddOp(std::unique_ptr<OpItem>&& op); 47 void ClearOp(); 48 49 void UpdateNodeIdToPicture(NodeId nodeId); 50 void FindIndexOfImage() const; 51 52 void Playback(SkCanvas& canvas, const SkRect* rect = nullptr); 53 void Playback(RSPaintFilterCanvas& canvas, const SkRect* rect = nullptr); 54 55 std::string PlayBackForRecord(SkCanvas& canvas, int startOpId, int endOpId, int descStartOpId, 56 const SkRect* rect = nullptr); 57 std::string PlayBackForRecord(RSPaintFilterCanvas& canvas, int startOpId, int endOpId, 58 int descStartOpId, const SkRect* rect = nullptr); 59 60 void SetWidth(int width); 61 void SetHeight(int height); 62 std::string GetOpsWithDesc() const; 63 size_t GetSize() const; 64 int GetWidth() const; 65 int GetHeight() const; 66 67 bool Marshalling(Parcel& parcel) const override; 68 [[nodiscard]] static RSB_EXPORT DrawCmdList* Unmarshalling(Parcel& parcel); 69 70 // cache related, only available on OHOS 71 void GenerateCache(const RSPaintFilterCanvas* canvas = nullptr, const SkRect* rect = nullptr); 72 void ClearCache(); 73 74 #if defined(RS_ENABLE_DRIVEN_RENDER) && defined(RS_ENABLE_GL) 75 // functions that are dedicated to driven render [start] 76 void CheckClipRect(SkRect& rect); 77 void ReplaceDrivenCmds(); 78 void RestoreOriginCmdsForDriven(); 79 // functions that are dedicated to driven render [end] 80 #endif 81 82 private: 83 std::vector<std::unique_ptr<OpItem>> ops_; 84 mutable std::vector<uint32_t> imageIndexs_; 85 mutable std::mutex mutex_; 86 int width_; 87 int height_; 88 89 #if defined(RS_ENABLE_DRIVEN_RENDER) && defined(RS_ENABLE_GL) 90 // variables that are dedicated to driven render [start] 91 std::vector<std::pair<int, std::unique_ptr<OpItem>>> opReplacedByDrivenRender_; 92 // variables that are dedicated to driven render [end] 93 #endif 94 95 #ifdef ROSEN_OHOS 96 // cache related, only available on OHOS 97 std::vector<std::pair<int, std::unique_ptr<OpItem>>> opReplacedByCache_; 98 bool isCached_ = false; 99 bool cachedHighContrast_ = false; 100 friend class RSMarshallingHelper; 101 using OpUnmarshallingFunc = OpItem* (*)(Parcel& parcel); 102 static OpUnmarshallingFunc GetOpUnmarshallingFunc(RSOpType type); 103 #endif 104 }; 105 106 using DrawCmdListPtr = std::shared_ptr<DrawCmdList>; 107 } // namespace Rosen 108 } // namespace OHOS 109 110 #endif // USE_ROSEN_DRAWING 111 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_LIST_H 112