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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: up 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
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <unordered_map>
11 10
12 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 14 #include "base/observer_list.h"
16 #include "cc/output/compositor_frame.h" 15 #include "cc/output/compositor_frame.h"
17 #include "cc/surfaces/surface_id.h" 16 #include "cc/surfaces/surface_id.h"
18 #include "cc/surfaces/surface_resource_holder.h" 17 #include "cc/surfaces/surface_resource_holder.h"
19 #include "cc/surfaces/surface_sequence.h" 18 #include "cc/surfaces/surface_sequence.h"
20 #include "cc/surfaces/surfaces_export.h" 19 #include "cc/surfaces/surfaces_export.h"
21 20
22 namespace cc { 21 namespace cc {
23 class CopyOutputRequest; 22 class CopyOutputRequest;
24 class Surface; 23 class Surface;
25 class SurfaceFactoryClient; 24 class SurfaceFactoryClient;
26 class SurfaceManager; 25 class SurfaceManager;
27 26
28 // A SurfaceFactory is used to create surfaces that may share resources and 27 // This class is used for creating surfaces and submitting compositor frames to
29 // receive returned resources for frames submitted to those surfaces. Resources 28 // them. Surfaces are created lazily each time SubmitCompositorFrame is
30 // submitted to frames created by a particular factory will be returned to that 29 // called with a local frame id that is different from the last call. Only one
31 // factory's client when they are no longer being used. This is the only class 30 // surface is owned by this class at a time, and upon constructing a new surface
32 // most users of surfaces will need to directly interact with. 31 // 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 // longer being used. This is the only class most users of surfaces will need to
34 // directly interact with.
33 class CC_SURFACES_EXPORT SurfaceFactory { 35 class CC_SURFACES_EXPORT SurfaceFactory {
34 public: 36 public:
35 using DrawCallback = base::Callback<void()>; 37 using DrawCallback = base::Callback<void()>;
36 38
37 SurfaceFactory(const FrameSinkId& frame_sink_id, 39 SurfaceFactory(const FrameSinkId& frame_sink_id,
38 SurfaceManager* manager, 40 SurfaceManager* manager,
39 SurfaceFactoryClient* client); 41 SurfaceFactoryClient* client);
40 ~SurfaceFactory(); 42 ~SurfaceFactory();
41 43
42 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } 44 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
43 45
44 void Create(const LocalFrameId& local_frame_id); 46 // Destroys the current surface. You need to call this method before the
45 void Destroy(const LocalFrameId& local_frame_id); 47 // 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 // the old surface will be dealt with).
50 void EvictSurface();
46 51
47 // Destroys all surfaces. 52 // Destroys and disowns the current surface, and resets all resource
48 void DestroyAll(); 53 // references. This is useful when resources are invalid (e.g. lost context).
49
50 // Destroys and disown all surfaces, and reset all resource references. This
51 // is useful when resources are invalid (e.g. lost context).
52 void Reset(); 54 void Reset();
53 55
54 // Set that the current frame on new_id is to be treated as the successor to 56 // Submits the frame to the current surface being managed by the factory if
55 // the current frame on old_id for the purposes of calculating damage. 57 // the local frame ids match, or creates a new surface with the given local
56 void SetPreviousFrameSurface(const LocalFrameId& new_id, 58 // frame id, destroys the old one, and submits the frame to this new surface.
57 const LocalFrameId& old_id); 59 // The frame can contain references to any surface, regardless of which
58 60 // factory owns it. The callback is called the first time this frame is used
59 // A frame can only be submitted to a surface created by this factory, 61 // to draw, or if the frame is discarded.
60 // although the frame may reference surfaces created by other factories.
61 // The callback is called the first time this frame is used to draw, or if
62 // the frame is discarded.
63 void SubmitCompositorFrame(const LocalFrameId& local_frame_id, 62 void SubmitCompositorFrame(const LocalFrameId& local_frame_id,
64 CompositorFrame frame, 63 CompositorFrame frame,
65 const DrawCallback& callback); 64 const DrawCallback& callback);
66 void RequestCopyOfSurface(const LocalFrameId& local_frame_id, 65 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> copy_request);
67 std::unique_ptr<CopyOutputRequest> copy_request);
68 66
69 // Evicts the current frame on the surface. All the resources 67 // Evicts the current frame on the surface. All the resources
70 // will be released and Surface::HasFrame will return false. 68 // will be released and Surface::HasFrame will return false.
71 void ClearSurface(const LocalFrameId& local_frame_id); 69 void ClearSurface();
72 70
73 void WillDrawSurface(const LocalFrameId& id, const gfx::Rect& damage_rect); 71 void WillDrawSurface(const LocalFrameId& id, const gfx::Rect& damage_rect);
74 72
75 SurfaceFactoryClient* client() { return client_; } 73 SurfaceFactoryClient* client() { return client_; }
76 74
77 void ReceiveFromChild(const TransferableResourceArray& resources); 75 void ReceiveFromChild(const TransferableResourceArray& resources);
78 void RefResources(const TransferableResourceArray& resources); 76 void RefResources(const TransferableResourceArray& resources);
79 void UnrefResources(const ReturnedResourceArray& resources); 77 void UnrefResources(const ReturnedResourceArray& resources);
80 78
81 SurfaceManager* manager() { return manager_; } 79 SurfaceManager* manager() { return manager_; }
82 80
83 // This can be set to false if resources from this SurfaceFactory don't need 81 // This can be set to false if resources from this SurfaceFactory don't need
84 // to have sync points set on them when returned from the Display, for 82 // to have sync points set on them when returned from the Display, for
85 // example if the Display shares a context with the creator. 83 // example if the Display shares a context with the creator.
86 bool needs_sync_points() const { return needs_sync_points_; } 84 bool needs_sync_points() const { return needs_sync_points_; }
87 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } 85 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; }
88 86
89 // SurfaceFactory's owner can call this when it finds out that SurfaceManager 87 // SurfaceFactory's owner can call this when it finds out that SurfaceManager
90 // is no longer alive during destruction. 88 // is no longer alive during destruction.
91 void DidDestroySurfaceManager() { manager_ = nullptr; } 89 void DidDestroySurfaceManager() { manager_ = nullptr; }
92 90
93 private: 91 private:
94 FrameSinkId frame_sink_id_; 92 std::unique_ptr<Surface> Create(const LocalFrameId& local_frame_id);
93 void Destroy(std::unique_ptr<Surface> surface);
94
95 const FrameSinkId frame_sink_id_;
95 SurfaceManager* manager_; 96 SurfaceManager* manager_;
96 SurfaceFactoryClient* client_; 97 SurfaceFactoryClient* client_;
97 SurfaceResourceHolder holder_; 98 SurfaceResourceHolder holder_;
98
99 bool needs_sync_points_; 99 bool needs_sync_points_;
100 100 std::unique_ptr<Surface> current_surface_;
101 using OwningSurfaceMap = std::
102 unordered_map<LocalFrameId, std::unique_ptr<Surface>, LocalFrameIdHash>;
103 OwningSurfaceMap surface_map_;
104
105 base::WeakPtrFactory<SurfaceFactory> weak_factory_; 101 base::WeakPtrFactory<SurfaceFactory> weak_factory_;
106 102
107 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); 103 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory);
108 }; 104 };
109 105
110 } // namespace cc 106 } // namespace cc
111 107
112 #endif // CC_SURFACES_SURFACE_FACTORY_H_ 108 #endif // CC_SURFACES_SURFACE_FACTORY_H_
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698