• 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 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_SKIA_RS_SKIA_FILTER_H
16 #define RENDER_SERVICE_CLIENT_CORE_RENDER_SKIA_RS_SKIA_FILTER_H
17 
18 #ifndef USE_ROSEN_DRAWING
19 #include "include/core/SkCanvas.h"
20 #include "include/core/SkImageFilter.h"
21 #include "include/core/SkPaint.h"
22 #include "include/effects/SkImageFilters.h"
23 #else
24 #include "draw/brush.h"
25 #include "draw/canvas.h"
26 #include "effect/image_filter.h"
27 #endif
28 
29 #include "render/rs_filter.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 class RSPaintFilterCanvas;
34 #ifndef USE_ROSEN_DRAWING
35 class RSSkiaFilter : public RSFilter {
36 public:
37     RSSkiaFilter(sk_sp<SkImageFilter> imagefilter);
38     RSSkiaFilter(const RSSkiaFilter&) = delete;
39     ~RSSkiaFilter() override;
40     SkPaint GetPaint() const;
41     virtual void DrawImageRect(
42         SkCanvas& canvas, const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst) const;
43     sk_sp<SkImageFilter> GetImageFilter() const;
44     virtual std::shared_ptr<RSSkiaFilter> Compose(const std::shared_ptr<RSSkiaFilter>& other) const = 0;
PreProcess(sk_sp<SkImage> image)45     virtual void PreProcess(sk_sp<SkImage> image) {};
PostProcess(RSPaintFilterCanvas & canvas)46     virtual void PostProcess(RSPaintFilterCanvas& canvas) {};
SetGreyCoef(float greyCoef1,float greyCoef2,bool isGreyCoefValid)47     virtual void SetGreyCoef(float greyCoef1, float greyCoef2, bool isGreyCoefValid) {};
CanSkipFrame()48     virtual bool CanSkipFrame() const { return false; };
SetCanvasChange(SkMatrix & mat,float surfaceWidth,float surfaceHeight)49     virtual void SetCanvasChange(SkMatrix& mat, float surfaceWidth, float surfaceHeight) {};
SetBoundsGeometry(float geoWidth,float geoHeight)50     virtual void SetBoundsGeometry(float geoWidth, float geoHeight) {};
51 
52 protected:
53     sk_sp<SkImageFilter> imageFilter_ = nullptr;
54 };
55 #else
56 class RSDrawingFilter : public RSFilter {
57 public:
58     RSDrawingFilter(std::shared_ptr<Drawing::ImageFilter> imagefilter);
59     ~RSDrawingFilter() override;
60     Drawing::Brush GetBrush() const;
61     virtual void DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
62         const Drawing::Rect& src, const Drawing::Rect& dst) const;
63     std::shared_ptr<Drawing::ImageFilter> GetImageFilter() const;
64     virtual std::shared_ptr<RSDrawingFilter> Compose(const std::shared_ptr<RSDrawingFilter>& other) const = 0;
PreProcess(std::shared_ptr<Drawing::Image> image)65     virtual void PreProcess(std::shared_ptr<Drawing::Image> image) {};
PostProcess(RSPaintFilterCanvas & canvas)66     virtual void PostProcess(RSPaintFilterCanvas& canvas) {};
SetGreyCoef(float greyCoef1,float greyCoef2,bool isGreyCoefValid)67     virtual void SetGreyCoef(float greyCoef1, float greyCoef2, bool isGreyCoefValid) {};
CanSkipFrame()68     virtual bool CanSkipFrame() const { return false; };
SetCanvasChange(Drawing::Matrix & mat,float surfaceWidth,float surfaceHeight)69     virtual void SetCanvasChange(Drawing::Matrix& mat, float surfaceWidth, float surfaceHeight) {};
SetBoundsGeometry(float geoWidth,float geoHeight)70     virtual void SetBoundsGeometry(float geoWidth, float geoHeight) {};
71 
72 protected:
73     std::shared_ptr<Drawing::ImageFilter> imageFilter_ = nullptr;
74 };
75 #endif
76 } // namespace Rosen
77 } // namespace OHOS
78 
79 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_SKIA_RS_SKIA_FILTER_H