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

Side by Side Diff: components/exo/compositor_frame_sink_holder.h

Issue 2493223002: Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink (Closed)
Patch Set: Replaced SatisfyCallback() and RequireCallback() with CompositorFrameSinkHolder::Satisfy() and Comp… Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_EXO_COMPOSITOR_FRAME_SINK_HOLDER_H_
6 #define COMPONENTS_EXO_COMPOSITOR_FRAME_SINK_HOLDER_H_
7
8 #include <list>
9 #include <map>
10 #include <memory>
11
12 #include "cc/ipc/mojo_compositor_frame_sink.mojom.h"
13 #include "cc/resources/single_release_callback.h"
14 #include "cc/resources/transferable_resource.h"
15 #include "cc/scheduler/begin_frame_source.h"
16 #include "components/exo/compositor_frame_sink.h"
17 #include "components/exo/surface_observer.h"
18 #include "mojo/public/cpp/bindings/binding.h"
19
20 namespace exo {
21 class Surface;
22
23 // This class talks to MojoCompositorFrameSink and keeps track of references to
24 // the contents of Buffers. It's keeped alive by references from
25 // release_callbacks_. It's destroyed when its owning Surface is destroyed and
26 // the last outstanding release callback is called.
27 class CompositorFrameSinkHolder
28 : public base::RefCounted<CompositorFrameSinkHolder>,
29 public cc::ExternalBeginFrameSourceClient,
30 public cc::mojom::MojoCompositorFrameSinkClient,
31 public cc::BeginFrameObserver,
32 public SurfaceObserver {
33 public:
34 CompositorFrameSinkHolder(
35 Surface* surface,
36 cc::mojom::MojoCompositorFrameSinkPtr mojo_compositor_frame_sink,
37 std::unique_ptr<CompositorFrameSink> frame_sink,
38 cc::mojom::MojoCompositorFrameSinkClientRequest request);
39
40 bool HasReleaseCallbackForResource(cc::ResourceId id);
41 void AddResourceReleaseCallback(
42 cc::ResourceId id,
43 std::unique_ptr<cc::SingleReleaseCallback> callback);
44
45 CompositorFrameSink* GetCompositorFrameSink() { return frame_sink_.get(); }
46
47 base::WeakPtr<CompositorFrameSinkHolder> GetWeakPtr() {
48 return weak_factory_.GetWeakPtr();
49 }
50
51 using FrameCallback = base::Callback<void(base::TimeTicks frame_time)>;
52 void ActivateFrameCallbacks(std::list<FrameCallback>* frame_callbacks);
53 void CancelFrameCallbacks();
54
55 void SetNeedsBeginFrame(bool needs_begin_frame);
56
57 void Satisfy(const cc::SurfaceSequence& sequence);
58 void Require(const cc::SurfaceId& id, const cc::SurfaceSequence& sequence);
59
60 // Overridden from cc::mojom::MojoCompositorFrameSinkClient:
61 void DidReceiveCompositorFrameAck() override;
62 void OnBeginFrame(const cc::BeginFrameArgs& args) override;
63 void ReclaimResources(const cc::ReturnedResourceArray& resources) override;
64 void WillDrawSurface() override;
65
66 // Overridden from cc::BeginFrameObserver:
67 const cc::BeginFrameArgs& LastUsedBeginFrameArgs() const override;
68 void OnBeginFrameSourcePausedChanged(bool paused) override;
69
70 // Overridden from cc::ExternalBeginFrameSouceClient:
71 void OnNeedsBeginFrames(bool needs_begin_frames) override;
72
73 // Overridden from SurfaceObserver:
74 void OnSurfaceDestroying(Surface* surface) override;
75
76 private:
77 friend class base::RefCounted<CompositorFrameSinkHolder>;
78
79 ~CompositorFrameSinkHolder() override;
80
81 void UpdateNeedsBeginFrame();
82
83 using ResourceReleaseCallbackMap =
84 std::map<int,
85 std::pair<scoped_refptr<CompositorFrameSinkHolder>,
86 std::unique_ptr<cc::SingleReleaseCallback>>>;
87 ResourceReleaseCallbackMap release_callbacks_;
88
89 Surface* surface_;
90 std::unique_ptr<CompositorFrameSink> frame_sink_;
91 cc::mojom::MojoCompositorFrameSinkPtr mojo_compositor_frame_sink_;
92
93 // Each FrameCallback holds a reference to the CompositorFrameSinkHolder
94 // itself to keep it alive. Running and erasing the callbacks might result in
95 // the instance being destroyed. Therefore, we should not access any member
96 // variables after running and erasing the callbacks.
97 std::list<FrameCallback> active_frame_callbacks_;
98 std::unique_ptr<cc::ExternalBeginFrameSource> begin_frame_source_;
99 bool needs_begin_frame_ = false;
100 cc::BeginFrameArgs last_begin_frame_args_;
101 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_;
102
103 base::WeakPtrFactory<CompositorFrameSinkHolder> weak_factory_;
104
105 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkHolder);
106 };
107
108 } // namespace exo
109
110 #endif // COMPONENTS_EXO_COMPOSITOR_FRAME_SINK_HOLDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698