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 cullRect_ = bounds;
37 return extendRecordingCanvas_.get();
38 }
39
FinishRecording()40 std::shared_ptr<Drawing::RecordCmd> RSRecordCmdUtils::FinishRecording()
41 {
42 if (extendRecordingCanvas_ == nullptr) {
43 ROSEN_LOGE("RSRecordCmdUtils::FinishRecording failed, extendRecordingCanvas_ is nullptr.");
44 return nullptr;
45 }
46 auto recordCmd = std::make_shared<Drawing::RecordCmd>(extendRecordingCanvas_->GetDrawCmdList(), cullRect_);
47 extendRecordingCanvas_ = nullptr;
48 cullRect_ = Drawing::Rect();
49 return recordCmd;
50 }
51 } // namespace Rosen
52 } // namespace OHOS
53