blob: d0f4499eb50146e8efe787738ec5fc2df5169d69 [file] [log] [blame]
Stan Iliev73d8fd92017-08-02 15:36:24 -04001/*
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 Sollenberger1958e5d2018-11-27 15:33:38 -050011#include "SkSurface_Base.h"
Stan Iliev73d8fd92017-08-02 15:36:24 -040012
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 III44764002018-11-13 10:26:34 -050021#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
22
23#include <log/log.h>
Stan Iliev73d8fd92017-08-02 15:36:24 -040024
25#if SK_SUPPORT_GPU
26bool 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 III44764002018-11-13 10:26:34 -050058void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) {
59 android_errorWriteLog(0x534e4554, bugNumber);
60}
61
Derek Sollenberger1958e5d2018-11-27 15:33:38 -050062sk_sp<SkSurface> SkAndroidFrameworkUtils::getSurfaceFromCanvas(SkCanvas* canvas) {
63 sk_sp<SkSurface> surface(SkSafeRef(canvas->getSurfaceBase()));
64 return surface;
65}
Mike Reed148b7fd2018-12-18 17:38:18 -050066
67int SkAndroidFrameworkUtils::SaveBehind(SkCanvas* canvas, const SkRect* subset) {
68 return canvas->only_axis_aligned_saveBehind(subset);
69}
Leon Scroggins III44764002018-11-13 10:26:34 -050070#endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
Stan Iliev73d8fd92017-08-02 15:36:24 -040071