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 "SkAndroidFrameworkUtils.h"
9 #include "SkCanvas.h"
10 #include "SkDevice.h"
11
12 #if SK_SUPPORT_GPU
13 #include "GrStyle.h"
14 #include "GrClip.h"
15 #include "GrRenderTargetContext.h"
16 #include "GrUserStencilSettings.h"
17 #include "effects/GrDisableColorXP.h"
18 #endif //SK_SUPPORT_GPU
19
20 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
21
22 #include <log/log.h>
23
24 #if SK_SUPPORT_GPU
clipWithStencil(SkCanvas * canvas)25 bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
26 SkRegion clipRegion;
27 canvas->temporary_internal_getRgnClip(&clipRegion);
28 if (clipRegion.isEmpty()) {
29 return false;
30 }
31 SkBaseDevice* device = canvas->getDevice();
32 if (!device) {
33 return false;
34 }
35 GrRenderTargetContext* rtc = device->accessRenderTargetContext();
36 if (!rtc) {
37 return false;
38 }
39 GrPaint grPaint;
40 grPaint.setXPFactory(GrDisableColorXPFactory::Get());
41 GrNoClip noClip;
42 static constexpr GrUserStencilSettings kDrawToStencil(
43 GrUserStencilSettings::StaticInit<
44 0x1,
45 GrUserStencilTest::kAlways,
46 0x1,
47 GrUserStencilOp::kReplace,
48 GrUserStencilOp::kReplace,
49 0x1>()
50 );
51 rtc->drawRegion(noClip, std::move(grPaint), GrAA::kNo, SkMatrix::I(), clipRegion,
52 GrStyle::SimpleFill(), &kDrawToStencil);
53 return true;
54 }
55 #endif //SK_SUPPORT_GPU
56
SafetyNetLog(const char * bugNumber)57 void SkAndroidFrameworkUtils::SafetyNetLog(const char* bugNumber) {
58 android_errorWriteLog(0x534e4554, bugNumber);
59 }
60
61 #endif // SK_BUILD_FOR_ANDROID_FRAMEWORK
62
63