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_preview.h"
17 
18 #include "draw/core_canvas.h"
19 #include "lattice_napi/js_lattice.h"
20 
21 #include "base/image/drawing_lattice.h"
22 #include "base/utils/utils.h"
23 
24 namespace OHOS::Ace {
CreateDrawingLattice(void * sptrAddr)25 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLattice(void* sptrAddr)
26 {
27 #ifndef USE_ROSEN_DRAWING
28     return nullptr;
29 #else
30     CHECK_NULL_RETURN(sptrAddr, nullptr);
31     auto* jsLattice = reinterpret_cast<OHOS::Rosen::Drawing::JsLattice*>(sptrAddr);
32     return AceType::MakeRefPtr<DrawingLatticePreview>(jsLattice->GetLattice());
33 #endif
34 }
35 
CreateDrawingLatticeFromNative(void * sptrAddr)36 RefPtr<DrawingLattice> DrawingLattice::CreateDrawingLatticeFromNative(void* sptrAddr)
37 {
38 #ifndef USE_ROSEN_DRAWING
39     return nullptr;
40 #else
41     CHECK_NULL_RETURN(sptrAddr, nullptr);
42     auto* lattice = reinterpret_cast<std::shared_ptr<OHOS::Rosen::Drawing::Lattice>*>(sptrAddr);
43     return AceType::MakeRefPtr<DrawingLatticePreview>(*lattice);
44 #endif
45 }
46 
GetDrawingLatticeSptrAddr()47 void* DrawingLatticePreview::GetDrawingLatticeSptrAddr()
48 {
49 #ifndef USE_ROSEN_DRAWING
50     return nullptr;
51 #else
52     return static_cast<void*>(&lattice_);
53 #endif
54 }
55 } // namespace OHOS::Ace
56