• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef SKIA_PAINT_H
17 #define SKIA_PAINT_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "include/core/SkPaint.h"
23 #include "include/core/SkColorSpace.h"
24 #include "include/core/SkShader.h"
25 #include "include/core/SkColorFilter.h"
26 #include "include/core/SkImageFilter.h"
27 #include "include/core/SkMaskFilter.h"
28 #include "include/core/SkPathEffect.h"
29 #include "src/core/SkPaintDefaults.h"
30 
31 #include "draw/paint.h"
32 
33 namespace OHOS {
34 namespace Rosen {
35 namespace Drawing {
36 const int MAX_PAINTS_NUMBER = 2;
37 struct SortedPaints {
38     SkPaint* paints_[MAX_PAINTS_NUMBER] = { 0 };
39     int count_ = 0;
40 };
41 
42 class SkiaPaint {
43 public:
44     SkiaPaint() noexcept;
45     ~SkiaPaint();
46 
47     static void BrushToSkPaint(const Brush& brush, SkPaint& paint);
48     static void PenToSkPaint(const Pen& pen, SkPaint& paint);
49     static void PaintToSkPaint(const Paint& paint, SkPaint& skPaint);
50 
51     void ApplyPaint(const Paint& paint);
52     SortedPaints& GetSortedPaints();
53     void Reset();
54 
55     static bool CanComputeFastBounds(const Brush& brush);
56     static const Rect& ComputeFastBounds(const Brush& brush, const Rect& orig, Rect* storage);
57 
58     static bool AsBlendMode(const Brush& brush);
59 
60 private:
61     static void ApplyFilter(SkPaint& paint, const Filter& filter);
62     static void ApplyStrokeParam(const Paint& paint, SkPaint& skPaint);
63 
64     int paintInUse_ = 0;
65     SkPaint paints_[MAX_PAINTS_NUMBER];
66     SkPaint defaultPaint_;
67 
68     SortedPaints sortedPaints_;
69 };
70 } // namespace Drawing
71 } // namespace Rosen
72 } // namespace OHOS
73 #endif