chromium/third_party/skia/src/pathops/SkPathOpsDebug.h

/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef SkPathOpsDebug_DEFINED
#define SkPathOpsDebug_DEFINED

#include "include/core/SkTypes.h"
#include "include/pathops/SkPathOps.h"
#include "include/private/base/SkTDArray.h"

#include <cstddef>

class SkOpAngle;
class SkOpCoincidence;
class SkOpContour;
class SkOpContourHead;
class SkOpPtT;
class SkOpSegment;
class SkOpSpan;
class SkOpSpanBase;
class SkPath;
struct SkDConic;
struct SkDCubic;
struct SkDLine;
struct SkDPoint;
struct SkDQuad;

// define this when running fuzz
// #define SK_BUILD_FOR_FUZZER

#ifdef SK_RELEASE
#define FORCE_RELEASE
#else
#define FORCE_RELEASE
#endif

#define DEBUG_UNDER_DEVELOPMENT

#define ONE_OFF_DEBUG
#define ONE_OFF_DEBUG_MATHEMATICA

#if defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_ANDROID)
    #define SK_RAND
#else
    #define SK_RAND(seed)
#endif

#define WIND_AS_STRING(x)

#if FORCE_RELEASE

#define DEBUG_ACTIVE_OP
#define DEBUG_ACTIVE_SPANS
#define DEBUG_ADD_INTERSECTING_TS
#define DEBUG_ADD_T
#define DEBUG_ALIGNMENT
#define DEBUG_ANGLE
#define DEBUG_ASSEMBLE
#define DEBUG_COINCIDENCE
#define DEBUG_COINCIDENCE_DUMP
#define DEBUG_COINCIDENCE_ORDER
#define DEBUG_COINCIDENCE_VERBOSE
#define DEBUG_CUBIC_BINARY_SEARCH
#define DEBUG_CUBIC_SPLIT
#define DEBUG_DUMP_SEGMENTS
#define DEBUG_DUMP_VERIFY
#define DEBUG_FLOW
#define DEBUG_LIMIT_WIND_SUM
#define DEBUG_MARK_DONE
#define DEBUG_PATH_CONSTRUCTION
#define DEBUG_PERP
#define DEBUG_SORT
#define DEBUG_T_SECT
#define DEBUG_T_SECT_DUMP
#define DEBUG_T_SECT_LOOP_COUNT
#define DEBUG_VALIDATE
#define DEBUG_WINDING
#define DEBUG_WINDING_AT_T

#else

#define DEBUG_ACTIVE_OP
#define DEBUG_ACTIVE_SPANS
#define DEBUG_ADD_INTERSECTING_TS
#define DEBUG_ADD_T
#define DEBUG_ALIGNMENT
#define DEBUG_ANGLE
#define DEBUG_ASSEMBLE
#define DEBUG_COINCIDENCE
#define DEBUG_COINCIDENCE_DUMP
#define DEBUG_COINCIDENCE_ORDER
#define DEBUG_COINCIDENCE_VERBOSE
#define DEBUG_CUBIC_BINARY_SEARCH
#define DEBUG_CUBIC_SPLIT
#define DEBUG_DUMP_VERIFY
#define DEBUG_DUMP_SEGMENTS
#define DEBUG_FLOW
#define DEBUG_LIMIT_WIND_SUM
#define DEBUG_MARK_DONE
#define DEBUG_PATH_CONSTRUCTION
#define DEBUG_PERP
#define DEBUG_SORT
#define DEBUG_T_SECT
#define DEBUG_T_SECT_DUMP
#define DEBUG_T_SECT_LOOP_COUNT
#define DEBUG_VALIDATE
#define DEBUG_WINDING
#define DEBUG_WINDING_AT_T

#endif

#ifdef SK_RELEASE
    #define SkDEBUGRELEASE
    #define SkDEBUGPARAMS
#else
    #define SkDEBUGRELEASE(a, b)
    #define SkDEBUGPARAMS(...)
#endif

#if DEBUG_VALIDATE == 0
    #define PATH_OPS_DEBUG_VALIDATE_PARAMS(...)
#else
    #define PATH_OPS_DEBUG_VALIDATE_PARAMS
#endif

#if DEBUG_T_SECT == 0
    #define PATH_OPS_DEBUG_T_SECT_RELEASE(a, b)
    #define PATH_OPS_DEBUG_T_SECT_PARAMS(...)
    #define PATH_OPS_DEBUG_T_SECT_CODE(...)
#else
    #define PATH_OPS_DEBUG_T_SECT_RELEASE
    #define PATH_OPS_DEBUG_T_SECT_PARAMS
    #define PATH_OPS_DEBUG_T_SECT_CODE
#endif

#if DEBUG_T_SECT_DUMP > 1
    extern int gDumpTSectNum;
#endif

#if DEBUG_COINCIDENCE || DEBUG_COINCIDENCE_DUMP
    #define DEBUG_COIN
#else
    #define DEBUG_COIN
#endif

#if DEBUG_COIN
enum class SkOpPhase : char;

    #define DEBUG_COIN_DECLARE_ONLY_PARAMS
    #define DEBUG_COIN_DECLARE_PARAMS
    #define DEBUG_COIN_ONLY_PARAMS
    #define DEBUG_COIN_PARAMS
    #define DEBUG_ITER_ONLY_PARAMS
    #define DEBUG_ITER_PARAMS
    #define DEBUG_PHASE_ONLY_PARAMS
    #define DEBUG_PHASE_PARAMS
    #define DEBUG_SET_PHASE
    #define DEBUG_STATIC_SET_PHASE
#elif DEBUG_VALIDATE
    #define DEBUG_COIN_DECLARE_ONLY_PARAMS
    #define DEBUG_COIN_DECLARE_PARAMS
    #define DEBUG_COIN_ONLY_PARAMS
    #define DEBUG_COIN_PARAMS
    #define DEBUG_ITER_ONLY_PARAMS
    #define DEBUG_ITER_PARAMS
    #define DEBUG_PHASE_ONLY_PARAMS
    #define DEBUG_PHASE_PARAMS
    #define DEBUG_SET_PHASE
    #define DEBUG_STATIC_SET_PHASE
#else
    #define DEBUG_COIN_DECLARE_ONLY_PARAMS()
    #define DEBUG_COIN_DECLARE_PARAMS()
    #define DEBUG_COIN_ONLY_PARAMS()
    #define DEBUG_COIN_PARAMS()
    #define DEBUG_ITER_ONLY_PARAMS(iteration)
    #define DEBUG_ITER_PARAMS(iteration)
    #define DEBUG_PHASE_ONLY_PARAMS(phase)
    #define DEBUG_PHASE_PARAMS(phase)
    #define DEBUG_SET_PHASE()
    #define DEBUG_STATIC_SET_PHASE(obj)
#endif

#define CUBIC_DEBUG_STR
#define CONIC_DEBUG_STR
#define QUAD_DEBUG_STR
#define LINE_DEBUG_STR
#define PT_DEBUG_STR

#define T_DEBUG_STR(t, n)
#define TX_DEBUG_STR(t)
#define CUBIC_DEBUG_DATA(c)
#define CONIC_DEBUG_DATA(c, w)
#define QUAD_DEBUG_DATA(q)
#define LINE_DEBUG_DATA(l)
#define PT_DEBUG_DATA(i, n)

#ifndef DEBUG_TEST
#define DEBUG_TEST
#endif

// Tests with extreme numbers may fail, but all other tests should never fail.
#define FAIL_IF(cond)

#define FAIL_WITH_NULL_IF(cond)

class SkPathOpsDebug {};

// Visual Studio 2017 does not permit calling member functions from the Immediate Window.
// Global functions work fine, however. Use globals rather than static members inside a class.
const SkOpAngle* AngleAngle(const SkOpAngle*, int id);
SkOpContour* AngleContour(SkOpAngle*, int id);
const SkOpPtT* AnglePtT(const SkOpAngle*, int id);
const SkOpSegment* AngleSegment(const SkOpAngle*, int id);
const SkOpSpanBase* AngleSpan(const SkOpAngle*, int id);

const SkOpAngle* ContourAngle(SkOpContour*, int id);
SkOpContour* ContourContour(SkOpContour*, int id);
const SkOpPtT* ContourPtT(SkOpContour*, int id);
const SkOpSegment* ContourSegment(SkOpContour*, int id);
const SkOpSpanBase* ContourSpan(SkOpContour*, int id);

const SkOpAngle* CoincidenceAngle(SkOpCoincidence*, int id);
SkOpContour* CoincidenceContour(SkOpCoincidence*, int id);
const SkOpPtT* CoincidencePtT(SkOpCoincidence*, int id);
const SkOpSegment* CoincidenceSegment(SkOpCoincidence*, int id);
const SkOpSpanBase* CoincidenceSpan(SkOpCoincidence*, int id);

const SkOpAngle* PtTAngle(const SkOpPtT*, int id);
SkOpContour* PtTContour(SkOpPtT*, int id);
const SkOpPtT* PtTPtT(const SkOpPtT*, int id);
const SkOpSegment* PtTSegment(const SkOpPtT*, int id);
const SkOpSpanBase* PtTSpan(const SkOpPtT*, int id);

const SkOpAngle* SegmentAngle(const SkOpSegment*, int id);
SkOpContour* SegmentContour(SkOpSegment*, int id);
const SkOpPtT* SegmentPtT(const SkOpSegment*, int id);
const SkOpSegment* SegmentSegment(const SkOpSegment*, int id);
const SkOpSpanBase* SegmentSpan(const SkOpSegment*, int id);

const SkOpAngle* SpanAngle(const SkOpSpanBase*, int id);
SkOpContour* SpanContour(SkOpSpanBase*, int id);
const SkOpPtT* SpanPtT(const SkOpSpanBase*, int id);
const SkOpSegment* SpanSegment(const SkOpSpanBase*, int id);
const SkOpSpanBase* SpanSpan(const SkOpSpanBase*, int id);

#if DEBUG_DUMP_VERIFY
void DumpOp(const SkPath& one, const SkPath& two, SkPathOp op,
        const char* testName);
void DumpOp(FILE* file, const SkPath& one, const SkPath& two, SkPathOp op,
        const char* testName);
void DumpSimplify(const SkPath& path, const char* testName);
void DumpSimplify(FILE* file, const SkPath& path, const char* testName);
void ReportOpFail(const SkPath& one, const SkPath& two, SkPathOp op);
void ReportSimplifyFail(const SkPath& path);
void VerifyOp(const SkPath& one, const SkPath& two, SkPathOp op,
    const SkPath& result);
void VerifySimplify(const SkPath& path, const SkPath& result);
#endif

// global path dumps for msvs Visual Studio 17 to use from Immediate Window
void Dump(const SkOpContour& );
void DumpAll(const SkOpContour& );
void DumpAngles(const SkOpContour& );
void DumpContours(const SkOpContour& );
void DumpContoursAll(const SkOpContour& );
void DumpContoursAngles(const SkOpContour& );
void DumpContoursPts(const SkOpContour& );
void DumpContoursPt(const SkOpContour& , int segmentID);
void DumpContoursSegment(const SkOpContour& , int segmentID);
void DumpContoursSpan(const SkOpContour& , int segmentID);
void DumpContoursSpans(const SkOpContour& );
void DumpPt(const SkOpContour& , int );
void DumpPts(const SkOpContour& , const char* prefix = "seg");
void DumpSegment(const SkOpContour& , int );
void DumpSegments(const SkOpContour& , const char* prefix = "seg", SkPathOp op = (SkPathOp) -1);
void DumpSpan(const SkOpContour& , int );
void DumpSpans(const SkOpContour& );

void Dump(const SkOpSegment& );
void DumpAll(const SkOpSegment& );
void DumpAngles(const SkOpSegment& );
void DumpCoin(const SkOpSegment& );
void DumpPts(const SkOpSegment& , const char* prefix = "seg");

void Dump(const SkOpPtT& );
void DumpAll(const SkOpPtT& );

void Dump(const SkOpSpanBase& );
void DumpCoin(const SkOpSpanBase& );
void DumpAll(const SkOpSpanBase& );

void DumpCoin(const SkOpSpan& );
bool DumpSpan(const SkOpSpan& );

void Dump(const SkDConic& );
void DumpID(const SkDConic& , int id);

void Dump(const SkDCubic& );
void DumpID(const SkDCubic& , int id);

void Dump(const SkDLine& );
void DumpID(const SkDLine& , int id);

void Dump(const SkDQuad& );
void DumpID(const SkDQuad& , int id);

void Dump(const SkDPoint& );

void Dump(const SkOpAngle& );

// generates tools/path_sorter.htm and path_visualizer.htm compatible data
void DumpQ(const SkDQuad& quad1, const SkDQuad& quad2, int testNo);
void DumpT(const SkDQuad& quad, double t);

// global path dumps for msvs Visual Studio 17 to use from Immediate Window
void Dump(const SkPath& path);
void DumpHex(const SkPath& path);

#endif