1 /* 2 * Copyright (C) 2024 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 #pragma once 18 19 #include <SkImage.h> 20 #include <SkRect.h> 21 #include <SkRuntimeEffect.h> 22 #include <SkShader.h> 23 #include <renderengine/LayerSettings.h> 24 #include <ui/EdgeExtensionEffect.h> 25 26 namespace android::renderengine::skia { 27 28 /** 29 * This shader is designed to prolong the texture of a surface whose bounds have been extended over 30 * the size of the texture. This shader is similar to the default clamp, but adds a blur effect and 31 * samples from close to the edge (compared to on the edge) to avoid weird artifacts when elements 32 * (in particular, scrollbars) touch the edge. 33 */ 34 class EdgeExtensionShaderFactory { 35 public: 36 EdgeExtensionShaderFactory(); 37 38 sk_sp<SkShader> createSkShader(const sk_sp<SkShader>& inputShader, const LayerSettings& layer, 39 const SkRect& imageBounds) const; 40 41 private: 42 std::unique_ptr<const SkRuntimeEffect::Result> mResult; 43 }; 44 } // namespace android::renderengine::skia 45