aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrStyle.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-04-25 13:37:22 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-25 13:37:22 -0700
commitc885dacfe4625af8b0e2e5c6e8a8ae8dc2d620a8 (patch)
tree8fc3e643c7e8695c02735e5e0e58e4f28d5bffe8 /src/gpu/GrStyle.h
parent21736bd8b51cb78dba14a5bedf6690619fdb9ed3 (diff)
Add initial implementation of GrShape and GrStyle classes and tests
The initial intent is to use GrShape to simplify the mask blur code paths. However, I also want to use this to explore a more unified drawing code flow for different geometry types. The goal is to have a single representation for geometries+styling that attempts to always keep the geometry in the simplest form (e.g. preferring rrects to paths). It also allows for converting styling information into modified geometry and for computing consistent keys. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1822723003 Review URL: https://codereview.chromium.org/1822723003
Diffstat (limited to 'src/gpu/GrStyle.h')
-rw-r--r--src/gpu/GrStyle.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/gpu/GrStyle.h b/src/gpu/GrStyle.h
new file mode 100644
index 0000000000..4eef252de4
--- /dev/null
+++ b/src/gpu/GrStyle.h
@@ -0,0 +1,92 @@
+/*
+ * 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
+ * is handled by drawing a stroke and a fill separately.
+ *
+ * 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);
+ }
+
+ GrStyle(const GrStyle& that) : fStrokeRec(SkStrokeRec::kFill_InitStyle) {
+ *this = that;
+ }
+
+ explicit GrStyle(const SkPaint& paint) : 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;
+ }
+ int 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