[go: nahoru, domu]

[animation] Increase the capacity of TargetProperties

This list of target properties in cc (defined in
cc/trees/target_property.h), is cc-specific and unrelated to the
generic animation system currently housed in cc/animation. As such,
other clients of this system may define their own list of target
properties, and the number of target properties used by these other
clients may well exceed the number of properties used by cc.

Unfortunately, the capacity of the TargetProperties type is tied to
cc's list of target properties. With this change, the maximum
capacity has been switched to an arbitrary constant. Corresponding
static_asserts have been added to ensure that this limit is not
exceeded.

Depressingly, this is still housed in cc/trees; it's not yet
possible to move TargetProperties cc/animation because it's used by
code in cc/trees which is not allowed to depend on cc/animation.
Once cc/animation no longer depends on cc we can break the
circularity and move this elsewhere.

Bug: 747185
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I89c8df0b08fe4729389295b6271c6e1f2b23074e
Reviewed-on: https://chromium-review.googlesource.com/720066
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509139}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index 5c1b29be..1ee79dd 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -326,6 +326,7 @@
     "trees/swap_promise_manager.h",
     "trees/swap_promise_monitor.cc",
     "trees/swap_promise_monitor.h",
+    "trees/target_property.cc",
     "trees/target_property.h",
     "trees/task_runner_provider.cc",
     "trees/task_runner_provider.h",
diff --git a/cc/trees/target_property.cc b/cc/trees/target_property.cc
new file mode 100644
index 0000000..ed20625
--- /dev/null
+++ b/cc/trees/target_property.cc
@@ -0,0 +1,20 @@
+// Copyright 2017 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.
+
+#include "cc/trees/target_property.h"
+
+namespace cc {
+
+static_assert(TargetProperty::LAST_TARGET_PROPERTY < kMaxTargetPropertyIndex,
+              "The number of cc target properties has exceeded the capacity of"
+              " TargetProperties");
+
+// bitset will use a multiple of the architecture int size, which is at least 32
+// bits so make it explicit to have as many properties as fit into the memory
+// used.
+static_assert(kMaxTargetPropertyIndex % (8 * sizeof(uint32_t)) == 0,
+              "The maximum number of target properties should be a multiple of "
+              "sizeof(uint32_t)");
+
+}  // namespace cc
diff --git a/cc/trees/target_property.h b/cc/trees/target_property.h
index a90a0a7..53d8c13a 100644
--- a/cc/trees/target_property.h
+++ b/cc/trees/target_property.h
@@ -9,8 +9,11 @@
 
 namespace cc {
 
+static constexpr size_t kMaxTargetPropertyIndex = 32u;
+
 namespace TargetProperty {
 
+// Must be zero-based as this will be stored in a bitset.
 enum Type {
   TRANSFORM = 0,
   OPACITY,
@@ -25,8 +28,8 @@
 
 }  // namespace TargetProperty
 
-// A set of target properties. TargetProperty must be 0-based enum.
-using TargetProperties = std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>;
+// A set of target properties.
+using TargetProperties = std::bitset<kMaxTargetPropertyIndex>;
 
 }  // namespace cc