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 DRAWING_OBJECT_H 17 #define DRAWING_OBJECT_H 18 19 #include <functional> 20 #include <memory> 21 #ifdef ROSEN_OHOS 22 #include <parcel.h> 23 #endif 24 #include "utils/drawing_macros.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 class Data; 30 class DRAWING_API Object { 31 public: 32 enum class ObjectType : int32_t { 33 NO_TYPE, 34 SHADER_EFFECT, 35 IMAGE_FILTER 36 }; Object()37 Object() : type_(static_cast<int32_t>(ObjectType::NO_TYPE)), subType_(0) {} 38 explicit Object(ObjectType type, int32_t subType = 0) type_(static_cast<int32_t> (type))39 : type_(static_cast<int32_t>(type)), subType_(subType) {} 40 virtual ~Object() = default; 41 #ifdef ROSEN_OHOS 42 virtual bool Marshalling(Parcel&) = 0; 43 virtual bool Unmarshalling(Parcel&, bool& isValid, int32_t depth = 0) = 0; 44 #endif 45 virtual std::shared_ptr<void> GenerateBaseObject() = 0; GetType()46 int32_t GetType() const { return type_; } GetSubType()47 int32_t GetSubType() const { return subType_; } 48 protected: 49 int32_t type_ = 0; 50 int32_t subType_ = 0; 51 }; 52 53 /** 54 * @brief InvalidObj class for handling failed deserialization 55 * Used as placeholder when object deserialization fails but data structure integrity needs to be maintained 56 */ 57 class DRAWING_API InvalidObj final : public Object { 58 public: InvalidObj()59 InvalidObj() : Object(ObjectType::NO_TYPE) {} 60 61 #ifdef ROSEN_OHOS Marshalling(Parcel & parcel)62 bool Marshalling(Parcel& parcel) override { 63 // Invalid object should not be marshalled 64 return false; 65 } 66 67 bool Unmarshalling(Parcel& parcel, bool& isValid, int32_t depth = 0) override { 68 // Invalid object should not be unmarshalled 69 return false; 70 } 71 #endif 72 GenerateBaseObject()73 std::shared_ptr<void> GenerateBaseObject() override { 74 // Invalid object generates nullptr to prevent usage of invalid data 75 return nullptr; 76 } 77 }; 78 } // namespace Drawing 79 } // namespace Rosen 80 } // namespace OHOS 81 #endif // DRAWING_OBJECT_H