blob: dc3a6ebc07402a8de7fef4e80fead612fd5e8972 [file] [log] [blame]
Stan Iliev73d8fd92017-08-02 15:36:24 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRefCnt.h"
12#include "include/core/SkTypes.h"
Stan Iliev73d8fd92017-08-02 15:36:24 -040013
Leon Scroggins III44764002018-11-13 10:26:34 -050014#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Stan Iliev73d8fd92017-08-02 15:36:24 -040015
16class SkCanvas;
Michael Ludwigc19b9c52020-06-25 16:19:03 -040017struct SkIRect;
Mike Reed148b7fd2018-12-18 17:38:18 -050018struct SkRect;
Derek Sollenberger1958e5d2018-11-27 15:33:38 -050019class SkSurface;
Stan Iliev73d8fd92017-08-02 15:36:24 -040020
21/**
22 * SkAndroidFrameworkUtils expose private APIs used only by Android framework.
23 */
24class SkAndroidFrameworkUtils {
25public:
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 III44764002018-11-13 10:26:34 -050038
39 static void SafetyNetLog(const char*);
Derek Sollenberger1958e5d2018-11-27 15:33:38 -050040
41 static sk_sp<SkSurface> getSurfaceFromCanvas(SkCanvas* canvas);
Mike Reed148b7fd2018-12-18 17:38:18 -050042
43 static int SaveBehind(SkCanvas* canvas, const SkRect* subset);
Stan Ilievb0a86842019-03-28 16:39:58 -040044
Michael Ludwigc19b9c52020-06-25 16:19:03 -040045 // 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 Ilievb0a86842019-03-28 16:39:58 -040053 /**
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 Iliev73d8fd92017-08-02 15:36:24 -040061};
62
Leon Scroggins III44764002018-11-13 10:26:34 -050063#endif // SK_BUILD_FOR_ANDROID_ANDROID
Stan Iliev73d8fd92017-08-02 15:36:24 -040064
65#endif // SkAndroidFrameworkUtils_DEFINED