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

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

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