Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: src/gpu/GrStyle.h

Issue 1822723003: Add initial implementation of GrShape and GrStyle classes and tests (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more cleanup Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
robertphillips 2016/04/24 23:00:44 separately
bsalomon 2016/04/25 13:32:26 Done.
22 * is handled by drawing a stroke and a fill separatetly.
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
robertphillips 2016/04/24 23:00:44 Do we need the init of fStrokeRec?
bsalomon 2016/04/25 13:32:27 Yep, it has no default cons.
robertphillips 2016/04/25 14:13:44 But aren't we just going to overwrite anything it
robertphillips 2016/04/25 14:15:30 Ah, forget it - I looked at the class.
37 GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) {
38 *this = that;
39 }
40
41 explicit GrStyle(const SkPaint& paint)
robertphillips 2016/04/24 23:00:44 put this on line above ?
bsalomon 2016/04/25 13:32:26 Done.
42 : fStrokeRec(paint) {
43 SkASSERT(SkStrokeRec::kStrokeAndFill_Style != fStrokeRec.getStyle());
44 this->initPathEffect(paint.getPathEffect());
45 }
46
47 GrStyle& operator=(const GrStyle& that) {
48 fPathEffect = that.fPathEffect;
49 fDashInfo = that.fDashInfo;
50 fStrokeRec = that.fStrokeRec;
51 return *this;
52 }
53 SkPathEffect* pathEffect() const { return fPathEffect.get(); }
54
55 bool isDashed() const { return SkPathEffect::kDash_DashType == fDashInfo.fTy pe; }
56 SkScalar dashPhase() const {
57 SkASSERT(this->isDashed());
58 return fDashInfo.fPhase;
59 }
60 SkScalar dashIntervalCnt() const {
61 SkASSERT(this->isDashed());
62 return fDashInfo.fIntervals.count();
63 }
64 const SkScalar* dashIntervals() const {
65 SkASSERT(this->isDashed());
66 return fDashInfo.fIntervals.get();
67 }
68
69 const SkStrokeRec& strokeRec() const { return fStrokeRec; }
70
71 private:
72 void initPathEffect(SkPathEffect* pe);
73
74 struct DashInfo {
75 DashInfo& operator=(const DashInfo& that) {
76 fType = that.fType;
77 fPhase = that.fPhase;
78 fIntervals.reset(that.fIntervals.count());
79 memcpy(fIntervals.get(), that.fIntervals.get(),
80 sizeof(SkScalar) * that.fIntervals.count());
81 return *this;
82 }
83 SkPathEffect::DashType fType;
84 SkScalar fPhase;
85 SkAutoSTArray<4, SkScalar> fIntervals;
86 };
87
88 SkStrokeRec fStrokeRec;
89 sk_sp<SkPathEffect> fPathEffect;
90 DashInfo fDashInfo;
91 };
92
93 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698