1 /*
2 * Copyright (c) 2021 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 "ui/rs_canvas_node.h"
17
18 #include <algorithm>
19 #include <string>
20
21 #ifdef ROSEN_OHOS
22 #include "common/rs_obj_abs_geometry.h"
23 #endif
24 #include "command/rs_canvas_node_command.h"
25 #include "platform/common/rs_log.h"
26 #include "common/rs_obj_geometry.h"
27 #include "transaction/rs_transaction_proxy.h"
28 #include "pipeline/rs_node_map.h"
29
30 namespace OHOS {
31 namespace Rosen {
Create(bool isRenderServiceNode)32 RSCanvasNode::SharedPtr RSCanvasNode::Create(bool isRenderServiceNode)
33 {
34 SharedPtr node(new RSCanvasNode(isRenderServiceNode));
35 RSNodeMap::MutableInstance().RegisterNode(node);
36
37 std::unique_ptr<RSCommand> command = std::make_unique<RSCanvasNodeCreate>(node->GetId());
38 auto transactionProxy = RSTransactionProxy::GetInstance();
39 if (transactionProxy != nullptr) {
40 transactionProxy->AddCommand(command, isRenderServiceNode);
41 }
42 ROSEN_LOGD("RSCanvasNode::Create, NodeID = %llu", node->GetId());
43 return node;
44 }
45
RSCanvasNode(bool isRenderServiceNode)46 RSCanvasNode::RSCanvasNode(bool isRenderServiceNode) : RSNode(isRenderServiceNode) {}
47
~RSCanvasNode()48 RSCanvasNode::~RSCanvasNode() {}
49
BeginRecording(int width,int height)50 SkCanvas* RSCanvasNode::BeginRecording(int width, int height)
51 {
52 #ifdef ROSEN_OHOS
53 recordingCanvas_ = new RSRecordingCanvas(width, height);
54 #endif
55 return recordingCanvas_;
56 }
57
IsRecording() const58 bool RSCanvasNode::IsRecording() const
59 {
60 return recordingCanvas_ != nullptr;
61 }
62
FinishRecording()63 void RSCanvasNode::FinishRecording()
64 {
65 #ifdef ROSEN_OHOS
66 if (!IsRecording()) {
67 ROSEN_LOGW("RSCanvasNode::FinishRecording, IsRecording = false");
68 return;
69 }
70 auto recording = static_cast<RSRecordingCanvas*>(recordingCanvas_)->GetDrawCmdList();
71 delete recordingCanvas_;
72 recordingCanvas_ = nullptr;
73 std::unique_ptr<RSCommand> command =
74 std::make_unique<RSCanvasNodeUpdateRecording>(GetId(), recording, drawContentLast_);
75 auto transactionProxy = RSTransactionProxy::GetInstance();
76 if (transactionProxy != nullptr) {
77 transactionProxy->AddCommand(command, IsRenderServiceNode());
78 }
79 #endif
80 }
81
82 } // namespace Rosen
83 } // namespace OHOS
84