Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkAndroidFrameworkUtils_DEFINED |
| 9 | #define SkAndroidFrameworkUtils_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRefCnt.h" |
| 12 | #include "include/core/SkTypes.h" |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 13 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 14 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 15 | |
| 16 | class SkCanvas; |
Michael Ludwig | c19b9c5 | 2020-06-25 16:19:03 -0400 | [diff] [blame] | 17 | struct SkIRect; |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 18 | struct SkRect; |
Derek Sollenberger | 1958e5d | 2018-11-27 15:33:38 -0500 | [diff] [blame] | 19 | class SkSurface; |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * SkAndroidFrameworkUtils expose private APIs used only by Android framework. |
| 23 | */ |
| 24 | class SkAndroidFrameworkUtils { |
| 25 | public: |
| 26 | |
| 27 | #if SK_SUPPORT_GPU |
| 28 | /** |
| 29 | * clipWithStencil draws the current clip into a stencil buffer with reference value and mask |
| 30 | * set to 0x1. This function works only on a GPU canvas. |
| 31 | * |
| 32 | * @param canvas A GPU canvas that has a non-empty clip. |
| 33 | * |
| 34 | * @return true on success or false if clip is empty or not a GPU canvas. |
| 35 | */ |
| 36 | static bool clipWithStencil(SkCanvas* canvas); |
| 37 | #endif //SK_SUPPORT_GPU |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 38 | |
| 39 | static void SafetyNetLog(const char*); |
Derek Sollenberger | 1958e5d | 2018-11-27 15:33:38 -0500 | [diff] [blame] | 40 | |
| 41 | static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas); |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 42 | |
| 43 | static int SaveBehind(SkCanvas* canvas, const SkRect* subset); |
Stan Iliev | b0a8684 | 2019-03-28 16:39:58 -0400 | [diff] [blame] | 44 | |
Michael Ludwig | c19b9c5 | 2020-06-25 16:19:03 -0400 | [diff] [blame] | 45 | // Operating within the canvas' clip stack, this resets the geometry of the clip to be an |
| 46 | // intersection with the device-space 'rect'. If 'rect' is null, this will use the rect that |
| 47 | // was last set using androidFramework_setDeviceClipRestriction on the canvas. If that was never |
| 48 | // set, it will restrict the clip to the canvas' dimensions. |
| 49 | // |
| 50 | // TODO: Eventually, make 'rect' non-optional and no longer store the restriction per canvas. |
| 51 | static void ReplaceClip(SkCanvas* canvas, const SkIRect* rect = nullptr); |
| 52 | |
Stan Iliev | b0a8684 | 2019-03-28 16:39:58 -0400 | [diff] [blame] | 53 | /** |
| 54 | * Unrolls a chain of nested SkPaintFilterCanvas to return the base wrapped canvas. |
| 55 | * |
| 56 | * @param canvas A SkPaintFilterCanvas or any other SkCanvas subclass. |
| 57 | * |
| 58 | * @return SkCanvas that was found in the innermost SkPaintFilterCanvas. |
| 59 | */ |
| 60 | static SkCanvas* getBaseWrappedCanvas(SkCanvas* canvas); |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 61 | }; |
| 62 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 63 | #endif // SK_BUILD_FOR_ANDROID_ANDROID |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 64 | |
| 65 | #endif // SkAndroidFrameworkUtils_DEFINED |