• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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_render_content.h"
17 
18 #include "pipeline/rs_recording_canvas.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 RSRenderContent::RSRenderContent() = default;
23 
GetMutableRenderProperties()24 RSProperties& RSRenderContent::GetMutableRenderProperties()
25 {
26     return renderProperties_;
27 }
28 
GetRenderProperties() const29 const RSProperties& RSRenderContent::GetRenderProperties() const
30 {
31     return renderProperties_;
32 }
33 
DrawPropertyDrawable(RSPropertyDrawableSlot slot,RSPaintFilterCanvas & canvas) const34 void RSRenderContent::DrawPropertyDrawable(RSPropertyDrawableSlot slot, RSPaintFilterCanvas& canvas) const
35 {
36     auto& drawablePtr = propertyDrawablesVec_[static_cast<size_t>(slot)];
37     if (!drawablePtr) {
38         return;
39     }
40 
41     auto recordingCanvas = canvas.GetRecordingCanvas();
42     if (recordingCanvas == nullptr || !canvas.GetRecordDrawable()) {
43         // non-recording canvas, draw directly
44         drawablePtr->Draw(*this, canvas);
45         return;
46     }
47 
48     auto castRecordingCanvas = static_cast<ExtendRecordingCanvas*>(canvas.GetRecordingCanvas());
49     auto drawFunc = [sharedPtr = shared_from_this(), slot](Drawing::Canvas* canvas, const Drawing::Rect* rect) -> void {
50         if (auto canvasPtr = static_cast<RSPaintFilterCanvas*>(canvas)) {
51             sharedPtr->DrawPropertyDrawable(slot, *canvasPtr);
52         }
53     };
54     // recording canvas, record lambda that draws the drawable
55     castRecordingCanvas->DrawDrawFunc(std::move(drawFunc));
56 }
57 
DrawPropertyDrawableRange(RSPropertyDrawableSlot begin,RSPropertyDrawableSlot end,RSPaintFilterCanvas & canvas) const58 void RSRenderContent::DrawPropertyDrawableRange(
59     RSPropertyDrawableSlot begin, RSPropertyDrawableSlot end, RSPaintFilterCanvas& canvas) const
60 {
61     auto recordingCanvas = canvas.GetRecordingCanvas();
62     if (recordingCanvas == nullptr || !canvas.GetRecordDrawable()) {
63         // non-recording canvas, draw directly
64         std::for_each(propertyDrawablesVec_.begin() + static_cast<size_t>(begin),
65             propertyDrawablesVec_.begin() + static_cast<size_t>(end) + 1, // +1 since we need to include end
66             [&](auto& drawablePtr) {
67                 if (drawablePtr) {
68                     drawablePtr->Draw(*this, canvas);
69                 }
70             });
71         return;
72     }
73 
74     auto castRecordingCanvas = static_cast<ExtendRecordingCanvas*>(canvas.GetRecordingCanvas());
75     auto drawFunc =
76         [sharedPtr = shared_from_this(), begin, end](Drawing::Canvas* canvas, const Drawing::Rect* rect) -> void {
77         if (auto canvasPtr = static_cast<RSPaintFilterCanvas*>(canvas)) {
78             sharedPtr->DrawPropertyDrawableRange(begin, end, *canvasPtr);
79         }
80     };
81     // recording canvas, record lambda that draws the drawable
82     castRecordingCanvas->DrawDrawFunc(std::move(drawFunc));
83 }
84 
GetType() const85 RSRenderNodeType RSRenderContent::GetType() const
86 {
87     return type_;
88 }
89 } // namespace Rosen
90 } // namespace OHOS
91