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 #include "render/rs_skia_filter.h"
17 #include <memory>
18 #include "draw/blend_mode.h"
19 
20 namespace OHOS {
21 namespace Rosen {
RSDrawingFilterOriginal(std::shared_ptr<Drawing::ImageFilter> imageFilter)22 RSDrawingFilterOriginal::RSDrawingFilterOriginal(std::shared_ptr<Drawing::ImageFilter> imageFilter)
23     : RSFilter(), imageFilter_(imageFilter) {}
24 
~RSDrawingFilterOriginal()25 RSDrawingFilterOriginal::~RSDrawingFilterOriginal() {}
26 
GetBrush() const27 Drawing::Brush RSDrawingFilterOriginal::GetBrush() const
28 {
29     Drawing::Brush brush;
30     brush.SetAntiAlias(true);
31     Drawing::Filter filter;
32     filter.SetImageFilter(imageFilter_);
33     brush.SetFilter(filter);
34     return brush;
35 }
36 
GetImageFilter() const37 std::shared_ptr<Drawing::ImageFilter> RSDrawingFilterOriginal::GetImageFilter() const
38 {
39     return imageFilter_;
40 }
41 
DrawImageRect(Drawing::Canvas & canvas,const std::shared_ptr<Drawing::Image> & image,const Drawing::Rect & src,const Drawing::Rect & dst) const42 void RSDrawingFilterOriginal::DrawImageRect(Drawing::Canvas& canvas, const std::shared_ptr<Drawing::Image>& image,
43     const Drawing::Rect& src, const Drawing::Rect& dst) const
44 {
45     auto brush = GetBrush();
46     canvas.AttachBrush(brush);
47     canvas.DrawImageRect(*image, src, dst, Drawing::SamplingOptions());
48     canvas.DetachBrush();
49 }
50 } // namespace Rosen
51 } // namespace OHOS
52