From 3d1d72c397c947b7d3ac6390b2a0c2b3a859b094 Mon Sep 17 00:00:00 2001 From: vmpstr Date: Mon, 26 Jan 2015 10:27:40 -0800 Subject: [PATCH] cc: Add frame timing request plumbing through the layers. This patch adds frame timing request class, which contains a rect and an id for that rect. Furthermore, it adds plumbing so that the requests get propagated from the original Layer into both pending and active LayerImpls. Verified using tracing that the requests appear correctly. R=danakj, michaelblain@chromium.org BUG=441555 Review URL: https://codereview.chromium.org/834343004 Cr-Commit-Position: refs/heads/master@{#313093} --- cc/BUILD.gn | 2 ++ cc/cc.gyp | 2 ++ cc/debug/frame_timing_request.cc | 17 +++++++++++++++++ cc/debug/frame_timing_request.h | 31 +++++++++++++++++++++++++++++++ cc/layers/layer.cc | 15 ++++++++++++++- cc/layers/layer.h | 9 +++++++++ cc/layers/layer_impl.cc | 26 +++++++++++++++++++++++++- cc/layers/layer_impl.h | 12 ++++++++++++ 8 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 cc/debug/frame_timing_request.cc create mode 100644 cc/debug/frame_timing_request.h diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 4b3f7837ebdb..a5945fb3f493 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -80,6 +80,8 @@ component("cc") { "debug/devtools_instrumentation.h", "debug/frame_rate_counter.cc", "debug/frame_rate_counter.h", + "debug/frame_timing_request.cc", + "debug/frame_timing_request.h", "debug/frame_timing_tracker.cc", "debug/frame_timing_tracker.h", "debug/frame_viewer_instrumentation.cc", diff --git a/cc/cc.gyp b/cc/cc.gyp index 4ee390085fa3..49d2f64de6d0 100644 --- a/cc/cc.gyp +++ b/cc/cc.gyp @@ -106,6 +106,8 @@ 'debug/devtools_instrumentation.h', 'debug/frame_rate_counter.cc', 'debug/frame_rate_counter.h', + 'debug/frame_timing_request.cc', + 'debug/frame_timing_request.h', 'debug/frame_timing_tracker.cc', 'debug/frame_timing_tracker.h', 'debug/frame_viewer_instrumentation.cc', diff --git a/cc/debug/frame_timing_request.cc b/cc/debug/frame_timing_request.cc new file mode 100644 index 000000000000..6c54ea2817a8 --- /dev/null +++ b/cc/debug/frame_timing_request.cc @@ -0,0 +1,17 @@ +// 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. + +#include "cc/debug/frame_timing_request.h" + +namespace cc { + +FrameTimingRequest::FrameTimingRequest() : id_(0) { +} + +FrameTimingRequest::FrameTimingRequest(int64_t request_id, + const gfx::Rect& rect) + : id_(request_id), rect_(rect) { +} + +} // namespace cc diff --git a/cc/debug/frame_timing_request.h b/cc/debug/frame_timing_request.h new file mode 100644 index 000000000000..7ab97def0ab4 --- /dev/null +++ b/cc/debug/frame_timing_request.h @@ -0,0 +1,31 @@ +// 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 CC_DEBUG_FRAME_TIMING_REQUEST_H_ +#define CC_DEBUG_FRAME_TIMING_REQUEST_H_ + +#include "ui/gfx/geometry/rect.h" + +namespace cc { + +// This class represents a request to record frame timing information about the +// given rect (in layer space) and an associated request id. When this request +// is propagated to the active LayerImpl, it will cause events to be saved in +// FrameTimingTracker, which in turn can be consumed by the requester. +class FrameTimingRequest { + public: + FrameTimingRequest(); + FrameTimingRequest(int64_t request_id, const gfx::Rect& rect); + + int64_t id() const { return id_; } + const gfx::Rect& rect() const { return rect_; } + + private: + int64_t id_; + gfx::Rect rect_; +}; + +} // namespace cc + +#endif // CC_DEBUG_FRAME_TIMING_REQUEST_H_ diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc index 45e8a83bffd7..feb23fa8d84f 100644 --- a/cc/layers/layer.cc +++ b/cc/layers/layer.cc @@ -78,7 +78,8 @@ Layer::Layer() clip_parent_(nullptr), replica_layer_(nullptr), raster_scale_(0.f), - client_(nullptr) { + client_(nullptr), + frame_timing_requests_dirty_(false) { layer_animation_controller_ = LayerAnimationController::Create(layer_id_); layer_animation_controller_->AddValueObserver(this); layer_animation_controller_->set_value_provider(this); @@ -1013,6 +1014,11 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { layer_animation_controller_->PushAnimationUpdatesTo( layer->layer_animation_controller()); + if (frame_timing_requests_dirty_) { + layer->PassFrameTimingRequests(&frame_timing_requests_); + frame_timing_requests_dirty_ = false; + } + // Reset any state that should be cleared for the next update. stacking_order_changed_ = false; update_rect_ = gfx::Rect(); @@ -1287,4 +1293,11 @@ gfx::Transform Layer::draw_transform_from_property_trees( return xform; } +void Layer::SetFrameTimingRequests( + const std::vector& requests) { + frame_timing_requests_ = requests; + frame_timing_requests_dirty_ = true; + SetNeedsCommit(); +} + } // namespace cc diff --git a/cc/layers/layer.h b/cc/layers/layer.h index 017df6842995..e4344127c764 100644 --- a/cc/layers/layer.h +++ b/cc/layers/layer.h @@ -7,6 +7,7 @@ #include #include +#include #include "base/callback.h" #include "base/memory/ref_counted.h" @@ -17,6 +18,7 @@ #include "cc/base/cc_export.h" #include "cc/base/region.h" #include "cc/base/scoped_ptr_vector.h" +#include "cc/debug/frame_timing_request.h" #include "cc/debug/micro_benchmark.h" #include "cc/layers/draw_properties.h" #include "cc/layers/layer_lists.h" @@ -505,6 +507,9 @@ class CC_EXPORT Layer : public base::RefCounted, return has_render_surface_; } + // Sets new frame timing requests for this layer. + void SetFrameTimingRequests(const std::vector& requests); + protected: friend class LayerImpl; friend class TreeSynchronizer; @@ -697,6 +702,10 @@ class CC_EXPORT Layer : public base::RefCounted, scoped_ptr render_surface_; gfx::Rect visible_rect_from_property_trees_; + + std::vector frame_timing_requests_; + bool frame_timing_requests_dirty_; + DISALLOW_COPY_AND_ASSIGN(Layer); }; diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc index 5bef67d23c99..d099a63321f5 100644 --- a/cc/layers/layer_impl.cc +++ b/cc/layers/layer_impl.cc @@ -70,7 +70,8 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) needs_push_properties_(false), num_dependents_need_push_properties_(0), sorting_context_id_(0), - current_draw_mode_(DRAW_MODE_NONE) { + current_draw_mode_(DRAW_MODE_NONE), + frame_timing_requests_dirty_(false) { DCHECK_GT(layer_id_, 0); DCHECK(layer_tree_impl_); layer_tree_impl_->RegisterLayer(this); @@ -607,6 +608,11 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->SetStackingOrderChanged(stacking_order_changed_); layer->SetDebugInfo(debug_info_); + if (frame_timing_requests_dirty_) { + layer->PassFrameTimingRequests(&frame_timing_requests_); + frame_timing_requests_dirty_ = false; + } + // Reset any state that should be cleared for the next update. stacking_order_changed_ = false; update_rect_ = gfx::Rect(); @@ -1024,6 +1030,13 @@ void LayerImpl::Set3dSortingContextId(int id) { NoteLayerPropertyChangedForSubtree(); } +void LayerImpl::PassFrameTimingRequests( + std::vector* requests) { + frame_timing_requests_.swap(*requests); + frame_timing_requests_dirty_ = true; + SetNeedsPushProperties(); +} + void LayerImpl::SetTransform(const gfx::Transform& transform) { if (transform_ == transform) return; @@ -1552,6 +1565,17 @@ void LayerImpl::AsValueInto(base::debug::TracedValue* state) const { NOTREACHED(); } } + + if (!frame_timing_requests_.empty()) { + state->BeginArray("frame_timing_requests"); + for (const auto& request : frame_timing_requests_) { + state->BeginDictionary(); + state->SetInteger("request_id", request.id()); + MathUtil::AddToTracedValue("request_rect", request.rect(), state); + state->EndDictionary(); + } + state->EndArray(); + } } bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const { diff --git a/cc/layers/layer_impl.h b/cc/layers/layer_impl.h index d1cf0530586d..f52b5de77ce2 100644 --- a/cc/layers/layer_impl.h +++ b/cc/layers/layer_impl.h @@ -7,6 +7,7 @@ #include #include +#include #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -18,6 +19,7 @@ #include "cc/base/cc_export.h" #include "cc/base/region.h" #include "cc/base/scoped_ptr_vector.h" +#include "cc/debug/frame_timing_request.h" #include "cc/input/input_handler.h" #include "cc/input/scrollbar.h" #include "cc/layers/draw_properties.h" @@ -566,6 +568,12 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, void Set3dSortingContextId(int id); int sorting_context_id() { return sorting_context_id_; } + void PassFrameTimingRequests( + std::vector* frame_timing_requests); + const std::vector& frame_timing_requests() const { + return frame_timing_requests_; + } + protected: LayerImpl(LayerTreeImpl* layer_impl, int id); @@ -720,6 +728,10 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver, scoped_refptr debug_info_; scoped_ptr render_surface_; + + std::vector frame_timing_requests_; + bool frame_timing_requests_dirty_; + DISALLOW_COPY_AND_ASSIGN(LayerImpl); }; -- 2.11.4.GIT