#include "SkRandom.h"
#include "SkRegion.h"
#include "SkString.h"
+#include "SkClipOpPriv.h"
////////////////////////////////////////////////////////////////////////////////
// This bench tests out AA/BW clipping via canvas' clipPath and clipRect calls
#include "SkPath.h"
#include "SkSurface.h"
#include "SkTypeface.h"
+#include "SkClipOpPriv.h"
static const int kBmpSize = 24;
static const int kMaxX = 250;
#include "gm.h"
#include "SkBlurMaskFilter.h"
+#include "SkClipOpPriv.h"
#include "SkColorFilter.h"
#include "SkPaint.h"
#include "SkRRect.h"
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "gm.h"
#include "SkCanvas.h"
-//#include "SkParsePath.h"
#include "SkPath.h"
-//#include "SkRandom.h"
namespace skiagm {
#include "SkBlurImageFilter.h"
#include "SkRRect.h"
#include "SkSurface.h"
+#include "SkClipOpPriv.h"
#define WIDTH 512
#define HEIGHT 512
#include "SkString.h"
#include "SkTRegistry.h"
#include "sk_tool_utils.h"
+#include "SkClipOpPriv.h"
class SkAnimTimer;
struct GrContextOptions;
"SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS",
"SK_SUPPORT_LEGACY_SHADER_ISABITMAP",
"SK_SUPPORT_LEGACY_EMBOSSMASKFILTER",
+ "SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM",
]
class SkSurface_Base;
class SkTextBlob;
+#ifdef SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM
+ #define SkCanvasImpl_DefaultClipOp kIntersect_SkClipOp
+#else
+ #define SkCanvasImpl_DefaultClipOp SkClipOp::kIntersect
+#endif
+
/** \class SkCanvas
A Canvas encapsulates all of the state about drawing into a device (bitmap).
this->clipRect(rect, op, false);
}
void clipRect(const SkRect& rect, bool doAntiAlias = false) {
- this->clipRect(rect, kIntersect_SkClipOp, doAntiAlias);
+ this->clipRect(rect, SkCanvasImpl_DefaultClipOp, doAntiAlias);
}
/**
this->clipRRect(rrect, op, false);
}
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
- this->clipRRect(rrect, kIntersect_SkClipOp, doAntiAlias);
+ this->clipRRect(rrect, SkCanvasImpl_DefaultClipOp, doAntiAlias);
}
/**
this->clipPath(path, op, false);
}
void clipPath(const SkPath& path, bool doAntiAlias = false) {
- this->clipPath(path, kIntersect_SkClipOp, doAntiAlias);
+ this->clipPath(path, SkCanvasImpl_DefaultClipOp, doAntiAlias);
}
/** EXPERIMENTAL -- only used for testing
@param deviceRgn The region to apply to the current clip
@param op The region op to apply to the current clip
*/
- void clipRegion(const SkRegion& deviceRgn, SkClipOp op = kIntersect_SkClipOp);
+ void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkCanvasImpl_DefaultClipOp);
/** Return true if the specified rectangle, after being transformed by the
current matrix, would lie completely outside of the current clip. Call
#include "SkTypes.h"
-// these kept in SkRegion::Op order for now ...
+// SkClipOp enum values always match the corresponding values in SkRegion::Op
+
+#ifdef SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM
+
enum SkClipOp {
kDifference_SkClipOp = 0,
kIntersect_SkClipOp = 1,
kReplace_SkClipOp = 5,
};
+#else
+
+enum class SkClipOp {
+ kDifference = 0,
+ kIntersect = 1,
+
+ // Goal: remove these, since they can grow the current clip
+
+ kUnion = 2,
+ kXOR = 3,
+ kReverseDifference = 4,
+ kReplace = 5,
+};
+
+#endif
+
#endif
class SkCanvasClipVisitor;
+
+#ifdef SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM
+ #define SkClipStackImpl_ReplaceOp kReplace_SkClipOp
+#else
+ #define SkClipStackImpl_ReplaceOp SkClipOp::kReplace
+#endif
+
// Because a single save/restore state can have multiple clips, this class
// stores the stack depth (fSaveCount) and clips (fDeque) separately.
// Each clip in fDeque stores the stack state to which it belongs
static const int kTypeCnt = kLastType + 1;
Element() {
- this->initCommon(0, kReplace_SkClipOp, false);
+ this->initCommon(0, SkClipStackImpl_ReplaceOp, false);
this->setEmpty();
}
int fGenID;
Element(int saveCount) {
- this->initCommon(saveCount, kReplace_SkClipOp, false);
+ this->initCommon(saveCount, SkClipStackImpl_ReplaceOp, false);
this->setEmpty();
}
struct ClipOpAndAA {
ClipOpAndAA() {}
- ClipOpAndAA(SkClipOp op, bool aa) : op(op), aa(aa) {}
- SkClipOp op : 31; // This really only needs to be 3, but there's no win today to do so.
- unsigned aa : 1; // MSVC won't pack an enum with an bool, so we call this an unsigned.
+ ClipOpAndAA(SkClipOp op, bool aa) : fOp(static_cast<unsigned>(op)), fAA(aa) {}
+
+ SkClipOp op() const { return static_cast<SkClipOp>(fOp); }
+ bool aa() const { return fAA != 0; }
+
+private:
+ unsigned fOp : 31; // This really only needs to be 3, but there's no win today to do so.
+ unsigned fAA : 1; // MSVC won't pack an enum with an bool, so we call this an unsigned.
};
static_assert(sizeof(ClipOpAndAA) == 4, "ClipOpAndAASize");
"SK_SUPPORT_LEGACY_IMAGE_ENCODER_CLASS",
# Temporarily Disable analytic AA for Google3
"SK_NO_ANALYTIC_AA",
+ "SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM",
]
################################################################################
#include "SkWindow.h"
#include "sk_tool_utils.h"
#include "SkScan.h"
+#include "SkClipOpPriv.h"
#include "SkReadBuffer.h"
#include "SkStream.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkRandom.h"
+#include "SkClipOpPriv.h"
constexpr int W = 150;
constexpr int H = 200;
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SampleCode.h"
#include "SkCanvas.h"
#include "SkPath.h"
#include "SkView.h"
+#include "SkClipOpPriv.h"
class ComplexClipView : public SampleView {
public:
#include "SkUtils.h"
#include "SkImage.h"
#include "SkSurface.h"
+#include "SkClipOpPriv.h"
#define FAT_PIXEL_COLOR SK_ColorBLACK
#define PIXEL_CENTER_SIZE 3
#include "SkRandom.h"
#include "SkStream.h"
#include "SkTime.h"
+#include "SkClipOpPriv.h"
// Intended to exercise pixel snapping observed with scaled images (and
// with non-scaled images, but for a different reason): Bug 1145
#include "SkUtils.h"
#include "SkKey.h"
#include "SkDrawFilter.h"
+#include "SkClipOpPriv.h"
static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) {
SkColor colors[] = { 0, SK_ColorWHITE };
#include "SkGrPriv.h"
#endif
+#include "SkClipOpPriv.h"
#define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
--- /dev/null
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkClipOpPriv_DEFINED
+#define SkClipOpPriv_DEFINED
+
+#include "SkClipOp.h"
+
+#ifndef SK_SUPPORT_LEGACY_CLIPOPS_PLAIN_ENUM
+const SkClipOp kDifference_SkClipOp = SkClipOp::kDifference;
+const SkClipOp kIntersect_SkClipOp = SkClipOp::kIntersect;
+const SkClipOp kUnion_SkClipOp = SkClipOp::kUnion;
+const SkClipOp kXOR_SkClipOp = SkClipOp::kXOR;
+const SkClipOp kReverseDifference_SkClipOp = SkClipOp::kReverseDifference;
+const SkClipOp kReplace_SkClipOp = SkClipOp::kReplace;
+#endif
+
+#endif
#include "SkClipStack.h"
#include "SkPath.h"
#include "SkPathOps.h"
+#include "SkClipOpPriv.h"
#include <new>
"reverse-difference",
"replace",
};
- static_assert(0 == kDifference_SkClipOp, "op_str");
- static_assert(1 == kIntersect_SkClipOp, "op_str");
- static_assert(2 == kUnion_SkClipOp, "op_str");
- static_assert(3 == kXOR_SkClipOp, "op_str");
- static_assert(4 == kReverseDifference_SkClipOp, "op_str");
- static_assert(5 == kReplace_SkClipOp, "op_str");
+ static_assert(0 == static_cast<int>(kDifference_SkClipOp), "op_str");
+ static_assert(1 == static_cast<int>(kIntersect_SkClipOp), "op_str");
+ static_assert(2 == static_cast<int>(kUnion_SkClipOp), "op_str");
+ static_assert(3 == static_cast<int>(kXOR_SkClipOp), "op_str");
+ static_assert(4 == static_cast<int>(kReverseDifference_SkClipOp), "op_str");
+ static_assert(5 == static_cast<int>(kReplace_SkClipOp), "op_str");
static_assert(SK_ARRAY_COUNT(kOpStrings) == SkRegion::kOpCnt, "op_str");
SkDebugf("Type: %s, Op: %s, AA: %s, Save Count: %d\n", kTypeStrings[fType],
- kOpStrings[fOp], (fDoAA ? "yes" : "no"), fSaveCount);
+ kOpStrings[static_cast<int>(fOp)], (fDoAA ? "yes" : "no"), fSaveCount);
switch (fType) {
case kEmpty_Type:
SkDebugf("\n");
void operator()(const SkRecords::ClipPath& op) {
// TODO: does the SkRegion op matter?
- if (op.opAA.aa && !op.path.isConvex()) {
+ if (op.opAA.aa() && !op.path.isConvex()) {
fNumSlowPathsAndDashEffects++;
}
}
static inline uint32_t ClipParams_pack(SkClipOp op, bool doAA) {
unsigned doAABit = doAA ? 1 : 0;
- return (doAABit << 4) | op;
+ return (doAABit << 4) | static_cast<int>(op);
}
static inline SkClipOp ClipParams_unpackRegionOp(uint32_t packed) {
#include "SkRSXform.h"
#include "SkTextBlob.h"
#include "SkTSearch.h"
+#include "SkClipOpPriv.h"
#define HEAP_BLOCK_SIZE 4096
DRAW(Concat, concat(r.matrix));
DRAW(Translate, translate(r.dx, r.dy));
-DRAW(ClipPath, clipPath(r.path, r.opAA.op, r.opAA.aa));
-DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa));
-DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa));
+DRAW(ClipPath, clipPath(r.path, r.opAA.op(), r.opAA.aa()));
+DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op(), r.opAA.aa()));
+DRAW(ClipRect, clipRect(r.rect, r.opAA.op(), r.opAA.aa()));
DRAW(ClipRegion, clipRegion(r.region, r.op));
#ifdef SK_EXPERIMENTAL_SHADOWING
#include "SkGr.h"
#include "SkGrPriv.h"
#endif
+#include "SkClipOpPriv.h"
class SkXfermodeImageFilter_Base : public SkImageFilter {
public:
#include "effects/GrConvexPolyEffect.h"
#include "effects/GrRRectEffect.h"
#include "effects/GrTextureDomain.h"
+#include "SkClipOpPriv.h"
typedef SkClipStack::Element Element;
typedef GrReducedClip::InitialState InitialState;
bool invert;
bool skip = false;
switch (op) {
- case SkRegion::kReplace_Op:
+ case kReplace_SkClipOp:
SkASSERT(iter.get() == elements.head());
// Fallthrough, handled same as intersect.
- case SkRegion::kIntersect_Op:
+ case kIntersect_SkClipOp:
invert = false;
if (iter.get()->contains(boundsInClipSpace)) {
skip = true;
}
break;
- case SkRegion::kDifference_Op:
+ case kDifference_SkClipOp:
invert = true;
// We don't currently have a cheap test for whether a rect is fully outside an
// element's primitive, so don't attempt to set skip.
#include "GrStencilSettings.h"
#include "GrStyle.h"
#include "GrUserStencilSettings.h"
+#include "SkClipOpPriv.h"
typedef SkClipStack::Element Element;
}
static bool element_is_pure_subtract(SkClipOp op) {
- SkASSERT(op >= 0);
- return op <= kIntersect_SkClipOp;
+ SkASSERT(static_cast<int>(op) >= 0);
+ return static_cast<int>(op) <= static_cast<int>(kIntersect_SkClipOp);
- GR_STATIC_ASSERT(0 == kDifference_SkClipOp);
- GR_STATIC_ASSERT(1 == kIntersect_SkClipOp);
+ GR_STATIC_ASSERT(0 == static_cast<int>(kDifference_SkClipOp));
+ GR_STATIC_ASSERT(1 == static_cast<int>(kIntersect_SkClipOp));
}
void GrReducedClip::addInteriorWindowRectangles(int maxWindowRectangles) {
#include "SkTextFormatParams.h"
#include "SkUtils.h"
#include "SkXfermodeInterpretation.h"
+#include "SkClipOpPriv.h"
#define DPI_FOR_RASTER_SCALE_ONE 72
"region_pathop_mismatch");
static SkPathOp region_op_to_pathops_op(SkClipOp op) {
- SkASSERT(op >= 0);
- SkASSERT(op <= kReverseDifference_SkClipOp);
+ SkASSERT(static_cast<int>(op) >= 0);
+ SkASSERT(static_cast<int>(op) <= static_cast<int>(kReverseDifference_SkClipOp));
return (SkPathOp)op;
}
#include "SkTypeface.h"
#include "SkUtils.h"
#include "SkXMLWriter.h"
+#include "SkClipOpPriv.h"
namespace {
#include "SkDevice.h"
#include "SkRasterClip.h"
#include "SkWriter32.h"
+#include "SkClipOpPriv.h"
/*
* WARNING: The structs below are part of a stable ABI and as such we explicitly
#include "SkRRect.h"
#include "SkSurface.h"
#include "SkTextBlob.h"
+#include "SkClipOpPriv.h"
bool SkDeferredCanvas::Rec::isConcat(SkMatrix* m) const {
switch (fType) {
static const char* gOpNames[] = {
"DIFF", "SECT", "UNION", "XOR", "RDIFF", "REPLACE"
};
- return gOpNames[op];
+ return gOpNames[static_cast<int>(op)];
}
static void toString(const SkRegion& rgn, SkString* str) {
#include "CanvasStateHelpers.h"
#include "SkCanvas.h"
+#include "SkClipOpPriv.h"
#include "SkCanvasStateUtils.h"
#include "SkCommandLineFlags.h"
#include "SkDrawFilter.h"
#include "SkPath.h"
#include "SkPathOps.h"
#include "SkSurface.h"
+#include "SkClipOpPriv.h"
using Key = SkTArray<uint32_t>;
#include "SkString.h"
#include "SkTRegistry.h"
#include "SkTypes.h"
+#include "SkClipOpPriv.h"
#if SK_SUPPORT_GPU
#include "GrContextFactory.h"
#include "SkDrawCommand.h"
#include "SkPaintFilterCanvas.h"
#include "SkTextBlob.h"
+#include "SkClipOpPriv.h"
#if SK_SUPPORT_GPU
#include "GrAuditTrail.h"
addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path");
addPathData(operand, "pathB");
fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename);<br>",
- kHTML4SpaceIndent, gOpStrs[elementOp]);
+ kHTML4SpaceIndent, gOpStrs[static_cast<int>(elementOp)]);
fClipStackData.appendf("}<br>");
fCalledAddStackData = true;
}
#include "SkValidatingReadBuffer.h"
#include "SkWriteBuffer.h"
#include "picture_utils.h"
+#include "SkClipOpPriv.h"
#define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command"
#define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible"
#include "SkStringUtils.h"
#include "SkTypeface.h"
#include "SkUtils.h"
+#include "SkClipOpPriv.h"
/* TODO(chudy): Replace all std::strings with char */