• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "rs_divided_render_util.h"
16 
17 #include <parameters.h>
18 
19 #include "common/rs_obj_abs_geometry.h"
20 #include "parameters.h"
21 #include "platform/common/rs_log.h"
22 #include "property/rs_properties_painter.h"
23 #include "render/rs_skia_filter.h"
24 
25 namespace OHOS {
26 namespace Rosen {
CreateBufferDrawParam(const RSSurfaceRenderNode & node,bool inLocalCoordinate,bool isClipHole,bool forceCPU,bool setColorFilter)27 BufferDrawParam RSDividedRenderUtil::CreateBufferDrawParam(
28     const RSSurfaceRenderNode& node, bool inLocalCoordinate, bool isClipHole, bool forceCPU, bool setColorFilter)
29 {
30     BufferDrawParam params;
31 #ifdef RS_ENABLE_EGLIMAGE
32     params.useCPU = forceCPU;
33 #else // RS_ENABLE_EGLIMAGE
34     (void)(forceCPU); // unused param.
35     params.useCPU = true;
36 #endif // RS_ENABLE_EGLIMAGE
37 #ifndef USE_ROSEN_DRAWING
38     params.paint.setAlphaf(node.GetGlobalAlpha());
39     params.paint.setAntiAlias(true);
40 #ifndef NEW_SKIA
41     params.paint.setFilterQuality(SkFilterQuality::kLow_SkFilterQuality);
42 #endif
43 #else
44     params.paint.SetAlphaF(node.GetGlobalAlpha());
45     params.paint.SetAntiAlias(true);
46     Drawing::Filter filter;
47     filter.SetFilterQuality(Drawing::Filter::FilterQuality::LOW);
48     params.paint.SetFilter(filter);
49 #endif
50     params.setColorFilter = setColorFilter;
51 
52     const RSProperties& property = node.GetRenderProperties();
53     auto backgroundColor = property.GetBackgroundColor();
54     auto backgroundAlpha = backgroundColor.GetAlpha();
55     int16_t finalBackgroundAlpha = static_cast<int16_t>(backgroundAlpha * node.GetGlobalAlpha());
56     backgroundColor.SetAlpha(finalBackgroundAlpha);
57 #ifndef USE_ROSEN_DRAWING
58     params.backgroundColor = static_cast<SkColor>(backgroundColor.AsArgbInt());
59 
60     const RectF absBounds = {
61         node.GetTotalMatrix().getTranslateX(), node.GetTotalMatrix().getTranslateY(),
62         property.GetBoundsWidth(), property.GetBoundsHeight()};
63 #else
64     params.backgroundColor = static_cast<Drawing::ColorQuad>(backgroundColor.AsArgbInt());
65 
66     const RectF absBounds = {
67         node.GetTotalMatrix().Get(Drawing::Matrix::TRANS_X), node.GetTotalMatrix().Get(Drawing::Matrix::TRANS_Y),
68         property.GetBoundsWidth(), property.GetBoundsHeight()};
69 #endif
70     RectF localBounds = {0.0f, 0.0f, absBounds.GetWidth(), absBounds.GetHeight()};
71 
72     // calculate clipRect and clipRRect(if has cornerRadius) for canvas.
73     CalculateSurfaceNodeClipRects(node, absBounds, localBounds, inLocalCoordinate, params);
74 
75     // inLocalCoordinate: reset the translate to (0, 0).
76     // else: use node's total matrix.
77     if (inLocalCoordinate) {
78 #ifndef USE_ROSEN_DRAWING
79         params.matrix = SkMatrix::I();
80 #else
81         params.matrix = Drawing::Matrix();
82 #endif
83     } else {
84         params.matrix = node.GetTotalMatrix();
85     }
86 
87     // we can use only the bound's size (ignore its offset) now,
88     // (the canvas was moved to the node's left-top point correctly).
89 #ifndef USE_ROSEN_DRAWING
90     params.dstRect = SkRect::MakeWH(localBounds.GetWidth(), localBounds.GetHeight());
91 #else
92     params.dstRect = Drawing::Rect(0, 0, localBounds.GetWidth(), localBounds.GetHeight());
93 #endif
94 
95     const sptr<IConsumerSurface>& surface = node.GetConsumer();
96     const sptr<SurfaceBuffer>& buffer = node.GetBuffer();
97     if (isClipHole || surface == nullptr || buffer == nullptr) {
98         return params;
99     }
100 
101     params.buffer = buffer;
102     params.acquireFence = node.GetAcquireFence();
103 #ifndef USE_ROSEN_DRAWING
104     params.srcRect = SkRect::MakeWH(buffer->GetSurfaceBufferWidth(), buffer->GetSurfaceBufferHeight());
105 #else
106     params.srcRect = Drawing::Rect(0, 0, buffer->GetSurfaceBufferWidth(), buffer->GetSurfaceBufferHeight());
107 #endif
108     RSBaseRenderUtil::DealWithSurfaceRotationAndGravity(surface->GetTransform(), property.GetFrameGravity(),
109         localBounds, params);
110     RSBaseRenderUtil::FlipMatrix(surface->GetTransform(), params);
111     return params;
112 }
113 
CalculateSurfaceNodeClipRects(const RSSurfaceRenderNode & node,const RectF & absBounds,const RectF & localBounds,bool inLocalCoordinate,BufferDrawParam & params)114 void RSDividedRenderUtil::CalculateSurfaceNodeClipRects(
115     const RSSurfaceRenderNode& node,
116     const RectF& absBounds,
117     const RectF& localBounds,
118     bool inLocalCoordinate,
119     BufferDrawParam& params)
120 {
121     const RSProperties& property = node.GetRenderProperties();
122     params.cornerRadius = property.GetCornerRadius();
123     params.isNeedClip = property.GetClipToFrame();
124     if (inLocalCoordinate) {
125         // in canvas's local coordinate system.
126 #ifndef USE_ROSEN_DRAWING
127         params.clipRect = SkRect::MakeWH(localBounds.GetWidth(), localBounds.GetHeight());
128 #else
129         params.clipRect = Drawing::Rect(0, 0, localBounds.GetWidth(), localBounds.GetHeight());
130 #endif
131         params.clipRRect = RRect(localBounds, params.cornerRadius);
132     } else {
133         // in logical screen's coordinate system.
134         const auto& clipRect = node.GetDstRect();
135 #ifndef USE_ROSEN_DRAWING
136         params.clipRect = SkRect::MakeXYWH(
137             clipRect.GetLeft(), clipRect.GetTop(), clipRect.GetWidth(), clipRect.GetHeight());
138 #else
139         params.clipRect = Drawing::Rect(clipRect.GetLeft(), clipRect.GetTop(),
140             clipRect.GetWidth() + clipRect.GetLeft(), clipRect.GetHeight() + clipRect.GetTop());
141 #endif
142         params.clipRRect = RRect(absBounds, params.cornerRadius);
143     }
144 }
145 } // namespace Rosen
146 } // namespace OHOS
147