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 #include "skia_picture.h" 17 #include "skia_adapter/skia_data.h" 18 #include "utils/data.h" 19 #include "utils/log.h" 20 namespace OHOS { 21 namespace Rosen { 22 namespace Drawing { SkiaPicture()23SkiaPicture::SkiaPicture() noexcept : skiaPicture_(nullptr) {} 24 GetPicture() const25const sk_sp<SkPicture> SkiaPicture::GetPicture() const 26 { 27 return skiaPicture_; 28 } 29 Serialize() const30std::shared_ptr<Data> SkiaPicture::Serialize() const 31 { 32 if (skiaPicture_ == nullptr) { 33 LOGD("SkiaPicture::Serialize, SkPicture is nullptr!"); 34 return nullptr; 35 } 36 37 auto skData = skiaPicture_->serialize(); 38 auto data = std::make_shared<Data>(); 39 data->GetImpl<SkiaData>()->SetSkData(skData); 40 41 return data; 42 } 43 Deserialize(std::shared_ptr<Data> data)44bool SkiaPicture::Deserialize(std::shared_ptr<Data> data) 45 { 46 if (data == nullptr) { 47 return false; 48 } 49 50 skiaPicture_ = SkPicture::MakeFromData(data->GetData(), data->GetSize()); 51 return skiaPicture_ != nullptr; 52 } 53 } // namespace Drawing 54 } // namespace Rosen 55 } // namespace OHOS 56