1 /* libs/graphics/sgl/SkEdge.h 2 ** 3 ** Copyright 2006, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef SkEdge_DEFINED 19 #define SkEdge_DEFINED 20 21 #include "SkRect.h" 22 23 struct SkEdge { 24 enum Type { 25 kLine_Type, 26 kQuad_Type, 27 kCubic_Type 28 }; 29 30 SkEdge* fNext; 31 SkEdge* fPrev; 32 33 SkFixed fX; 34 SkFixed fDX; 35 int32_t fFirstY; 36 int32_t fLastY; 37 int8_t fCurveCount; // only used by kQuad(+) and kCubic(-) 38 uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception 39 uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic 40 int8_t fWinding; // 1 or -1 41 42 int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, 43 int shiftUp); 44 inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by); 45 void chopLineWithClip(const SkIRect& clip); 46 intersectsClipSkEdge47 inline bool intersectsClip(const SkIRect& clip) const { 48 SkASSERT(fFirstY < clip.fBottom); 49 return fLastY >= clip.fTop; 50 } 51 52 #ifdef SK_DEBUG dumpSkEdge53 void dump() const { 54 #ifdef SK_CAN_USE_FLOAT 55 SkDebugf("edge: firstY:%d lastY:%d x:%g dx:%g w:%d\n", fFirstY, fLastY, SkFixedToFloat(fX), SkFixedToFloat(fDX), fWinding); 56 #else 57 SkDebugf("edge: firstY:%d lastY:%d x:%x dx:%x w:%d\n", fFirstY, fLastY, fX, fDX, fWinding); 58 #endif 59 } 60 validateSkEdge61 void validate() const { 62 SkASSERT(fPrev && fNext); 63 SkASSERT(fPrev->fNext == this); 64 SkASSERT(fNext->fPrev == this); 65 66 SkASSERT(fFirstY <= fLastY); 67 SkASSERT(SkAbs32(fWinding) == 1); 68 } 69 #endif 70 }; 71 72 struct SkQuadraticEdge : public SkEdge { 73 SkFixed fQx, fQy; 74 SkFixed fQDx, fQDy; 75 SkFixed fQDDx, fQDDy; 76 SkFixed fQLastX, fQLastY; 77 78 int setQuadratic(const SkPoint pts[3], int shiftUp); 79 int updateQuadratic(); 80 }; 81 82 struct SkCubicEdge : public SkEdge { 83 SkFixed fCx, fCy; 84 SkFixed fCDx, fCDy; 85 SkFixed fCDDx, fCDDy; 86 SkFixed fCDDDx, fCDDDy; 87 SkFixed fCLastX, fCLastY; 88 89 int setCubic(const SkPoint pts[4], const SkIRect* clip, int shiftUp); 90 int updateCubic(); 91 }; 92 93 #endif 94