1 /* 2 * Copyright (c) 2023-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 SKIA_HELPER_H 17 #define SKIA_HELPER_H 18 19 #include "include/core/SkFlattenable.h" 20 #include "src/core/SkReadBuffer.h" 21 #include "src/core/SkWriteBuffer.h" 22 #include "utils/data.h" 23 #include "utils/log.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 namespace Drawing { 28 class SkiaHelper { 29 public: 30 static std::shared_ptr<Data> FlattenableSerialize(const SkFlattenable* flattenable); 31 32 template <typename T> FlattenableDeserialize(std::shared_ptr<Data> data)33 static sk_sp<T> FlattenableDeserialize(std::shared_ptr<Data> data) 34 { 35 if (data == nullptr) { 36 LOGD("SkiaHelper::FlattenableDeserialize, data is nullptr!"); 37 return nullptr; 38 } 39 40 SkReadBuffer reader(data->GetData(), data->GetSize()); 41 return reader.readFlattenable<T>(); 42 } 43 }; 44 } // namespace Drawing 45 } // namespace Rosen 46 } // namespace OHOS 47 #endif 48