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

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

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

Powered by Google App Engine
This is Rietveld 408576698