blob: ecdf735c7226dad5e2803bdd33f0d7e1d25f4dc5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/android/SkAndroidFrameworkUtils.h"
9#include "include/core/SkCanvas.h"
10#include "include/utils/SkPaintFilterCanvas.h"
11#include "src/core/SkDevice.h"
12#include "src/image/SkSurface_Base.h"
Stan Iliev73d8fd92017-08-02 15:36:24 -040013
Leon Scroggins III44764002018-11-13 10:26:34 -050014#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
15
16#include <log/log.h>
Stan Iliev73d8fd92017-08-02 15:36:24 -040017
18#if SK_SUPPORT_GPU
19bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
Mike Reeded4108e2020-12-17 10:32:24 -050020 return canvas->baseDevice()->android_utils_clipWithStencil();
Stan Iliev73d8fd92017-08-02 15:36:24 -040021}
Mike Reedaebe4392019-12-20 14:59:49 -050022#endif
Stan Iliev73d8fd92017-08-02 15:36:24 -040023
Leon Scroggins III44764002018-11-13 10:26:34 -050024void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) {
25 android_errorWriteLog(0x534e4554, bugNumber);
26}
27
Derek Sollenberger1958e5d2018-11-27 15:33:38 -050028sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) {
29 sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase()));
30 return surface;
31}
Mike Reed148b7fd2018-12-18 17:38:18 -050032
33int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) {
34 return canvas->only_axis_aligned_saveBehind(subset);
35}
Stan Ilievb0a86842019-03-28 16:39:58 -040036
Michael Ludwigc19b9c52020-06-25 16:19:03 -040037void SkAndroidFrameworkUtils::ReplaceClip(SkCanvas* canvas, const SkIRect* rect) {
38 SkIRect deviceRestriction;
39 if (!rect) {
40 if (canvas->fClipRestrictionRect.isEmpty()) {
41 deviceRestriction = canvas->imageInfo().bounds();
42 } else {
43 deviceRestriction = canvas->fClipRestrictionRect;
44 }
45 } else {
46 deviceRestriction = *rect;
47 }
48 canvas->androidFramework_replaceClip(deviceRestriction);
49}
50
Stan Ilievb0a86842019-03-28 16:39:58 -040051SkCanvas* SkAndroidFrameworkUtils::getBaseWrappedCanvas(SkCanvas* canvas) {
52 auto pfc = canvas->internal_private_asPaintFilterCanvas();
53 auto result = canvas;
54 while (pfc) {
55 result = pfc->proxy();
56 pfc = result->internal_private_asPaintFilterCanvas();
57 }
58 return result;
59}
Leon Scroggins III44764002018-11-13 10:26:34 -050060#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK