| OLD | NEW | 
| (Empty) |  | 
 |   1 /* | 
 |   2  * Copyright 2016 Google Inc. | 
 |   3  * | 
 |   4  * Use of this source code is governed by a BSD-style license that can be | 
 |   5  * found in the LICENSE file. | 
 |   6  */ | 
 |   7  | 
 |   8 #ifndef GrStyle_DEFINED | 
 |   9 #define GrStyle_DEFINED | 
 |  10  | 
 |  11 #include "GrTypes.h" | 
 |  12 #include "SkPathEffect.h" | 
 |  13 #include "SkStrokeRec.h" | 
 |  14 #include "SkTemplates.h" | 
 |  15  | 
 |  16 /** | 
 |  17  * Represents the various ways that a GrShape can be styled. It has fill/strokin
    g information | 
 |  18  * as well as an optional path effect. If the path effect represents dashing, th
    e dashing | 
 |  19  * information is extracted from the path effect and stored explicitly. | 
 |  20  * | 
 |  21  * This object does not support stroke-and-fill styling. It is expected that str
    oking and filling | 
 |  22  * is handled by drawing a stroke and a fill separately. | 
 |  23  * | 
 |  24  * This will replace GrStrokeInfo as GrShape is deployed. | 
 |  25  */ | 
 |  26 class GrStyle { | 
 |  27 public: | 
 |  28     GrStyle() : fStrokeRec(SkStrokeRec::kFill_InitStyle) { | 
 |  29         fDashInfo.fType = SkPathEffect::kNone_DashType; | 
 |  30     } | 
 |  31  | 
 |  32     GrStyle(const SkStrokeRec& strokeRec, SkPathEffect* pe) : fStrokeRec(strokeR
    ec) { | 
 |  33         SkASSERT(SkStrokeRec::kStrokeAndFill_Style != strokeRec.getStyle()); | 
 |  34         this->initPathEffect(pe); | 
 |  35     } | 
 |  36  | 
 |  37     GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) { | 
 |  38         *this = that; | 
 |  39     } | 
 |  40  | 
 |  41     explicit GrStyle(const SkPaint& paint) : fStrokeRec(paint) { | 
 |  42         SkASSERT(SkStrokeRec::kStrokeAndFill_Style != fStrokeRec.getStyle()); | 
 |  43         this->initPathEffect(paint.getPathEffect()); | 
 |  44     } | 
 |  45  | 
 |  46     GrStyle& operator=(const GrStyle& that) { | 
 |  47         fPathEffect = that.fPathEffect; | 
 |  48         fDashInfo = that.fDashInfo; | 
 |  49         fStrokeRec = that.fStrokeRec; | 
 |  50         return *this; | 
 |  51     } | 
 |  52     SkPathEffect* pathEffect() const { return fPathEffect.get(); } | 
 |  53  | 
 |  54     bool isDashed() const { return SkPathEffect::kDash_DashType == fDashInfo.fTy
    pe; } | 
 |  55     SkScalar dashPhase() const { | 
 |  56         SkASSERT(this->isDashed()); | 
 |  57         return fDashInfo.fPhase; | 
 |  58     } | 
 |  59     int dashIntervalCnt() const { | 
 |  60         SkASSERT(this->isDashed()); | 
 |  61         return fDashInfo.fIntervals.count(); | 
 |  62     } | 
 |  63     const SkScalar* dashIntervals() const { | 
 |  64         SkASSERT(this->isDashed()); | 
 |  65         return fDashInfo.fIntervals.get(); | 
 |  66     } | 
 |  67  | 
 |  68     const SkStrokeRec& strokeRec() const { return fStrokeRec; } | 
 |  69  | 
 |  70 private: | 
 |  71     void initPathEffect(SkPathEffect* pe); | 
 |  72  | 
 |  73     struct DashInfo { | 
 |  74         DashInfo& operator=(const DashInfo& that) { | 
 |  75             fType = that.fType; | 
 |  76             fPhase = that.fPhase; | 
 |  77             fIntervals.reset(that.fIntervals.count()); | 
 |  78             memcpy(fIntervals.get(), that.fIntervals.get(), | 
 |  79                    sizeof(SkScalar) * that.fIntervals.count()); | 
 |  80             return *this; | 
 |  81         } | 
 |  82         SkPathEffect::DashType      fType; | 
 |  83         SkScalar                    fPhase; | 
 |  84         SkAutoSTArray<4, SkScalar>  fIntervals; | 
 |  85     }; | 
 |  86  | 
 |  87     SkStrokeRec         fStrokeRec; | 
 |  88     sk_sp<SkPathEffect> fPathEffect; | 
 |  89     DashInfo            fDashInfo; | 
 |  90 }; | 
 |  91  | 
 |  92 #endif | 
| OLD | NEW |