1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_GRAPHICS_BLURDRAWLOOPER_H_ 18 #define ANDROID_GRAPHICS_BLURDRAWLOOPER_H_ 19 20 #include <hwui/Paint.h> 21 #include <SkRefCnt.h> 22 23 class SkColorSpace; 24 25 namespace android { 26 27 class BlurDrawLooper : public SkRefCnt { 28 public: 29 static sk_sp<BlurDrawLooper> Make(SkColor4f, SkColorSpace*, float blurSigma, SkPoint offset); 30 31 ~BlurDrawLooper() override; 32 33 // proc(SkPoint offset, const Paint& modifiedPaint) 34 template <typename DrawProc> apply(const Paint & paint,DrawProc proc)35 void apply(const Paint& paint, DrawProc proc) const { 36 Paint p(paint); 37 proc(this->apply(&p), p); // draw the shadow 38 proc({0, 0}, paint); // draw the original (on top) 39 } 40 41 private: 42 const SkColor4f mColor; 43 const float mBlurSigma; 44 const SkPoint mOffset; 45 46 SkPoint apply(Paint* paint) const; 47 48 BlurDrawLooper(SkColor4f, float, SkPoint); 49 }; 50 51 } // namespace android 52 53 #endif // ANDROID_GRAPHICS_BLURDRAWLOOPER_H_ 54