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 | |
11 | #include "include/core/SkRefCnt.h" |
12 | #include "include/core/SkTypes.h" |
13 | |
14 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
15 | |
16 | class SkCanvas; |
17 | struct SkIRect; |
18 | struct SkRect; |
19 | class SkSurface; |
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 |
38 | |
39 | static void SafetyNetLog(const char*); |
40 | |
41 | static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas); |
42 | |
43 | static int SaveBehind(SkCanvas* canvas, const SkRect* subset); |
44 | |
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 | |
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); |
61 | }; |
62 | |
63 | #endif // SK_BUILD_FOR_ANDROID_ANDROID |
64 | |
65 | #endif // SkAndroidFrameworkUtils_DEFINED |
66 | |