1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkQuadClipper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2009 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkQuadClipper_DEFINED 1.14 +#define SkQuadClipper_DEFINED 1.15 + 1.16 +#include "SkPath.h" 1.17 + 1.18 +/** This class is initialized with a clip rectangle, and then can be fed quads, 1.19 + which must already be monotonic in Y. 1.20 + 1.21 + In the future, it might return a series of segments, allowing it to clip 1.22 + also in X, to ensure that all segments fit in a finite coordinate system. 1.23 + */ 1.24 +class SkQuadClipper { 1.25 +public: 1.26 + SkQuadClipper(); 1.27 + 1.28 + void setClip(const SkIRect& clip); 1.29 + 1.30 + bool clipQuad(const SkPoint src[3], SkPoint dst[3]); 1.31 + 1.32 +private: 1.33 + SkRect fClip; 1.34 +}; 1.35 + 1.36 +/** Iterator that returns the clipped segements of a quad clipped to a rect. 1.37 + The segments will be either lines or quads (based on SkPath::Verb), and 1.38 + will all be monotonic in Y 1.39 + */ 1.40 +class SkQuadClipper2 { 1.41 +public: 1.42 + bool clipQuad(const SkPoint pts[3], const SkRect& clip); 1.43 + bool clipCubic(const SkPoint pts[4], const SkRect& clip); 1.44 + 1.45 + SkPath::Verb next(SkPoint pts[]); 1.46 + 1.47 +private: 1.48 + SkPoint* fCurrPoint; 1.49 + SkPath::Verb* fCurrVerb; 1.50 + 1.51 + enum { 1.52 + kMaxVerbs = 13, 1.53 + kMaxPoints = 32 1.54 + }; 1.55 + SkPoint fPoints[kMaxPoints]; 1.56 + SkPath::Verb fVerbs[kMaxVerbs]; 1.57 + 1.58 + void clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip); 1.59 + void clipMonoCubic(const SkPoint srcPts[4], const SkRect& clip); 1.60 + void appendVLine(SkScalar x, SkScalar y0, SkScalar y1, bool reverse); 1.61 + void appendQuad(const SkPoint pts[3], bool reverse); 1.62 + void appendCubic(const SkPoint pts[4], bool reverse); 1.63 +}; 1.64 + 1.65 +#ifdef SK_DEBUG 1.66 + void sk_assert_monotonic_x(const SkPoint pts[], int count); 1.67 + void sk_assert_monotonic_y(const SkPoint pts[], int count); 1.68 +#else 1.69 + #define sk_assert_monotonic_x(pts, count) 1.70 + #define sk_assert_monotonic_y(pts, count) 1.71 +#endif 1.72 + 1.73 +#endif