aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/android/SkAndroidFrameworkUtils.cpp
diff options
context:
space:
mode:
authorGravatar Stan Iliev <stani@google.com>2017-08-02 15:36:24 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-02 19:56:07 +0000
commit73d8fd90653135bb1247f92ebc1d730a40b4f9d5 (patch)
tree5d13763f33e48082d5d616fd9dea0b06a16bf69c /src/android/SkAndroidFrameworkUtils.cpp
parentdcba08e891f1766b047cf0dbe8bbd275d9f55d2b (diff)
Add a private API for writing the clip to the stencil
Add a private API used by Android framework, which writes the clip into a stencil buffer. This is used by HWUI to clip the WebView. Bug: 31489986 Change-Id: I94515f1539acd9d069c8aceb3300577feed9c94f Reviewed-on: https://skia-review.googlesource.com/29521 Commit-Queue: Stan Iliev <stani@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'src/android/SkAndroidFrameworkUtils.cpp')
-rw-r--r--src/android/SkAndroidFrameworkUtils.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/android/SkAndroidFrameworkUtils.cpp b/src/android/SkAndroidFrameworkUtils.cpp
new file mode 100644
index 0000000000..5fbc2cae18
--- /dev/null
+++ b/src/android/SkAndroidFrameworkUtils.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkAndroidFrameworkUtils.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+
+#if SK_SUPPORT_GPU
+#include "GrStyle.h"
+#include "GrClip.h"
+#include "GrRenderTargetContext.h"
+#include "GrUserStencilSettings.h"
+#include "effects/GrDisableColorXP.h"
+#endif //SK_SUPPORT_GPU
+
+#ifdef SK_BUILD_FOR_ANDROID
+
+#if SK_SUPPORT_GPU
+bool SkAndroidFrameworkUtils::clipWithStencil(SkCanvas* canvas) {
+ SkRegion clipRegion;
+ canvas->temporary_internal_getRgnClip(&clipRegion);
+ if (clipRegion.isEmpty()) {
+ return false;
+ }
+ SkBaseDevice* device = canvas->getDevice();
+ if (!device) {
+ return false;
+ }
+ GrRenderTargetContext* rtc = device->accessRenderTargetContext();
+ if (!rtc) {
+ return false;
+ }
+ GrPaint grPaint;
+ grPaint.setXPFactory(GrDisableColorXPFactory::Get());
+ GrNoClip noClip;
+ static constexpr GrUserStencilSettings kDrawToStencil(
+ GrUserStencilSettings::StaticInit<
+ 0x1,
+ GrUserStencilTest::kAlways,
+ 0x1,
+ GrUserStencilOp::kReplace,
+ GrUserStencilOp::kReplace,
+ 0x1>()
+ );
+ rtc->drawRegion(noClip, std::move(grPaint), GrAA::kNo, SkMatrix::I(), clipRegion,
+ GrStyle::SimpleFill(), &kDrawToStencil);
+ return true;
+}
+#endif //SK_SUPPORT_GPU
+
+#endif // SK_BUILD_FOR_ANDROID
+