1 /*
2 * Copyright (c) 2022 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 "modifier/rs_extended_modifier.h"
17
18 #include <memory>
19
20 #include "modifier/rs_render_modifier.h"
21 #include "modifier/rs_modifier_type.h"
22 #include "pipeline/rs_node_map.h"
23 #include "pipeline/rs_recording_canvas.h"
24 #include "ui/rs_canvas_node.h"
25
26 namespace OHOS {
27 namespace Rosen {
CreateDrawingContext(NodeId nodeId)28 RSDrawingContext RSExtendedModifierHelper::CreateDrawingContext(NodeId nodeId)
29 {
30 auto node = RSNodeMap::Instance().GetNode<RSCanvasNode>(nodeId);
31 if (!node) {
32 return { nullptr };
33 }
34 auto recordingCanvas = new RSRecordingCanvas(node->GetPaintWidth(), node->GetPaintHeight());
35 return { recordingCanvas, node->GetPaintWidth(), node->GetPaintHeight() };
36 }
37
CreateRenderModifier(RSDrawingContext & ctx,PropertyId id,RSModifierType type)38 std::shared_ptr<RSRenderModifier> RSExtendedModifierHelper::CreateRenderModifier(
39 RSDrawingContext& ctx, PropertyId id, RSModifierType type)
40 {
41 auto renderProperty = std::make_shared<RSRenderProperty<DrawCmdListPtr>>(
42 RSExtendedModifierHelper::FinishDrawing(ctx), id);
43 auto renderModifier = std::make_shared<RSDrawCmdListRenderModifier>(renderProperty);
44 renderModifier->SetType(type);
45 return renderModifier;
46 }
47
FinishDrawing(RSDrawingContext & ctx)48 std::shared_ptr<DrawCmdList> RSExtendedModifierHelper::FinishDrawing(RSDrawingContext& ctx)
49 {
50 auto recording = static_cast<RSRecordingCanvas*>(ctx.canvas)->GetDrawCmdList();
51 delete ctx.canvas;
52 ctx.canvas = nullptr;
53 return recording;
54 }
55 } // namespace Rosen
56 } // namespace OHOS
57