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

Unified Diff: Source/core/animation/UnderlyingValue.h

Issue 1322123003: Add composite() method to InterpolationType interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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
« no previous file with comments | « Source/core/animation/InvalidatableStyleInterpolation.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/UnderlyingValue.h
diff --git a/Source/core/animation/UnderlyingValue.h b/Source/core/animation/UnderlyingValue.h
new file mode 100644
index 0000000000000000000000000000000000000000..6d76d8fd866865e678c19e11ff99d5ccd5d05c00
--- /dev/null
+++ b/Source/core/animation/UnderlyingValue.h
@@ -0,0 +1,59 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UnderlyingValue_h
+#define UnderlyingValue_h
+
+#include "core/animation/InterpolationValue.h"
+#include "wtf/Allocator.h"
+
+namespace blink {
+
+// Handles memory management of underlying InterpolationValues in applyStack()
+// Ensures we perform copy on write if we are not the owner of an underlying InterpolationValue.
+// This functions similar to a DataRef except on OwnPtr'd objects.
+class UnderlyingValue {
+ STACK_ALLOCATED();
+
+public:
+ UnderlyingValue()
+ : m_valueOwner(nullptr)
+ , m_value(nullptr)
+ { }
+
+ void set(const InterpolationValue* interpolationValue)
+ {
+ // By clearing m_valueOwner we will perform a copy before attempting to mutate m_value,
+ // thus upholding the const contract for this instance of interpolationValue despite the const_cast.
+ m_valueOwner.clear();
+ m_value = const_cast<InterpolationValue*>(interpolationValue);
+ }
+ void set(PassOwnPtr<InterpolationValue> interpolationValue)
+ {
+ m_valueOwner = interpolationValue;
+ m_value = m_valueOwner.get();
+ }
+ InterpolationComponentValue& mutableComponent()
+ {
+ ASSERT(m_value);
+ if (!m_valueOwner)
+ set(m_value->clone());
+ return m_value->mutableComponent();
+ }
+ const InterpolationValue* get() const { return m_value; }
+ operator bool() const { return m_value; }
+ const InterpolationValue* operator->() const
+ {
+ ASSERT(m_value);
+ return m_value;
+ }
+
+private:
+ OwnPtr<InterpolationValue> m_valueOwner;
+ InterpolationValue* m_value;
+};
+
+} // namespace blink
+
+#endif // UnderlyingValue_h
« no previous file with comments | « Source/core/animation/InvalidatableStyleInterpolation.cpp ('k') | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698