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

Side by Side Diff: cc/surfaces/surface_factory.h

Issue 2676373004: Implement service-side surface synchronization (Closed)
Patch Set: Better unit test name Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 CC_SURFACES_SURFACE_FACTORY_H_ 5 #ifndef CC_SURFACES_SURFACE_FACTORY_H_
6 #define CC_SURFACES_SURFACE_FACTORY_H_ 6 #define CC_SURFACES_SURFACE_FACTORY_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "cc/output/compositor_frame.h" 15 #include "cc/output/compositor_frame.h"
16 #include "cc/surfaces/pending_frame_observer.h"
16 #include "cc/surfaces/surface_id.h" 17 #include "cc/surfaces/surface_id.h"
17 #include "cc/surfaces/surface_resource_holder.h" 18 #include "cc/surfaces/surface_resource_holder.h"
18 #include "cc/surfaces/surface_sequence.h" 19 #include "cc/surfaces/surface_sequence.h"
19 #include "cc/surfaces/surfaces_export.h" 20 #include "cc/surfaces/surfaces_export.h"
20 21
21 namespace cc { 22 namespace cc {
22 class CopyOutputRequest; 23 class CopyOutputRequest;
23 class Surface; 24 class Surface;
24 class SurfaceFactoryClient; 25 class SurfaceFactoryClient;
25 class SurfaceManager; 26 class SurfaceManager;
26 27
27 // This class is used for creating surfaces and submitting compositor frames to 28 // This class is used for creating surfaces and submitting compositor frames to
28 // them. Surfaces are created lazily each time SubmitCompositorFrame is 29 // them. Surfaces are created lazily each time SubmitCompositorFrame is
29 // called with a local frame id that is different from the last call. Only one 30 // called with a local frame id that is different from the last call. Only one
30 // surface is owned by this class at a time, and upon constructing a new surface 31 // surface is owned by this class at a time, and upon constructing a new surface
31 // the old one will be destructed. Resources submitted to surfaces created by a 32 // the old one will be destructed. Resources submitted to surfaces created by a
32 // particular factory will be returned to that factory's client when they are no 33 // particular factory will be returned to that factory's client when they are no
33 // longer being used. This is the only class most users of surfaces will need to 34 // longer being used. This is the only class most users of surfaces will need to
34 // directly interact with. 35 // directly interact with.
35 class CC_SURFACES_EXPORT SurfaceFactory { 36 class CC_SURFACES_EXPORT SurfaceFactory : public PendingFrameObserver {
36 public: 37 public:
37 using DrawCallback = base::Callback<void()>; 38 using DrawCallback = base::Callback<void()>;
38 39
39 SurfaceFactory(const FrameSinkId& frame_sink_id, 40 SurfaceFactory(const FrameSinkId& frame_sink_id,
40 SurfaceManager* manager, 41 SurfaceManager* manager,
41 SurfaceFactoryClient* client); 42 SurfaceFactoryClient* client);
42 ~SurfaceFactory(); 43 ~SurfaceFactory() override;
43 44
44 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } 45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
45 46
46 // Destroys the current surface. You need to call this method before the 47 // Destroys the current surface. You need to call this method before the
47 // factory is destroyed, or when you would like to get rid of the surface as 48 // factory is destroyed, or when you would like to get rid of the surface as
48 // soon as possible (otherwise, the next time you call SubmitCompositorFrame 49 // soon as possible (otherwise, the next time you call SubmitCompositorFrame
49 // the old surface will be dealt with). 50 // the old surface will be dealt with).
50 void EvictSurface(); 51 void EvictSurface();
51 52
52 // Destroys and disowns the current surface, and resets all resource 53 // Destroys and disowns the current surface, and resets all resource
(...skipping 18 matching lines...) Expand all
71 void WillDrawSurface(const LocalSurfaceId& id, const gfx::Rect& damage_rect); 72 void WillDrawSurface(const LocalSurfaceId& id, const gfx::Rect& damage_rect);
72 73
73 SurfaceFactoryClient* client() { return client_; } 74 SurfaceFactoryClient* client() { return client_; }
74 75
75 void ReceiveFromChild(const TransferableResourceArray& resources); 76 void ReceiveFromChild(const TransferableResourceArray& resources);
76 void RefResources(const TransferableResourceArray& resources); 77 void RefResources(const TransferableResourceArray& resources);
77 void UnrefResources(const ReturnedResourceArray& resources); 78 void UnrefResources(const ReturnedResourceArray& resources);
78 79
79 SurfaceManager* manager() { return manager_; } 80 SurfaceManager* manager() { return manager_; }
80 81
82 Surface* current_surface_for_testing() { return current_surface_.get(); }
83
81 // This can be set to false if resources from this SurfaceFactory don't need 84 // This can be set to false if resources from this SurfaceFactory don't need
82 // to have sync points set on them when returned from the Display, for 85 // to have sync points set on them when returned from the Display, for
83 // example if the Display shares a context with the creator. 86 // example if the Display shares a context with the creator.
84 bool needs_sync_points() const { return needs_sync_points_; } 87 bool needs_sync_points() const { return needs_sync_points_; }
85 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } 88 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; }
86 89
87 // SurfaceFactory's owner can call this when it finds out that SurfaceManager 90 // SurfaceFactory's owner can call this when it finds out that SurfaceManager
88 // is no longer alive during destruction. 91 // is no longer alive during destruction.
89 void DidDestroySurfaceManager() { manager_ = nullptr; } 92 void DidDestroySurfaceManager() { manager_ = nullptr; }
90 93
91 private: 94 private:
95 // PendingFrameObserver implementation.
96 void OnSurfaceActivated(Surface* pending_surface) override;
97 void OnSurfaceDependenciesChanged(
98 Surface* pending_surface,
99 const SurfaceDependencies& added_dependencies,
100 const SurfaceDependencies& removed_dependencies) override;
101 void OnSurfaceDiscarded(Surface* pending_surface) override;
102
92 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id); 103 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id);
93 void Destroy(std::unique_ptr<Surface> surface); 104 void Destroy(std::unique_ptr<Surface> surface);
94 105
95 const FrameSinkId frame_sink_id_; 106 const FrameSinkId frame_sink_id_;
96 SurfaceManager* manager_; 107 SurfaceManager* manager_;
97 SurfaceFactoryClient* client_; 108 SurfaceFactoryClient* client_;
98 SurfaceResourceHolder holder_; 109 SurfaceResourceHolder holder_;
99 bool needs_sync_points_; 110 bool needs_sync_points_;
100 std::unique_ptr<Surface> current_surface_; 111 std::unique_ptr<Surface> current_surface_;
101 base::WeakPtrFactory<SurfaceFactory> weak_factory_; 112 base::WeakPtrFactory<SurfaceFactory> weak_factory_;
102 113
103 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); 114 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory);
104 }; 115 };
105 116
106 } // namespace cc 117 } // namespace cc
107 118
108 #endif // CC_SURFACES_SURFACE_FACTORY_H_ 119 #endif // CC_SURFACES_SURFACE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698