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 #pragma once 17 18 #include "GrRecordingContext.h" 19 #include <effects/StretchEffect.h> 20 #include <SkSurface.h> 21 #include "SkiaDisplayList.h" 22 23 namespace android::uirenderer { 24 25 /** 26 * Helper class used to create/cache an SkSurface instance 27 * to create a mask that is used to draw a stretched hole punch 28 */ 29 class StretchMask { 30 public: 31 /** 32 * Release the current surface used for the stretch mask 33 */ clear()34 void clear() { 35 mMaskSurface = nullptr; 36 } 37 38 /** 39 * Reset the dirty flag to re-create the stretch mask on the next draw 40 * pass 41 */ markDirty()42 void markDirty() { 43 mIsDirty = true; 44 } 45 46 /** 47 * Draws the stretch mask into the given target canvas 48 * @param context GrRecordingContext used to create the surface if necessary 49 * @param stretch StretchEffect to apply to the mask 50 * @param bounds Target bounds to draw into the given canvas 51 * @param displayList List of drawing commands to render into the stretch mask 52 * @param canvas Target canvas to draw the mask into 53 */ 54 void draw(GrRecordingContext* context, 55 const StretchEffect& stretch, const SkRect& bounds, 56 skiapipeline::SkiaDisplayList* displayList, SkCanvas* canvas); 57 private: 58 sk_sp<SkSurface> mMaskSurface; 59 bool mIsDirty = true; 60 }; 61 62 } 63