Flutter Engine
The Flutter Engine
SkAndroidFrameworkUtils.cpp
Go to the documentation of this file.
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
11#include "src/base/SkTLazy.h"
12#include "src/core/SkDevice.h"
15
16#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
17
18#include <log/log.h>
19
20#if defined(SK_GANESH)
21bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
22 return canvas->rootDevice()->android_utils_clipWithStencil();
23}
24#endif
25
26void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) {
27 android_errorWriteLog(0x534e4554, bugNumber);
28}
29
30sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) {
31 sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase()));
32 return surface;
33}
34
35int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) {
36 return canvas->only_axis_aligned_saveBehind(subset);
37}
38
39void SkAndroidFrameworkUtils::ResetClip(SkCanvas* canvas) {
40 canvas->internal_private_resetClip();
41}
42
43SkCanvas* SkAndroidFrameworkUtils::getBaseWrappedCanvas(SkCanvas* canvas) {
44 auto pfc = canvas->internal_private_asPaintFilterCanvas();
45 auto result = canvas;
46 while (pfc) {
47 result = pfc->proxy();
48 pfc = result->internal_private_asPaintFilterCanvas();
49 }
50 return result;
51}
52
53bool SkAndroidFrameworkUtils::ShaderAsALinearGradient(SkShader* shader,
54 LinearGradientInfo* info) {
55 SkASSERT(shader);
57 if (info) {
58 baseInfo.init();
59 baseInfo->fColorCount = info->fColorCount;
60 baseInfo->fColors = info->fColors;
61 baseInfo->fColorOffsets = info->fColorOffsets;
62 }
63 if (as_SB(shader)->asGradient(baseInfo.getMaybeNull()) != SkShaderBase::GradientType::kLinear) {
64 return false;
65 }
66 if (info) {
67 info->fColorCount = baseInfo->fColorCount; // this is inout in asGradient()
68 info->fPoints[0] = baseInfo->fPoint[0];
69 info->fPoints[1] = baseInfo->fPoint[1];
70 info->fTileMode = baseInfo->fTileMode;
71 info->fGradientFlags = baseInfo->fGradientFlags;
72 }
73 return true;
74}
75
76#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkASSERT(cond)
Definition: SkAssert.h:116
static T * SkSafeRef(T *obj)
Definition: SkRefCnt.h:140
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
virtual SkPaintFilterCanvas * internal_private_asPaintFilterCanvas() const
Definition: SkCanvas.h:2610
virtual bool android_utils_clipWithStencil()
Definition: SkDevice.h:267
T * init(Args &&... args)
Definition: SkTLazy.h:45
const T * getMaybeNull() const
Definition: SkTLazy.h:108
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51