SkEdge.h revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkEdge_DEFINED 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkEdge_DEFINED 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRect.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkEdge { 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Type { 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLine_Type, 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kQuad_Type, 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kCubic_Type 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEdge* fNext; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEdge* fPrev; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fX; 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fDX; 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fFirstY; 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fLastY; 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int8_t fCurveCount; // only used by kQuad(+) and kCubic(-) 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fCurveShift; // appled to all Dx/DDx/DDDx except for fCubicDShift exception 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fCubicDShift; // applied to fCDx and fCDy only in cubic 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int8_t fWinding; // 1 or -1 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int shiftUp); 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by); 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void chopLineWithClip(const SkIRect& clip); 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com inline bool intersectsClip(const SkIRect& clip) const { 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fFirstY < clip.fBottom); 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fLastY >= clip.fTop; 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void dump() const { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #ifdef SK_CAN_USE_FLOAT 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("edge: firstY:%d lastY:%d x:%g dx:%g w:%d\n", fFirstY, fLastY, SkFixedToFloat(fX), SkFixedToFloat(fDX), fWinding); 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #else 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDebugf("edge: firstY:%d lastY:%d x:%x dx:%x w:%d\n", fFirstY, fLastY, fX, fDX, fWinding); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #endif 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void validate() const { 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPrev && fNext); 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fPrev->fNext == this); 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fNext->fPrev == this); 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(fFirstY <= fLastY); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(SkAbs32(fWinding) == 1); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkQuadraticEdge : public SkEdge { 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fQx, fQy; 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fQDx, fQDy; 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fQDDx, fQDDy; 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fQLastX, fQLastY; 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 70c07d23a6e220c0aff36e3e4e06c1b685a440108ereed@android.com int setQuadratic(const SkPoint pts[3], int shiftUp); 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int updateQuadratic(); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkCubicEdge : public SkEdge { 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fCx, fCy; 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fCDx, fCDy; 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fCDDx, fCDDy; 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fCDDDx, fCDDDy; 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkFixed fCLastX, fCLastY; 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int setCubic(const SkPoint pts[4], const SkIRect* clip, int shiftUp); 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int updateCubic(); 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 86