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 "pipeline/rs_record_cmd_utils.h"
17 #include "pipeline/rs_recording_canvas.h"
18 #include "platform/common/rs_log.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 
RSRecordCmdUtils()23 RSRecordCmdUtils::RSRecordCmdUtils()
24     : extendRecordingCanvas_(nullptr), cullRect_(Drawing::Rect()) {}
25 
BeginRecording(Drawing::Rect & bounds)26 Drawing::Canvas* RSRecordCmdUtils::BeginRecording(Drawing::Rect& bounds)
27 {
28     Drawing::RectI rect = bounds.RoundOut();
29     int32_t width = rect.GetWidth();
30     int32_t height = rect.GetHeight();
31     if (width <= 0 || height <= 0) {
32         ROSEN_LOGE("RSRecordCmdUtils::BeginRecording failed, rect is valid.");
33         return nullptr;
34     }
35     extendRecordingCanvas_ = std::make_shared<ExtendRecordingCanvas>(width, height);
36     extendRecordingCanvas_->SetIsRecordCmd(true);
37     cullRect_ = bounds;
38     return extendRecordingCanvas_.get();
39 }
40 
FinishRecording()41 std::shared_ptr<Drawing::RecordCmd> RSRecordCmdUtils::FinishRecording()
42 {
43     if (extendRecordingCanvas_ == nullptr) {
44         ROSEN_LOGE("RSRecordCmdUtils::FinishRecording failed, extendRecordingCanvas_ is nullptr.");
45         return nullptr;
46     }
47     auto recordCmd = std::make_shared<Drawing::RecordCmd>(extendRecordingCanvas_->GetDrawCmdList(), cullRect_);
48     extendRecordingCanvas_ = nullptr;
49     cullRect_ = Drawing::Rect();
50     return recordCmd;
51 }
52 } // namespace Rosen
53 } // namespace OHOS
54