blob: 5fbc2cae1877fced7c7e8b8db0074aa3f6ad35bd [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"
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
21
22#if SK_SUPPORT_GPU
23bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
24 SkRegion clipRegion;
25 canvas->temporary_internal_getRgnClip(&clipRegion);
26 if (clipRegion.isEmpty()) {
27 return false;
28 }
29 SkBaseDevice* device = canvas->getDevice();
30 if (!device) {
31 return false;
32 }
33 GrRenderTargetContext* rtc = device->accessRenderTargetContext();
34 if (!rtc) {
35 return false;
36 }
37 GrPaint grPaint;
38 grPaint.setXPFactory(GrDisableColorXPFactory::Get());
39 GrNoClip noClip;
40 static constexpr GrUserStencilSettings kDrawToStencil(
41 GrUserStencilSettings::StaticInit<
42 0x1,
43 GrUserStencilTest::kAlways,
44 0x1,
45 GrUserStencilOp::kReplace,
46 GrUserStencilOp::kReplace,
47 0x1>()
48 );
49 rtc->drawRegion(noClip, std::move(grPaint), GrAA::kNo, SkMatrix::I(), clipRegion,
50 GrStyle::SimpleFill(), &kDrawToStencil);
51 return true;
52}
53#endif //SK_SUPPORT_GPU
54
55#endif // SK_BUILD_FOR_ANDROID
56