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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrStyle.h
diff --git a/src/gpu/GrStyle.h b/src/gpu/GrStyle.h
new file mode 100644
index 0000000000000000000000000000000000000000..9164f34a45ae7714cb831646560e449d4fb5f354
--- /dev/null
+++ b/src/gpu/GrStyle.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrStyle_DEFINED
+#define GrStyle_DEFINED
+
+#include "GrTypes.h"
+#include "SkPathEffect.h"
+#include "SkStrokeRec.h"
+#include "SkTemplates.h"
+
+/**
+ * Represents the various ways that a GrShape can be styled. It has fill/stroking information
+ * as well as an optional path effect. If the path effect represents dashing, the dashing
+ * information is extracted from the path effect and stored explicitly.
+ *
+ * This object does not support stroke-and-fill styling. It is expected that stroking and filling
robertphillips 2016/04/24 23:00:44 separately
bsalomon 2016/04/25 13:32:26 Done.
+ * is handled by drawing a stroke and a fill separatetly.
+ *
+ * This will replace GrStrokeInfo as GrShape is deployed.
+ */
+class GrStyle {
+public:
+ GrStyle() : fStrokeRec(SkStrokeRec::kFill_InitStyle) {
+ fDashInfo.fType = SkPathEffect::kNone_DashType;
+ }
+
+ GrStyle(const SkStrokeRec& strokeRec, SkPathEffect* pe) : fStrokeRec(strokeRec) {
+ SkASSERT(SkStrokeRec::kStrokeAndFill_Style != strokeRec.getStyle());
+ this->initPathEffect(pe);
+ }
+
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.
+ GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) {
+ *this = that;
+ }
+
+ 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.
+ : fStrokeRec(paint) {
+ SkASSERT(SkStrokeRec::kStrokeAndFill_Style != fStrokeRec.getStyle());
+ this->initPathEffect(paint.getPathEffect());
+ }
+
+ GrStyle& operator=(const GrStyle& that) {
+ fPathEffect = that.fPathEffect;
+ fDashInfo = that.fDashInfo;
+ fStrokeRec = that.fStrokeRec;
+ return *this;
+ }
+ SkPathEffect* pathEffect() const { return fPathEffect.get(); }
+
+ bool isDashed() const { return SkPathEffect::kDash_DashType == fDashInfo.fType; }
+ SkScalar dashPhase() const {
+ SkASSERT(this->isDashed());
+ return fDashInfo.fPhase;
+ }
+ SkScalar dashIntervalCnt() const {
+ SkASSERT(this->isDashed());
+ return fDashInfo.fIntervals.count();
+ }
+ const SkScalar* dashIntervals() const {
+ SkASSERT(this->isDashed());
+ return fDashInfo.fIntervals.get();
+ }
+
+ const SkStrokeRec& strokeRec() const { return fStrokeRec; }
+
+private:
+ void initPathEffect(SkPathEffect* pe);
+
+ struct DashInfo {
+ DashInfo& operator=(const DashInfo& that) {
+ fType = that.fType;
+ fPhase = that.fPhase;
+ fIntervals.reset(that.fIntervals.count());
+ memcpy(fIntervals.get(), that.fIntervals.get(),
+ sizeof(SkScalar) * that.fIntervals.count());
+ return *this;
+ }
+ SkPathEffect::DashType fType;
+ SkScalar fPhase;
+ SkAutoSTArray<4, SkScalar> fIntervals;
+ };
+
+ SkStrokeRec fStrokeRec;
+ sk_sp<SkPathEffect> fPathEffect;
+ DashInfo fDashInfo;
+};
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698