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