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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #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 Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 13 | |
| 14 | #if SK_SUPPORT_GPU |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrClip.h" |
| 16 | #include "src/gpu/GrRenderTargetContext.h" |
| 17 | #include "src/gpu/GrStyle.h" |
| 18 | #include "src/gpu/GrUserStencilSettings.h" |
| 19 | #include "src/gpu/effects/GrDisableColorXP.h" |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 20 | #endif //SK_SUPPORT_GPU |
| 21 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 22 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 23 | |
| 24 | #include <log/log.h> |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 25 | |
| 26 | #if SK_SUPPORT_GPU |
| 27 | bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) { |
| 28 | SkRegion clipRegion; |
| 29 | canvas->temporary_internal_getRgnClip(&clipRegion); |
| 30 | if (clipRegion.isEmpty()) { |
| 31 | return false; |
| 32 | } |
| 33 | SkBaseDevice* device = canvas->getDevice(); |
| 34 | if (!device) { |
| 35 | return false; |
| 36 | } |
| 37 | GrRenderTargetContext* rtc = device->accessRenderTargetContext(); |
| 38 | if (!rtc) { |
| 39 | return false; |
| 40 | } |
| 41 | GrPaint grPaint; |
| 42 | grPaint.setXPFactory(GrDisableColorXPFactory::Get()); |
| 43 | GrNoClip noClip; |
| 44 | static constexpr GrUserStencilSettings kDrawToStencil( |
| 45 | GrUserStencilSettings::StaticInit< |
| 46 | 0x1, |
| 47 | GrUserStencilTest::kAlways, |
| 48 | 0x1, |
| 49 | GrUserStencilOp::kReplace, |
| 50 | GrUserStencilOp::kReplace, |
| 51 | 0x1>() |
| 52 | ); |
| 53 | rtc->drawRegion(noClip, std::move(grPaint), GrAA::kNo, SkMatrix::I(), clipRegion, |
| 54 | GrStyle::SimpleFill(), &kDrawToStencil); |
| 55 | return true; |
| 56 | } |
| 57 | #endif //SK_SUPPORT_GPU |
| 58 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 59 | void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) { |
| 60 | android_errorWriteLog(0x534e4554, bugNumber); |
| 61 | } |
| 62 | |
Derek Sollenberger | 1958e5d | 2018-11-27 15:33:38 -0500 | [diff] [blame] | 63 | sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) { |
| 64 | sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase())); |
| 65 | return surface; |
| 66 | } |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 67 | |
| 68 | int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) { |
| 69 | return canvas->only_axis_aligned_saveBehind(subset); |
| 70 | } |
Stan Iliev | b0a8684 | 2019-03-28 16:39:58 -0400 | [diff] [blame] | 71 | |
| 72 | SkCanvas* SkAndroidFrameworkUtils::getBaseWrappedCanvas(SkCanvas* canvas) { |
| 73 | auto pfc = canvas->internal_private_asPaintFilterCanvas(); |
| 74 | auto result = canvas; |
| 75 | while (pfc) { |
| 76 | result = pfc->proxy(); |
| 77 | pfc = result->internal_private_asPaintFilterCanvas(); |
| 78 | } |
| 79 | return result; |
| 80 | } |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 81 | #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 82 | |