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

Unified Diff: ui/compositor/compositor.h

Issue 2773433003: Fix CompositorResizeLock to do something. (Closed)
Patch Set: resizelock: observer-rebase Created 3 years, 9 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 | « ui/compositor/BUILD.gn ('k') | ui/compositor/compositor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/compositor.h
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
index 99e30e965a33334f4179a716654b0e675596682d..fe85a4e2e150cc040e2ab2437d21f1ccc194b240 100644
--- a/ui/compositor/compositor.h
+++ b/ui/compositor/compositor.h
@@ -24,6 +24,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/compositor/compositor_animation_observer.h"
#include "ui/compositor/compositor_export.h"
+#include "ui/compositor/compositor_lock.h"
#include "ui/compositor/compositor_observer.h"
#include "ui/compositor/layer_animator_collection.h"
#include "ui/gfx/color_space.h"
@@ -68,7 +69,7 @@ class Layer;
class Reflector;
class ScopedAnimationDurationScaleMode;
-const int kCompositorLockTimeoutMs = 67;
+constexpr int kCompositorLockTimeoutMs = 67;
class COMPOSITOR_EXPORT ContextFactoryObserver {
public:
@@ -167,32 +168,6 @@ class COMPOSITOR_EXPORT ContextFactory {
virtual void RemoveObserver(ContextFactoryObserver* observer) = 0;
};
-// This class represents a lock on the compositor, that can be used to prevent
-// commits to the compositor tree while we're waiting for an asynchronous
-// event. The typical use case is when waiting for a renderer to produce a frame
-// at the right size. The caller keeps a reference on this object, and drops the
-// reference once it desires to release the lock.
-// By default, the lock will be cancelled after a short timeout to ensure
-// responsiveness of the UI, so the compositor tree should be kept in a
-// "reasonable" state while the lock is held. If the compositor sets
-// locks to not time out, then the lock will remain in effect until destroyed.
-// Don't instantiate this class directly, use Compositor::GetCompositorLock.
-class COMPOSITOR_EXPORT CompositorLock
- : public base::RefCounted<CompositorLock>,
- public base::SupportsWeakPtr<CompositorLock> {
- private:
- friend class base::RefCounted<CompositorLock>;
- friend class Compositor;
-
- explicit CompositorLock(Compositor* compositor);
- ~CompositorLock();
-
- void CancelLock();
-
- Compositor* compositor_;
- DISALLOW_COPY_AND_ASSIGN(CompositorLock);
-};
-
// Compositor object to take care of GPU painting.
// A Browser compositor object is responsible for generating the final
// displayable form of pixels comprising a single widget's contents. It draws an
@@ -200,7 +175,8 @@ class COMPOSITOR_EXPORT CompositorLock
// view hierarchy.
class COMPOSITOR_EXPORT Compositor
: NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
- NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
+ NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient),
+ NON_EXPORTED_BASE(public CompositorLockDelegate) {
public:
Compositor(const cc::FrameSinkId& frame_sink_id,
ui::ContextFactory* context_factory,
@@ -325,16 +301,13 @@ class COMPOSITOR_EXPORT Compositor
void RemoveAnimationObserver(CompositorAnimationObserver* observer);
bool HasAnimationObserver(const CompositorAnimationObserver* observer) const;
- // Change the timeout behavior for all future locks that are created. Locks
- // should time out if there is an expectation that the compositor will be
- // responsive.
- void SetLocksWillTimeOut(bool locks_will_time_out) {
- locks_will_time_out_ = locks_will_time_out;
- }
-
// Creates a compositor lock. Returns NULL if it is not possible to lock at
- // this time (i.e. we're waiting to complete a previous unlock).
- scoped_refptr<CompositorLock> GetCompositorLock();
+ // this time (i.e. we're waiting to complete a previous unlock). If the
+ // timeout is null, then no timeout is used.
+ std::unique_ptr<CompositorLock> GetCompositorLock(
+ CompositorLockClient* client,
+ base::TimeDelta timeout =
+ base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
// Internal functions, called back by command-buffer contexts on swap buffer
// events.
@@ -374,7 +347,7 @@ class COMPOSITOR_EXPORT Compositor
void DidSubmitCompositorFrame() override;
void DidLoseCompositorFrameSink() override {}
- bool IsLocked() { return compositor_lock_ != NULL; }
+ bool IsLocked() { return !active_locks_.empty(); }
void SetOutputIsSecure(bool output_is_secure);
@@ -392,13 +365,12 @@ class COMPOSITOR_EXPORT Compositor
private:
friend class base::RefCounted<Compositor>;
- friend class CompositorLock;
- // Called by CompositorLock.
- void UnlockCompositor();
+ // CompositorLockDelegate implementation.
+ void RemoveCompositorLock(CompositorLock* lock) override;
- // Called to release any pending CompositorLock
- void CancelCompositorLock();
+ // Causes all active CompositorLocks to be timed out.
+ void TimeoutLocks();
gfx::Size size_;
@@ -406,22 +378,22 @@ class COMPOSITOR_EXPORT Compositor
ui::ContextFactoryPrivate* context_factory_private_;
// The root of the Layer tree drawn by this compositor.
- Layer* root_layer_;
+ Layer* root_layer_ = nullptr;
base::ObserverList<CompositorObserver, true> observer_list_;
base::ObserverList<CompositorAnimationObserver> animation_observer_list_;
- gfx::AcceleratedWidget widget_;
+ gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
// A sequence number of a current compositor frame for use with metrics.
- int activated_frame_count_;
+ int activated_frame_count_ = 0;
- // current VSYNC refresh rate per second.
- float refresh_rate_;
+ // Current vsync refresh rate per second.
+ float refresh_rate_ = 0.f;
// A map from child id to parent id.
std::unordered_set<cc::FrameSinkId, cc::FrameSinkIdHash> child_frame_sinks_;
- bool widget_valid_;
- bool compositor_frame_sink_requested_;
+ bool widget_valid_ = false;
+ bool compositor_frame_sink_requested_ = false;
const cc::FrameSinkId frame_sink_id_;
scoped_refptr<cc::Layer> root_web_layer_;
std::unique_ptr<cc::AnimationHost> animation_host_;
@@ -433,10 +405,9 @@ class COMPOSITOR_EXPORT Compositor
// The device scale factor of the monitor that this compositor is compositing
// layers on.
- float device_scale_factor_;
+ float device_scale_factor_ = 0.f;
- bool locks_will_time_out_;
- CompositorLock* compositor_lock_;
+ std::vector<CompositorLock*> active_locks_;
LayerAnimatorCollection layer_animator_collection_;
scoped_refptr<cc::AnimationTimeline> animation_timeline_;
@@ -446,6 +417,7 @@ class COMPOSITOR_EXPORT Compositor
gfx::ColorSpace blending_color_space_;
base::WeakPtrFactory<Compositor> weak_ptr_factory_;
+ base::WeakPtrFactory<Compositor> lock_timeout_weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Compositor);
};
« no previous file with comments | « ui/compositor/BUILD.gn ('k') | ui/compositor/compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698