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

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

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Rebase Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CC_SURFACES_SURFACE_FACTORY_H_
6 #define CC_SURFACES_SURFACE_FACTORY_H_
7
8 #include <memory>
9 #include <set>
10
11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "cc/output/compositor_frame.h"
16 #include "cc/surfaces/pending_frame_observer.h"
17 #include "cc/surfaces/surface_id.h"
18 #include "cc/surfaces/surface_resource_holder.h"
19 #include "cc/surfaces/surface_sequence.h"
20 #include "cc/surfaces/surfaces_export.h"
21
22 namespace cc {
23 class CopyOutputRequest;
24 class Surface;
25 class SurfaceFactoryClient;
26 class SurfaceManager;
27
28 // This class is used for creating surfaces and submitting compositor frames to
29 // them. Surfaces are created lazily each time SubmitCompositorFrame is
30 // called with a local frame id that is different from the last call. Only one
31 // surface is owned by this class at a time, and upon constructing a new surface
32 // the old one will be destructed. Resources submitted to surfaces created by a
33 // particular factory will be returned to that factory's client when they are no
34 // longer being used. This is the only class most users of surfaces will need to
35 // directly interact with.
36 class CC_SURFACES_EXPORT SurfaceFactory : public PendingFrameObserver {
37 public:
38 using DrawCallback = base::Callback<void()>;
39
40 SurfaceFactory(const FrameSinkId& frame_sink_id,
41 SurfaceManager* manager,
42 SurfaceFactoryClient* client);
43 ~SurfaceFactory() override;
44
45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
46
47 // Destroys the current surface. You need to call this method before the
48 // factory is destroyed, or when you would like to get rid of the surface as
49 // soon as possible (otherwise, the next time you call SubmitCompositorFrame
50 // the old surface will be dealt with).
51 void EvictSurface();
52
53 // Submits the frame to the current surface being managed by the factory if
54 // the local frame ids match, or creates a new surface with the given local
55 // frame id, destroys the old one, and submits the frame to this new surface.
56 // The frame can contain references to any surface, regardless of which
57 // factory owns it. The callback is called the first time this frame is used
58 // to draw, or if the frame is discarded.
59 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id,
60 CompositorFrame frame,
61 const DrawCallback& callback);
62 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> copy_request);
63
64 // Evicts the current frame on the surface. All the resources
65 // will be released and Surface::HasFrame will return false.
66 void ClearSurface();
67
68 void WillDrawSurface(const LocalSurfaceId& id, const gfx::Rect& damage_rect);
69
70 SurfaceFactoryClient* client() { return client_; }
71
72 void ReceiveFromChild(const TransferableResourceArray& resources);
73 void RefResources(const TransferableResourceArray& resources);
74 void UnrefResources(const ReturnedResourceArray& resources);
75
76 SurfaceManager* manager() { return manager_; }
77
78 Surface* current_surface_for_testing() { return current_surface_.get(); }
79
80 // This can be set to false if resources from this SurfaceFactory don't need
81 // to have sync points set on them when returned from the Display, for
82 // example if the Display shares a context with the creator.
83 bool needs_sync_points() const { return needs_sync_points_; }
84 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; }
85
86 private:
87 // PendingFrameObserver implementation.
88 void OnReferencedSurfacesChanged(
89 Surface* surface,
90 const std::vector<SurfaceId>* active_referenced_surfaces,
91 const std::vector<SurfaceId>* pending_referenced_surfaces) override;
92 void OnSurfaceActivated(Surface* surface) override;
93 void OnSurfaceDependenciesChanged(
94 Surface* surface,
95 const SurfaceDependencies& added_dependencies,
96 const SurfaceDependencies& removed_dependencies) override;
97 void OnSurfaceDiscarded(Surface* surface) override;
98
99 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id);
100 void Destroy(std::unique_ptr<Surface> surface);
101
102 const FrameSinkId frame_sink_id_;
103 SurfaceManager* manager_;
104 SurfaceFactoryClient* client_;
105 SurfaceResourceHolder holder_;
106 bool needs_sync_points_;
107 bool seen_first_frame_activation_ = false;
108 std::unique_ptr<Surface> current_surface_;
109 base::WeakPtrFactory<SurfaceFactory> weak_factory_;
110
111 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory);
112 };
113
114 } // namespace cc
115
116 #endif // CC_SURFACES_SURFACE_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698