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
25 namespace OHOS {
26 namespace Rosen {
CreateDrawingContext(NodeId nodeId)27 RSDrawingContext RSExtendedModifierHelper::CreateDrawingContext(NodeId nodeId)
28 {
29 auto node = RSNodeMap::Instance().GetNode<RSCanvasNode>(nodeId);
30 if (!node) {
31 return { nullptr };
32 }
33 #ifndef USE_ROSEN_DRAWING
34 auto recordingCanvas = new RSRecordingCanvas(node->GetPaintWidth(), node->GetPaintHeight());
35 recordingCanvas->SetIsCustomTextType(node->GetIsCustomTextType());
36 #else
37 auto recordingCanvas = new Drawing::RecordingCanvas(node->GetPaintWidth(), node->GetPaintHeight());
38 #endif
39 return { recordingCanvas, node->GetPaintWidth(), node->GetPaintHeight() };
40 }
41
CreateRenderModifier(RSDrawingContext & ctx,PropertyId id,RSModifierType type)42 std::shared_ptr<RSRenderModifier> RSExtendedModifierHelper::CreateRenderModifier(
43 RSDrawingContext& ctx, PropertyId id, RSModifierType type)
44 {
45 #ifndef USE_ROSEN_DRAWING
46 auto renderProperty = std::make_shared<RSRenderProperty<DrawCmdListPtr>>(
47 RSExtendedModifierHelper::FinishDrawing(ctx), id);
48 #else
49 auto renderProperty = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>(
50 RSExtendedModifierHelper::FinishDrawing(ctx), id);
51 #endif
52 auto renderModifier = std::make_shared<RSDrawCmdListRenderModifier>(renderProperty);
53 renderModifier->SetType(type);
54 return renderModifier;
55 }
56
57 #ifndef USE_ROSEN_DRAWING
FinishDrawing(RSDrawingContext & ctx)58 std::shared_ptr<DrawCmdList> RSExtendedModifierHelper::FinishDrawing(RSDrawingContext& ctx)
59 #else
60 std::shared_ptr<Drawing::DrawCmdList> RSExtendedModifierHelper::FinishDrawing(RSDrawingContext& ctx)
61 #endif
62 {
63 #ifndef USE_ROSEN_DRAWING
64 auto recording = static_cast<RSRecordingCanvas*>(ctx.canvas)->GetDrawCmdList();
65 #else
66 auto recording = static_cast<Drawing::RecordingCanvas*>(ctx.canvas)->GetDrawCmdList();
67 #endif
68 if (RSSystemProperties::GetDrawTextAsBitmap()) {
69 // replace drawOpItem with cached one (generated by CPU)
70 #ifndef USE_ROSEN_DRAWING
71 recording->GenerateCache();
72 #endif
73 }
74 delete ctx.canvas;
75 ctx.canvas = nullptr;
76 return recording;
77 }
78 } // namespace Rosen
79 } // namespace OHOS
80