• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "drawing_lattice_ohos.h"
17 
18 #include "base/utils/utils.h"
19 #include "lattice_napi/js_lattice.h"
20 
21 #if defined(ACE_STATIC)
22 #include "lattice_ani/ani_lattice.h"
23 #endif
24 namespace OHOS::Ace {
25 
26 #if defined(ACE_STATIC)
CreateDrawingLatticeFromAni(void * aniAddr)27 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromAni(void* aniAddr)
28 {
29     CHECK_NULL_RETURN(aniAddr, nullptr);
30     auto* aniLattice = reinterpret_cast<OHOS::Rosen::Drawing::AniLattice*>(aniAddr);
31     CHECK_NULL_RETURN(aniLattice, nullptr);
32     auto lattice = aniLattice->GetLattice();
33     return AceType::MakeRefPtr<DrawingLatticeOhos>(lattice);
34 }
35 #endif
36 
CreateDrawingLattice(void * sptrAddr)37 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLattice(void* sptrAddr)
38 {
39     CHECK_NULL_RETURN(sptrAddr, nullptr);
40     auto* jsLattice = reinterpret_cast<OHOS::Rosen::Drawing::JsLattice*>(sptrAddr);
41     return AceType::MakeRefPtr<DrawingLatticeOhos>(jsLattice->GetLattice());
42 }
43 
CreateDrawingLatticeFromNative(void * sptrAddr)44 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromNative(void* sptrAddr)
45 {
46     CHECK_NULL_RETURN(sptrAddr, nullptr);
47     auto* lattice = reinterpret_cast<std::shared_ptr<OHOS::Rosen::Drawing::Lattice>*>(sptrAddr);
48     return AceType::MakeRefPtr<DrawingLatticeOhos>(*lattice);
49 }
50 
GetDrawingLatticeSptrAddr()51 void* DrawingLatticeOhos::GetDrawingLatticeSptrAddr()
52 {
53     return static_cast<void*>(&lattice_);
54 }
55 
DumpToString()56 std::string DrawingLatticeOhos::DumpToString()
57 {
58     if (lattice_) {
59         std::string drawingConfigStr;
60         drawingConfigStr.append("fXCount = " + std::to_string(lattice_->fXCount));
61         drawingConfigStr.append("fXDivs = [");
62         for (int32_t idx = 0; idx < lattice_->fXCount; ++idx) {
63             drawingConfigStr.append(std::to_string(lattice_->fXDivs[idx]) + " ");
64         }
65         drawingConfigStr.append("] ");
66         drawingConfigStr.append("fYCount = " + std::to_string(lattice_->fYCount));
67         drawingConfigStr.append("fYDivs = [");
68         for (int32_t idx = 0; idx < lattice_->fYCount; ++idx) {
69             drawingConfigStr.append(std::to_string(lattice_->fYDivs[idx]) + " ");
70         }
71         drawingConfigStr.append("] ");
72         return drawingConfigStr;
73     }
74     return "Lattice is null";
75 }
76 } // namespace OHOS::Ace
77