aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/record/SkRecordTraits.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/record/SkRecordTraits.h')
-rw-r--r--src/record/SkRecordTraits.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/record/SkRecordTraits.h b/src/record/SkRecordTraits.h
new file mode 100644
index 0000000000..570a717e92
--- /dev/null
+++ b/src/record/SkRecordTraits.h
@@ -0,0 +1,31 @@
+#include "SkRecords.h"
+#include "SkTLogic.h"
+
+// Type traits that are useful for working with SkRecords.
+
+namespace SkRecords {
+
+namespace {
+
+// Abstracts away whether the T is optional or not.
+template <typename T> const T* as_ptr(const SkRecords::Optional<T>& x) { return x; }
+template <typename T> const T* as_ptr(const T& x) { return &x; }
+
+} // namespace
+
+// Gets the paint from any command that may have one.
+template <typename Command> const SkPaint* GetPaint(const Command& x) { return as_ptr(x.paint); }
+
+// Have a paint? You are a draw command!
+template <typename Command> struct IsDraw {
+ SK_CREATE_MEMBER_DETECTOR(paint);
+ static const bool value = HasMember_paint<Command>::value;
+};
+
+// Have a clip op? You are a clip command.
+template <typename Command> struct IsClip {
+ SK_CREATE_MEMBER_DETECTOR(op);
+ static const bool value = HasMember_op<Command>::value;
+};
+
+} // namespace SkRecords