aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrSamplerState.h
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-09-07 12:36:34 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-07 16:58:31 +0000
commit2bbdcc44c63974f29f3743bb58d929601a3f65c6 (patch)
treed420f298f606b061054e56866d1930ab84f00ed5 /include/gpu/GrSamplerState.h
parent4df0092eac6e9bb5afc516773a0c618630193dc6 (diff)
Rework GrSamplerParams to be more compact and use its own wrap mode enum.
The main change is to make GrSamplerParams smaller by making its enums have byte-sized underlying types. The rest is cosmetic. Change-Id: Ib71ea50612d24619a85e463826c6b8dfb9b445e3 Reviewed-on: https://skia-review.googlesource.com/43200 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'include/gpu/GrSamplerState.h')
-rw-r--r--include/gpu/GrSamplerState.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
new file mode 100644
index 0000000000..75f68912fa
--- /dev/null
+++ b/include/gpu/GrSamplerState.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrSamplerState_DEFINED
+#define GrSamplerState_DEFINED
+
+#include "GrTypes.h"
+
+/**
+ * Represents the filtering and tile modes used to access a texture.
+ */
+class GrSamplerState {
+public:
+ enum class Filter : uint8_t { kNearest, kBilerp, kMipMap };
+ enum class WrapMode : uint8_t { kClamp, kRepeat, kMirrorRepeat };
+
+ static constexpr GrSamplerState ClampNearest() { return GrSamplerState(); }
+ static constexpr GrSamplerState ClampBilerp() {
+ return GrSamplerState(WrapMode::kClamp, Filter::kBilerp);
+ }
+
+ constexpr GrSamplerState() : GrSamplerState(WrapMode::kClamp, Filter::kNearest) {}
+
+ constexpr GrSamplerState(WrapMode wrapXAndY, Filter filter)
+ : fWrapModes{wrapXAndY, wrapXAndY}, fFilter(filter) {}
+
+ constexpr GrSamplerState(const WrapMode wrapModes[2], Filter filter)
+ : fWrapModes{wrapModes[0], wrapModes[1]}, fFilter(filter) {}
+
+ constexpr GrSamplerState(const GrSamplerState&) = default;
+
+ GrSamplerState& operator=(const GrSamplerState& that) {
+ fWrapModes[0] = that.fWrapModes[0];
+ fWrapModes[1] = that.fWrapModes[1];
+ fFilter = that.fFilter;
+ return *this;
+ }
+
+ Filter filter() const { return fFilter; }
+
+ void setFilterMode(Filter filterMode) { fFilter = filterMode; }
+
+ void setWrapModeX(const WrapMode wrap) { fWrapModes[0] = wrap; }
+ void setWrapModeY(const WrapMode wrap) { fWrapModes[1] = wrap; }
+
+ WrapMode wrapModeX() const { return fWrapModes[0]; }
+ WrapMode wrapModeY() const { return fWrapModes[1]; }
+
+ bool isRepeated() const {
+ return WrapMode::kClamp != fWrapModes[0] || WrapMode::kClamp != fWrapModes[1];
+ }
+
+ bool operator==(const GrSamplerState& that) const {
+ return fWrapModes[0] == that.fWrapModes[0] && fWrapModes[1] == that.fWrapModes[1] &&
+ fFilter == that.fFilter;
+ }
+
+ bool operator!=(const GrSamplerState& that) const { return !(*this == that); }
+
+private:
+ WrapMode fWrapModes[2];
+ Filter fFilter;
+};
+
+#endif