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 clipWithStencil(SkCanvas * canvas)19bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) { 20 return canvas->baseDevice()->android_utils_clipWithStencil(); 21 } 22 #endif 23 SafetyNetLog(const char * bugNumber)24void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) { 25 android_errorWriteLog(0x534e4554, bugNumber); 26 } 27 getSurfaceFromCanvas(SkCanvas * canvas)28sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) { 29 sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase())); 30 return surface; 31 } 32 SaveBehind(SkCanvas * canvas,const SkRect * subset)33int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) { 34 return canvas->only_axis_aligned_saveBehind(subset); 35 } 36 ReplaceClip(SkCanvas * canvas,const SkIRect * rect)37void 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 getBaseWrappedCanvas(SkCanvas * canvas)51SkCanvas* 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 } 60 #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK 61