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