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 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 14 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 15 | |
| 16 | #include <log/log.h> |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 17 | |
| 18 | #if SK_SUPPORT_GPU |
| 19 | bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) { |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 20 | SkBaseDevice* device = canvas->getDevice(); |
Mike Reed | aebe439 | 2019-12-20 14:59:49 -0500 | [diff] [blame] | 21 | return device && device->android_utils_clipWithStencil(); |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 22 | } |
Mike Reed | aebe439 | 2019-12-20 14:59:49 -0500 | [diff] [blame] | 23 | #endif |
Stan Iliev | 73d8fd9 | 2017-08-02 15:36:24 -0400 | [diff] [blame] | 24 | |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 25 | void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) { |
| 26 | android_errorWriteLog(0x534e4554, bugNumber); |
| 27 | } |
| 28 | |
Derek Sollenberger | 1958e5d | 2018-11-27 15:33:38 -0500 | [diff] [blame] | 29 | sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) { |
| 30 | sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase())); |
| 31 | return surface; |
| 32 | } |
Mike Reed | 148b7fd | 2018-12-18 17:38:18 -0500 | [diff] [blame] | 33 | |
| 34 | int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) { |
| 35 | return canvas->only_axis_aligned_saveBehind(subset); |
| 36 | } |
Stan Iliev | b0a8684 | 2019-03-28 16:39:58 -0400 | [diff] [blame] | 37 | |
Michael Ludwig | c19b9c5 | 2020-06-25 16:19:03 -0400 | [diff] [blame^] | 38 | void SkAndroidFrameworkUtils::ReplaceClip(SkCanvas* canvas, const SkIRect* rect) { |
| 39 | SkIRect deviceRestriction; |
| 40 | if (!rect) { |
| 41 | if (canvas->fClipRestrictionRect.isEmpty()) { |
| 42 | deviceRestriction = canvas->imageInfo().bounds(); |
| 43 | } else { |
| 44 | deviceRestriction = canvas->fClipRestrictionRect; |
| 45 | } |
| 46 | } else { |
| 47 | deviceRestriction = *rect; |
| 48 | } |
| 49 | canvas->androidFramework_replaceClip(deviceRestriction); |
| 50 | } |
| 51 | |
Stan Iliev | b0a8684 | 2019-03-28 16:39:58 -0400 | [diff] [blame] | 52 | SkCanvas* SkAndroidFrameworkUtils::getBaseWrappedCanvas(SkCanvas* canvas) { |
| 53 | auto pfc = canvas->internal_private_asPaintFilterCanvas(); |
| 54 | auto result = canvas; |
| 55 | while (pfc) { |
| 56 | result = pfc->proxy(); |
| 57 | pfc = result->internal_private_asPaintFilterCanvas(); |
| 58 | } |
| 59 | return result; |
| 60 | } |
Leon Scroggins III | 4476400 | 2018-11-13 10:26:34 -0500 | [diff] [blame] | 61 | #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK |