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

Unified Diff: chrome/browser/android/vr_shell/ui_elements/ui_element.h

Issue 2966793002: NOT FOR REVIEW - convert to cc animation
Patch Set: switch to transform operations Created 3 years, 6 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
Index: chrome/browser/android/vr_shell/ui_elements/ui_element.h
diff --git a/chrome/browser/android/vr_shell/ui_elements/ui_element.h b/chrome/browser/android/vr_shell/ui_elements/ui_element.h
index a45bed66245e87d051cc6e7cd11071e963f8ddb0..a39c537115602722a4bf22b89ffc1f7336074287 100644
--- a/chrome/browser/android/vr_shell/ui_elements/ui_element.h
+++ b/chrome/browser/android/vr_shell/ui_elements/ui_element.h
@@ -10,6 +10,9 @@
#include <vector>
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "cc/animation/animation_observer.h"
+#include "cc/animation/transform_operations.h"
#include "chrome/browser/android/vr_shell/color_scheme.h"
#include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -20,11 +23,14 @@
namespace base {
class TimeTicks;
-}
+} // namespace base
+
+namespace cc {
+class AnimationPlayer;
+} // namespace cc
namespace vr_shell {
-class Animation;
class UiElementRenderer;
enum XAnchoring {
@@ -54,39 +60,10 @@ enum Fill {
SELF = 4,
};
-class WorldRectangle {
+class UiElement : public cc::AnimationObserver {
public:
- const gfx::Transform& transform() const { return transform_; }
- void set_transform(const gfx::Transform& transform) {
- transform_ = transform;
- }
-
- gfx::Point3F GetCenter() const;
- gfx::Vector3dF GetNormal() const;
-
- // Computes the distance from |ray_origin| to this rectangles's plane, along
- // |ray_vector|. Returns true and populates |distance| if the calculation is
- // possible, and false if the ray is parallel to the plane.
- bool GetRayDistance(const gfx::Point3F& ray_origin,
- const gfx::Vector3dF& ray_vector,
- float* distance) const;
-
- // Projects a 3D world point onto the X and Y axes of the transformed
- // rectangle, returning 2D coordinates relative to the un-transformed unit
- // rectangle. This allows beam intersection points to be mapped to sprite
- // pixel coordinates. Points that fall onto the rectangle will generate X and
- // Y values on the interval [-0.5, 0.5].
- gfx::PointF GetUnitRectangleCoordinates(
- const gfx::Point3F& world_point) const;
-
- private:
- gfx::Transform transform_;
-};
-
-class UiElement : public WorldRectangle {
- public:
- UiElement();
- virtual ~UiElement();
+ explicit UiElement(int id);
+ ~UiElement() override;
virtual void OnBeginFrame(const base::TimeTicks& begin_frame_time);
@@ -119,7 +96,6 @@ class UiElement : public WorldRectangle {
virtual bool HitTest(const gfx::PointF& point) const;
int id() const { return id_; }
- void set_id(int id) { id_ = id; }
// If a non-negative parent ID is specified, applicable transformations
// are applied relative to the parent, rather than absolutely.
@@ -153,19 +129,13 @@ class UiElement : public WorldRectangle {
gfx::Vector3dF size() const { return size_; }
void set_size(const gfx::Vector3dF& size) { size_ = size; }
- // The scale of the object, and its children.
- gfx::Vector3dF scale() const { return scale_; }
- void set_scale(const gfx::Vector3dF& scale) { scale_ = scale; }
-
- // The rotation of the object, and its children.
- gfx::Quaternion rotation() const { return rotation_; }
- void set_rotation(const gfx::Quaternion& rotation) { rotation_ = rotation; }
+ // This is the local transform. It is inherited by descendants.
+ const cc::TransformOperations& transform_operations() const {
+ return transform_operations_;
+ }
- // The translation of the object, and its children. Translation is applied
- // after rotation and scaling.
- gfx::Vector3dF translation() const { return translation_; }
- void set_translation(const gfx::Vector3dF& translation) {
- translation_ = translation;
+ void set_transform_operations(const cc::TransformOperations& operations) {
+ transform_operations_ = operations;
}
// The opacity of the object (between 0.0 and 1.0).
@@ -188,10 +158,7 @@ class UiElement : public WorldRectangle {
void set_y_anchoring(YAnchoring y_anchoring) { y_anchoring_ = y_anchoring; }
// Animations that affect the properties of the object over time.
- std::vector<std::unique_ptr<Animation>>& animations() { return animations_; }
- const std::vector<std::unique_ptr<Animation>>& animations() const {
- return animations_;
- }
+ cc::AnimationPlayer& animation_player() { return *animation_player_; }
Fill fill() const { return fill_; }
void set_fill(Fill fill) { fill_ = fill; }
@@ -238,10 +205,48 @@ class UiElement : public WorldRectangle {
void SetMode(ColorScheme::Mode mode);
ColorScheme::Mode mode() const { return mode_; }
+ const gfx::Transform& screen_space_transform() const {
+ return screen_space_transform_;
+ }
+ void set_screen_space_transform(const gfx::Transform& transform) {
+ screen_space_transform_ = transform;
+ }
+
+ gfx::Point3F GetCenter() const;
+ gfx::Vector3dF GetNormal() const;
+
+ // Computes the distance from |ray_origin| to this rectangles's plane, along
+ // |ray_vector|. Returns true and populates |distance| if the calculation is
+ // possible, and false if the ray is parallel to the plane.
+ bool GetRayDistance(const gfx::Point3F& ray_origin,
+ const gfx::Vector3dF& ray_vector,
+ float* distance) const;
+
+ // Projects a 3D world point onto the X and Y axes of the transformed
+ // rectangle, returning 2D coordinates relative to the un-transformed unit
+ // rectangle. This allows beam intersection points to be mapped to sprite
+ // pixel coordinates. Points that fall onto the rectangle will generate X and
+ // Y values on the interval [-0.5, 0.5].
+ gfx::PointF GetUnitRectangleCoordinates(
+ const gfx::Point3F& world_point) const;
+
protected:
virtual void OnSetMode();
private:
+ // cc::AnimationObserver
+ void NotifyClientOpacityAnimated(float opacity,
+ bool notify_active_elements,
+ bool notify_pending_elements) override;
+ void NotifyClientTransformOperationsAnimated(
+ const cc::TransformOperations& operations,
+ bool notify_active_elements,
+ bool notify_pending_elements) override;
+
+ void NotifyClientBoundsAnimated(const gfx::SizeF& size,
+ bool notify_active_elements,
+ bool notify_pending_elements) override;
+
// Valid IDs are non-negative.
int id_ = -1;
@@ -269,16 +274,6 @@ class UiElement : public WorldRectangle {
// The size of the object. This does not affect children.
gfx::Vector3dF size_ = {1.0f, 1.0f, 1.0f};
- // The scale of the object, and its children.
- gfx::Vector3dF scale_ = {1.0f, 1.0f, 1.0f};
-
- // The rotation of the object, and its children.
- gfx::Quaternion rotation_;
-
- // The translation of the object, and its children. Translation is applied
- // after rotation and scaling.
- gfx::Vector3dF translation_ = {0.0f, 0.0f, 0.0f};
-
// The opacity of the object (between 0.0 and 1.0).
float opacity_ = 1.0f;
@@ -291,8 +286,7 @@ class UiElement : public WorldRectangle {
XAnchoring x_anchoring_ = XAnchoring::XNONE;
YAnchoring y_anchoring_ = YAnchoring::YNONE;
- // Animations that affect the properties of the object over time.
- std::vector<std::unique_ptr<Animation>> animations_;
+ scoped_refptr<cc::AnimationPlayer> animation_player_;
Fill fill_ = Fill::NONE;
@@ -304,6 +298,16 @@ class UiElement : public WorldRectangle {
int draw_phase_ = 1;
+ // This local transform operations. They are inherited by descendants and are
+ // stored as a list of operations rather than a baked transform to make
+ // transitions easier to implement (you may, for example, want to animate just
+ // the translation, but leave the rotation and scale in tact).
+ cc::TransformOperations transform_operations_;
+
+ // This is the combined, local to screen transform. It includes
+ // |inheritable_transform_|, |transform_|, and anchoring adjustments.
+ gfx::Transform screen_space_transform_;
+
// This transform can be used by children to derive position of its parent.
gfx::Transform inheritable_transform_;
@@ -313,8 +317,6 @@ class UiElement : public WorldRectangle {
// An identifier used for testing and debugging, in lieu of a string.
UiElementDebugId debug_id_ = UiElementDebugId::kNone;
- gfx::Transform transform_;
-
ColorScheme::Mode mode_ = ColorScheme::kModeNormal;
DISALLOW_COPY_AND_ASSIGN(UiElement);

Powered by Google App Engine
This is Rietveld 408576698