1 /*
2 * Copyright (c) 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 "frameworks/bridge/declarative_frontend/jsview/models/rendering_context_model_impl.h"
17 #include "core/components/custom_paint/custom_paint_component.h"
18
19 namespace OHOS::Ace::Framework {
GetWidth(RefPtr<AceType> & canvasPattern,double & width)20 void RenderingContextModelImpl::GetWidth(RefPtr<AceType>& canvasPattern, double& width)
21 {
22 CHECK_NULL_VOID(canvasPattern);
23 auto CustomPaintComponent = AceType::DynamicCast<CanvasTaskPool>(canvasPattern);
24 if (CustomPaintComponent) {
25 width = CustomPaintComponent->GetWidth();
26 return;
27 }
28 }
29
GetHeight(RefPtr<AceType> & canvasPattern,double & height)30 void RenderingContextModelImpl::GetHeight(RefPtr<AceType>& canvasPattern, double& height)
31 {
32 CHECK_NULL_VOID(canvasPattern);
33 auto CustomPaintComponent = AceType::DynamicCast<CanvasTaskPool>(canvasPattern);
34 if (CustomPaintComponent) {
35 height = CustomPaintComponent->GetHeight();
36 return;
37 }
38 }
39
SetTransferFromImageBitmap(RefPtr<AceType> & canvasPattern,RefPtr<AceType> offscreenCPattern)40 void RenderingContextModelImpl::SetTransferFromImageBitmap(
41 RefPtr<AceType>& canvasPattern, RefPtr<AceType> offscreenCPattern)
42 {
43 CHECK_NULL_VOID(canvasPattern);
44 auto pool = AceType::DynamicCast<CanvasTaskPool>(canvasPattern);
45 if (pool) {
46 auto offscreenCanvas = AceType::DynamicCast<OffscreenCanvas>(offscreenCPattern);
47 CHECK_NULL_VOID(offscreenCanvas);
48 pool->TransferFromImageBitmap(offscreenCanvas);
49 }
50 }
51 } // namespace OHOS::Ace::Framework
52