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 27 enum SnapshotRegionMode { 28 COMMON, 29 LOCALIZED, 30 NO_REGION 31 }; 32 struct LocalizedSnapshotRegion { 33 double start = -1.f; 34 double top = -1.f; 35 double end = -1.f; 36 double bottom = -1.f; 37 }; 38 39 struct SnapshotOptions { 40 float scale; 41 bool waitUntilRenderFinished; 42 LocalizedSnapshotRegion snapshotRegion; 43 SnapshotRegionMode regionMode; 44 explicit SnapshotOptions(float scale = DEFAULT_SNAPSHOT_SCALE, bool waitUntilRenderFinished = false, 45 SnapshotRegionMode regionMode = SnapshotRegionMode::NO_REGION) scaleSnapshotOptions46 : scale(scale), waitUntilRenderFinished(waitUntilRenderFinished), regionMode(regionMode) {} ToStringSnapshotOptions47 std::string ToString() const 48 { 49 std::string region = (regionMode == SnapshotRegionMode::COMMON ? "{Common, " : "{Localized, ") + 50 std::to_string(snapshotRegion.start) + ", " + std::to_string(snapshotRegion.top) + ", " + 51 std::to_string(snapshotRegion.end) + ", " + std::to_string(snapshotRegion.bottom) + "}"; 52 return "{" + std::to_string(scale) + ", " + (waitUntilRenderFinished ? "true, " : "false, ") + region + "}"; 53 } 54 }; 55 struct SnapshotParam { 56 int32_t delay; 57 bool checkImageStatus; 58 SnapshotOptions options; 59 explicit SnapshotParam(int32_t delay = DEFAULT_DELAY_TIME, bool checkImageStatus = false, delaySnapshotParam60 SnapshotOptions options = SnapshotOptions()) : delay(delay), checkImageStatus(checkImageStatus), 61 options(options) {} ToStringSnapshotParam62 std::string ToString() const 63 { 64 return "{" + std::to_string(delay) + ", " + (checkImageStatus ? "true" : "false") + ", " + 65 std::to_string(options.scale) + ", " + (options.waitUntilRenderFinished ? "true}" : "false}"); 66 } 67 }; 68 } // namespace OHOS::Ace::NG 69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_LINE_PAINTER_H