| 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 "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" | 
|---|
| 13 |  | 
|---|
| 14 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 
|---|
| 15 |  | 
|---|
| 16 | #include <log/log.h> | 
|---|
| 17 |  | 
|---|
| 18 | #if SK_SUPPORT_GPU | 
|---|
| 19 | bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) { | 
|---|
| 20 | SkBaseDevice* device = canvas->getDevice(); | 
|---|
| 21 | return device && device->android_utils_clipWithStencil(); | 
|---|
| 22 | } | 
|---|
| 23 | #endif | 
|---|
| 24 |  | 
|---|
| 25 | void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) { | 
|---|
| 26 | android_errorWriteLog(0x534e4554, bugNumber); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) { | 
|---|
| 30 | sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase())); | 
|---|
| 31 | return surface; | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) { | 
|---|
| 35 | return canvas->only_axis_aligned_saveBehind(subset); | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 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 |  | 
|---|
| 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 | } | 
|---|
| 61 | #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK | 
|---|
| 62 |  | 
|---|