18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDashPathEffect_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDashPathEffect_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathEffect.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDashPathEffect 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDashPathEffect is a subclass of SkPathEffect that implements dashing 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 177ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDashPathEffect : public SkPathEffect { 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 1920bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com /** intervals: array containing an even number of entries (>=2), with 2020bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com the even indices specifying the length of "on" intervals, and the odd 2120bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com indices specifying the length of "off" intervals. 22fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com count: number of elements in the intervals array 2320bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com phase: offset into the intervals array (mod the sum of all of the 2420bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com intervals). 2520bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 2620bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com For example: if intervals[] = {10, 20}, count = 2, and phase = 25, 2720bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com this will set up a dashed path like so: 2820bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 5 pixels off 2920bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 10 pixels on 3020bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 20 pixels off 3120bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 10 pixels on 3220bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 20 pixels off 3320bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com ... 3420bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com A phase of -5, 25, 55, 85, etc. would all result in the same path, 3520bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com because the sum of all the intervals is 30. 3620bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com 3720bf4ca8f5a5c00d19d8474d40208e456ee26838epoger@google.com Note: only affects stroked paths. 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 390a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org static SkDashPathEffect* Create(const SkScalar intervals[], int count, 4035c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org SkScalar phase) { 4135c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org return SkNEW_ARGS(SkDashPathEffect, (intervals, count, phase)); 420a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org } 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkDashPathEffect(); 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 45548a1f321011292359ef163f78c8a1d4871b3b7freed@google.com virtual bool filterPath(SkPath* dst, const SkPath& src, 464bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com SkStrokeRec*, const SkRect*) const SK_OVERRIDE; 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 48687c57c7d5a17549f63e0b15208db18b220e2a91skia.committer@gmail.com virtual bool asPoints(PointData* results, const SkPath& src, 494bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com const SkStrokeRec&, const SkMatrix&, 504bbdeac58cc928dc66296bde3bd06e78070d96b7reed@google.com const SkRect*) const SK_OVERRIDE; 51629ab540667422d3edcb97c51e9628b7051e1ba4robertphillips@google.com 52aec143824c9be4e4af6e2cb7cce3d2d2268c0b15commit-bot@chromium.org virtual DashType asADash(DashInfo* info) const SK_OVERRIDE; 53aec143824c9be4e4af6e2cb7cce3d2d2268c0b15commit-bot@chromium.org 549fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDashPathEffect) 556bac947cd5bc460dd9166ada6310d678fd2e39f8reed@google.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 5735c03fbf101306e8e82141853de4c664cbafedbbcommit-bot@chromium.org SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase); 589fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 59bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org explicit SkDashPathEffect(SkReadBuffer&); 609fa60daad4d5f54c0dbe3dbcc7608a8f6d721187reed#endif 61bd0be25074e53a6d1abc284562568c9745191984commit-bot@chromium.org virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 620a2bf90dccba3bde188e0386a7f0c60e6dde1ae9commit-bot@chromium.org 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar* fIntervals; 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fCount; 66aec143824c9be4e4af6e2cb7cce3d2d2268c0b15commit-bot@chromium.org SkScalar fPhase; 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // computed from phase 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fInitialDashLength; 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int32_t fInitialDashIndex; 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fIntervalLength; 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkPathEffect INHERITED; 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 76