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