Sk2DPathEffect.cpp revision d252db03d9650013b545ef9781fe993c07f8f314
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* libs/graphics/effects/Sk2DPathEffect.cpp 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Copyright 2006, The Android Open Source Project 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Licensed under the Apache License, Version 2.0 (the "License"); 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** you may not use this file except in compliance with the License. 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** You may obtain a copy of the License at 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** http://www.apache.org/licenses/LICENSE-2.0 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** Unless required by applicable law or agreed to in writing, software 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** distributed under the License is distributed on an "AS IS" BASIS, 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** See the License for the specific language governing permissions and 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com** limitations under the License. 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "Sk2DPathEffect.h" 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBlitter.h" 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScan.h" 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass Sk2DPathEffectBlitter : public SkBlitter { 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Sk2DPathEffectBlitter(Sk2DPathEffect* pe, SkPath* dst) 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fPE(pe), fDst(dst) 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com {} 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void blitH(int x, int y, int count) 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPE->nextSpan(x, y, count, fDst); 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Sk2DPathEffect* fPE; 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* fDst; 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////////// 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSk2DPathEffect::Sk2DPathEffect(const SkMatrix& mat) : fMatrix(mat) 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mat.invert(&fInverse); 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool Sk2DPathEffect::filterPath(SkPath* dst, const SkPath& src, SkScalar* width) 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Sk2DPathEffectBlitter blitter(this, dst); 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath tmp; 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src.transform(fInverse, &tmp); 51d252db03d9650013b545ef9781fe993c07f8f314reed@android.com tmp.getBounds().round(&ir); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!ir.isEmpty()) { 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // need to pass a clip to fillpath, required for inverse filltypes, 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // even though those do not make sense for this patheffect 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion clip(ir); 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->begin(ir, dst); 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScan::FillPath(tmp, clip, &blitter); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->end(dst); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid Sk2DPathEffect::nextSpan(int x, int y, int count, SkPath* path) 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkMatrix& mat = this->getMatrix(); 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint src, dst; 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src.set(SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar(y) + SK_ScalarHalf); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com do { 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com mat.mapPoints(&dst, &src, 1); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->next(dst, x++, y, path); 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com src.fX += SK_Scalar1; 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } while (--count > 0); 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid Sk2DPathEffect::begin(const SkIRect& uvBounds, SkPath* dst) {} 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid Sk2DPathEffect::next(const SkPoint& loc, int u, int v, SkPath* dst) {} 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid Sk2DPathEffect::end(SkPath* dst) {} 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//////////////////////////////////////////////////////////////////////////////// 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid Sk2DPathEffect::flatten(SkFlattenableWriteBuffer& buffer) 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com buffer.writeMul4(&fMatrix, sizeof(fMatrix)); 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSk2DPathEffect::Sk2DPathEffect(SkFlattenableReadBuffer& buffer) 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com buffer.read(&fMatrix, sizeof(fMatrix)); 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMatrix.invert(&fInverse); 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkFlattenable::Factory Sk2DPathEffect::getFactory() 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return CreateProc; 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkFlattenable* Sk2DPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return SkNEW_ARGS(Sk2DPathEffect, (buffer)); 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 106