1 /*
2 * Copyright (c) 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 "rs_parallel_hardware_composer.h"
17 #include "platform/common/rs_log.h"
18
19 namespace OHOS {
20 namespace Rosen {
21
RSParallelSelfDrawingSurfaceShape(bool isRRect,RectF rect,Vector4f cornerRadius)22 RSParallelSelfDrawingSurfaceShape::RSParallelSelfDrawingSurfaceShape(bool isRRect, RectF rect, Vector4f cornerRadius)
23 : isRRect_(isRRect), rect_(rect), cornerRadius_(cornerRadius) {};
24
Init(uint32_t threadNum)25 void RSParallelHardwareComposer::Init(uint32_t threadNum)
26 {
27 std::map<unsigned int, Holes>().swap(surfaceAndHolesMap_);
28 // to avoid crash caused by multi-thread, init surfaceAndHolesMap_ firstly.
29 for (unsigned int i = 0; i < threadNum; i++) {
30 surfaceAndHolesMap_[i] = Holes();
31 }
32 }
33
ClearTransparentColor(RSPaintFilterCanvas & canvas,unsigned int surfaceIndex)34 void RSParallelHardwareComposer::ClearTransparentColor(RSPaintFilterCanvas& canvas, unsigned int surfaceIndex)
35 {
36 const auto &holes = surfaceAndHolesMap_[surfaceIndex];
37 if (holes.size() == 0) {
38 return;
39 }
40 for (const auto& hole : holes) {
41 #ifndef USE_ROSEN_DRAWING
42 canvas.save();
43 if (hole->IsRRect()) {
44 canvas.clipRRect(hole->GetRRect(), true);
45 } else {
46 canvas.clipRect(hole->GetRect());
47 }
48 canvas.clear(SK_ColorTRANSPARENT);
49 canvas.restore();
50 #else
51 canvas.Save();
52 if (hole->IsRRect()) {
53 canvas.ClipRoundRect(hole->GetRRect(), Drawing::ClipOp::INTERSECT, true);
54 } else {
55 canvas.ClipRect(hole->GetRect(), Drawing::ClipOp::INTERSECT, false);
56 }
57 canvas.Clear(Drawing::Color::COLOR_TRANSPARENT);
58 canvas.Restore();
59 #endif
60 }
61 }
62
AddTransparentColorArea(unsigned int surfaceIndex,std::unique_ptr<RSParallelSelfDrawingSurfaceShape> && shape)63 void RSParallelHardwareComposer::AddTransparentColorArea(unsigned int surfaceIndex,
64 std::unique_ptr<RSParallelSelfDrawingSurfaceShape> &&shape)
65 {
66 if (surfaceAndHolesMap_.count(surfaceIndex) > 0) {
67 surfaceAndHolesMap_[surfaceIndex].push_back(std::move(shape));
68 } else {
69 RS_LOGE("Key doesn't exist, size:%{public}zu, index:%{public}u", surfaceAndHolesMap_.size(), surfaceIndex);
70 }
71 }
72
73 } // namespace Rosen
74 } // namespace OHOS