aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-03-09 09:03:58 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-09 14:39:24 +0000
commitc65aec97619682b2c0191554f44ddf35f618a94d (patch)
treed88683d594b32b9604d98e9a31840c2d77312c7c /src/gpu
parent4eed4c885050132b7131324ea336ad0f6d977fef (diff)
Make GrClip.h private
BUG=skia: Change-Id: I4aa3c2707811ece3a63d161035e316c3bbc1cd15 Reviewed-on: https://skia-review.googlesource.com/9482 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrClip.h143
-rw-r--r--src/gpu/GrContext.cpp7
-rw-r--r--src/gpu/GrTextureProducer.cpp2
-rw-r--r--src/gpu/GrYUVProvider.cpp8
-rw-r--r--src/gpu/GrYUVProvider.h1
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp3
-rw-r--r--src/gpu/ops/GrAAHairLinePathRenderer.cpp6
7 files changed, 156 insertions, 14 deletions
diff --git a/src/gpu/GrClip.h b/src/gpu/GrClip.h
new file mode 100644
index 0000000000..eb4eab2d0c
--- /dev/null
+++ b/src/gpu/GrClip.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrClip_DEFINED
+#define GrClip_DEFINED
+
+#include "GrTypes.h"
+#include "SkRRect.h"
+#include "SkRect.h"
+
+class GrAppliedClip;
+class GrContext;
+class GrRenderTargetContext;
+
+/**
+ * GrClip is an abstract base class for applying a clip. It constructs a clip mask if necessary, and
+ * fills out a GrAppliedClip instructing the caller on how to set up the draw state.
+ */
+class GrClip {
+public:
+ virtual bool quickContains(const SkRect&) const = 0;
+ virtual bool quickContains(const SkRRect& rrect) const {
+ return this->quickContains(rrect.getBounds());
+ }
+ virtual void getConservativeBounds(int width, int height, SkIRect* devResult,
+ bool* isIntersectionOfRects = nullptr) const = 0;
+ virtual bool apply(GrContext*, GrRenderTargetContext*, bool useHWAA,
+ bool hasUserStencilSettings, GrAppliedClip* out) const = 0;
+
+ virtual ~GrClip() {}
+
+ /**
+ * This method quickly and conservatively determines whether the entire clip is equivalent to
+ * intersection with a rrect. This will only return true if the rrect does not fully contain
+ * the render target bounds. Moreover, the returned rrect need not be contained by the render
+ * target bounds. We assume all draws will be implicitly clipped by the render target bounds.
+ *
+ * @param rtBounds The bounds of the render target that the clip will be applied to.
+ * @param rrect If return is true rrect will contain the rrect equivalent to the clip within
+ * rtBounds.
+ * @param aa If return is true aa will indicate whether the rrect clip is antialiased.
+ * @return true if the clip is equivalent to a single rrect, false otherwise.
+ *
+ */
+ virtual bool isRRect(const SkRect& rtBounds, SkRRect* rrect, GrAA* aa) const = 0;
+
+ /**
+ * This is the maximum distance that a draw may extend beyond a clip's boundary and still count
+ * count as "on the other side". We leave some slack because floating point rounding error is
+ * likely to blame. The rationale for 1e-3 is that in the coverage case (and barring unexpected
+ * rounding), as long as coverage stays within 0.5 * 1/256 of its intended value it shouldn't
+ * have any effect on the final pixel values.
+ */
+ constexpr static SkScalar kBoundsTolerance = 1e-3f;
+
+ /**
+ * Returns true if the given query bounds count as entirely inside the clip.
+ *
+ * @param innerClipBounds device-space rect contained by the clip (SkRect or SkIRect).
+ * @param queryBounds device-space bounds of the query region.
+ */
+ template <typename TRect>
+ constexpr static bool IsInsideClip(const TRect& innerClipBounds, const SkRect& queryBounds) {
+ return innerClipBounds.fRight - innerClipBounds.fLeft > kBoundsTolerance &&
+ innerClipBounds.fBottom - innerClipBounds.fTop > kBoundsTolerance &&
+ innerClipBounds.fLeft < queryBounds.fLeft + kBoundsTolerance &&
+ innerClipBounds.fTop < queryBounds.fTop + kBoundsTolerance &&
+ innerClipBounds.fRight > queryBounds.fRight - kBoundsTolerance &&
+ innerClipBounds.fBottom > queryBounds.fBottom - kBoundsTolerance;
+ }
+
+ /**
+ * Returns true if the given query bounds count as entirely outside the clip.
+ *
+ * @param outerClipBounds device-space rect that contains the clip (SkRect or SkIRect).
+ * @param queryBounds device-space bounds of the query region.
+ */
+ template <typename TRect>
+ constexpr static bool IsOutsideClip(const TRect& outerClipBounds, const SkRect& queryBounds) {
+ return outerClipBounds.fRight - outerClipBounds.fLeft <= kBoundsTolerance ||
+ outerClipBounds.fBottom - outerClipBounds.fTop <= kBoundsTolerance ||
+ outerClipBounds.fLeft >= queryBounds.fRight - kBoundsTolerance ||
+ outerClipBounds.fTop >= queryBounds.fBottom - kBoundsTolerance ||
+ outerClipBounds.fRight <= queryBounds.fLeft + kBoundsTolerance ||
+ outerClipBounds.fBottom <= queryBounds.fTop + kBoundsTolerance;
+ }
+
+ /**
+ * Returns the minimal integer rect that counts as containing a given set of bounds.
+ */
+ static SkIRect GetPixelIBounds(const SkRect& bounds) {
+ return SkIRect::MakeLTRB(SkScalarFloorToInt(bounds.fLeft + kBoundsTolerance),
+ SkScalarFloorToInt(bounds.fTop + kBoundsTolerance),
+ SkScalarCeilToInt(bounds.fRight - kBoundsTolerance),
+ SkScalarCeilToInt(bounds.fBottom - kBoundsTolerance));
+ }
+
+ /**
+ * Returns the minimal pixel-aligned rect that counts as containing a given set of bounds.
+ */
+ static SkRect GetPixelBounds(const SkRect& bounds) {
+ return SkRect::MakeLTRB(SkScalarFloorToScalar(bounds.fLeft + kBoundsTolerance),
+ SkScalarFloorToScalar(bounds.fTop + kBoundsTolerance),
+ SkScalarCeilToScalar(bounds.fRight - kBoundsTolerance),
+ SkScalarCeilToScalar(bounds.fBottom - kBoundsTolerance));
+ }
+
+ /**
+ * Returns true if the given rect counts as aligned with pixel boundaries.
+ */
+ static bool IsPixelAligned(const SkRect& rect) {
+ return SkScalarAbs(SkScalarRoundToScalar(rect.fLeft) - rect.fLeft) <= kBoundsTolerance &&
+ SkScalarAbs(SkScalarRoundToScalar(rect.fTop) - rect.fTop) <= kBoundsTolerance &&
+ SkScalarAbs(SkScalarRoundToScalar(rect.fRight) - rect.fRight) <= kBoundsTolerance &&
+ SkScalarAbs(SkScalarRoundToScalar(rect.fBottom) - rect.fBottom) <= kBoundsTolerance;
+ }
+};
+
+/**
+ * Specialized implementation for no clip.
+ */
+class GrNoClip final : public GrClip {
+private:
+ bool quickContains(const SkRect&) const final { return true; }
+ bool quickContains(const SkRRect&) const final { return true; }
+ void getConservativeBounds(int width, int height, SkIRect* devResult,
+ bool* isIntersectionOfRects) const final {
+ devResult->setXYWH(0, 0, width, height);
+ if (isIntersectionOfRects) {
+ *isIntersectionOfRects = true;
+ }
+ }
+ bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*) const final {
+ return true;
+ }
+ bool isRRect(const SkRect&, SkRRect*, GrAA*) const override { return false; }
+};
+
+#endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 67c497b680..40e212df8d 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -6,24 +6,23 @@
*/
#include "GrContext.h"
-#include "GrContextPriv.h"
+#include "GrClip.h"
#include "GrContextOptions.h"
+#include "GrContextPriv.h"
#include "GrDrawingManager.h"
#include "GrRenderTargetContext.h"
+#include "GrRenderTargetProxy.h"
#include "GrResourceCache.h"
#include "GrResourceProvider.h"
-#include "GrRenderTargetProxy.h"
#include "GrSemaphore.h"
#include "GrSoftwarePathRenderer.h"
#include "GrSurfaceContext.h"
#include "GrSurfacePriv.h"
#include "GrSurfaceProxyPriv.h"
#include "GrTextureContext.h"
-
#include "SkConvertPixels.h"
#include "SkGr.h"
#include "SkUnPreMultiplyPriv.h"
-
#include "effects/GrConfigConversionEffect.h"
#include "text/GrTextBlobCache.h"
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index 496dbb2d0b..37fab37737 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -6,7 +6,7 @@
*/
#include "GrTextureProducer.h"
-
+#include "GrClip.h"
#include "GrRenderTargetContext.h"
#include "GrTexture.h"
#include "effects/GrBicubicEffect.h"
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 8d921a4f5a..84a41f808a 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -5,19 +5,19 @@
* found in the LICENSE file.
*/
+#include "GrYUVProvider.h"
+#include "GrClip.h"
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrRenderTargetContext.h"
#include "GrTextureProxy.h"
-#include "GrYUVProvider.h"
-#include "effects/GrSRGBEffect.h"
-#include "effects/GrYUVEffect.h"
-
#include "SkAutoMalloc.h"
#include "SkCachedData.h"
#include "SkRefCnt.h"
#include "SkResourceCache.h"
#include "SkYUVPlanesCache.h"
+#include "effects/GrSRGBEffect.h"
+#include "effects/GrYUVEffect.h"
namespace {
/**
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index ef3ae6dd7e..af5a4a47c9 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -14,6 +14,7 @@
class GrContext;
class GrTexture;
+class GrTextureProxy;
/**
* There are at least 2 different ways to extract/retrieve YUV planar data...
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index d6299022e5..7bdcaf5ca0 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -6,13 +6,14 @@
*/
#include "GrConfigConversionEffect.h"
+#include "../private/GrGLSL.h"
+#include "GrClip.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
#include "GrSimpleTextureEffect.h"
#include "SkMatrix.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "../private/GrGLSL.h"
class GrGLConfigConversionEffect : public GrGLSLFragmentProcessor {
public:
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 6e244839ec..408740d2a7 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -6,9 +6,9 @@
*/
#include "GrAAHairLinePathRenderer.h"
-
#include "GrBuffer.h"
#include "GrCaps.h"
+#include "GrClip.h"
#include "GrContext.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrDrawOpTest.h"
@@ -20,10 +20,8 @@
#include "SkGeometry.h"
#include "SkStroke.h"
#include "SkTemplates.h"
-
-#include "ops/GrMeshDrawOp.h"
-
#include "effects/GrBezierEffect.h"
+#include "ops/GrMeshDrawOp.h"
#define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true>