Sk2DPathEffect.cpp revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
1/* libs/graphics/effects/Sk2DPathEffect.cpp 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#include "Sk2DPathEffect.h" 19#include "SkBlitter.h" 20#include "SkPath.h" 21#include "SkScan.h" 22 23class Sk2DPathEffectBlitter : public SkBlitter { 24public: 25 Sk2DPathEffectBlitter(Sk2DPathEffect* pe, SkPath* dst) 26 : fPE(pe), fDst(dst) 27 {} 28 virtual void blitH(int x, int y, int count) 29 { 30 fPE->nextSpan(x, y, count, fDst); 31 } 32private: 33 Sk2DPathEffect* fPE; 34 SkPath* fDst; 35}; 36 37//////////////////////////////////////////////////////////////////////////////////// 38 39Sk2DPathEffect::Sk2DPathEffect(const SkMatrix& mat) : fMatrix(mat) 40{ 41 mat.invert(&fInverse); 42} 43 44bool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width) 45{ 46 Sk2DPathEffectBlitter blitter(this, dst); 47 SkPath tmp; 48 SkRect bounds; 49 SkIRect ir; 50 51 src.transform(fInverse, &tmp); 52 tmp.computeBounds(&bounds, SkPath::kExact_BoundsType); 53 bounds.round(&ir); 54 if (!ir.isEmpty()) { 55 // need to pass a clip to fillpath, required for inverse filltypes, 56 // even though those do not make sense for this patheffect 57 SkRegion clip(ir); 58 59 this->begin(ir, dst); 60 SkScan::FillPath(tmp, clip, &blitter); 61 this->end(dst); 62 } 63 return true; 64} 65 66void Sk2DPathEffect::nextSpan(int x, int y, int count, SkPath* path) 67{ 68 const SkMatrix& mat = this->getMatrix(); 69 SkPoint src, dst; 70 71 src.set(SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar(y) + SK_ScalarHalf); 72 do { 73 mat.mapPoints(&dst, &src, 1); 74 this->next(dst, x++, y, path); 75 src.fX += SK_Scalar1; 76 } while (--count > 0); 77} 78 79void Sk2DPathEffect::begin(const SkIRect& uvBounds, SkPath* dst) {} 80void Sk2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) {} 81void Sk2DPathEffect::end(SkPath* dst) {} 82 83//////////////////////////////////////////////////////////////////////////////// 84 85void Sk2DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) 86{ 87 buffer.writeMul4(&fMatrix, sizeof(fMatrix)); 88} 89 90Sk2DPathEffect::Sk2DPathEffect(SkFlattenableReadBuffer& buffer) 91{ 92 buffer.read(&fMatrix, sizeof(fMatrix)); 93 fMatrix.invert(&fInverse); 94} 95 96SkFlattenable::Factory Sk2DPathEffect::getFactory() 97{ 98 return CreateProc; 99} 100 101SkFlattenable* Sk2DPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) 102{ 103 return SkNEW_ARGS(Sk2DPathEffect, (buffer)); 104} 105 106 107 108