1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_SNAPSHOT_PARAM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_SNAPSHOT_PARAM_H 18 19 #include <string> 20 #include <utility> 21 22 namespace OHOS::Ace::NG { 23 24 constexpr float DEFAULT_SNAPSHOT_SCALE = 1.f; 25 constexpr int32_t DEFAULT_DELAY_TIME = 300; 26 using NodeIdentity = std::pair<std::string, int32_t>; 27 28 enum SnapshotRegionMode { 29 COMMON, 30 LOCALIZED, 31 NO_REGION 32 }; 33 struct LocalizedSnapshotRegion { 34 double start = -1.f; 35 double top = -1.f; 36 double end = -1.f; 37 double bottom = -1.f; 38 }; 39 40 struct SnapshotOptions { 41 float scale; 42 bool waitUntilRenderFinished; 43 LocalizedSnapshotRegion snapshotRegion; 44 SnapshotRegionMode regionMode; 45 explicit SnapshotOptions(float scale = DEFAULT_SNAPSHOT_SCALE, bool waitUntilRenderFinished = false, 46 SnapshotRegionMode regionMode = SnapshotRegionMode::NO_REGION) scaleSnapshotOptions47 : scale(scale), waitUntilRenderFinished(waitUntilRenderFinished), regionMode(regionMode) {} ToStringSnapshotOptions48 std::string ToString() const 49 { 50 std::string region = (regionMode == SnapshotRegionMode::COMMON ? "{Common, " : "{Localized, ") + 51 std::to_string(snapshotRegion.start) + ", " + std::to_string(snapshotRegion.top) + ", " + 52 std::to_string(snapshotRegion.end) + ", " + std::to_string(snapshotRegion.bottom) + "}"; 53 return "{" + std::to_string(scale) + ", " + (waitUntilRenderFinished ? "true, " : "false, ") + region + "}"; 54 } 55 }; 56 struct SnapshotParam { 57 int32_t delay; 58 bool checkImageStatus; 59 SnapshotOptions options; 60 explicit SnapshotParam(int32_t delay = DEFAULT_DELAY_TIME, bool checkImageStatus = false, delaySnapshotParam61 SnapshotOptions options = SnapshotOptions()) : delay(delay), checkImageStatus(checkImageStatus), 62 options(options) {} ToStringSnapshotParam63 std::string ToString() const 64 { 65 return "{" + std::to_string(delay) + ", " + (checkImageStatus ? "true" : "false") + ", " + 66 std::to_string(options.scale) + ", " + (options.waitUntilRenderFinished ? "true}" : "false}"); 67 } 68 }; 69 } // namespace OHOS::Ace::NG 70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_LINE_PAINTER_H