OLD | NEW |
| (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 using WillDrawCallback = | |
40 base::RepeatingCallback<void(const LocalSurfaceId&, const gfx::Rect&)>; | |
41 | |
42 SurfaceFactory(const FrameSinkId& frame_sink_id, | |
43 SurfaceManager* manager, | |
44 SurfaceFactoryClient* client, | |
45 SurfaceResourceHolderClient* resource_holder_client); | |
46 ~SurfaceFactory() override; | |
47 | |
48 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | |
49 | |
50 // Destroys the current surface. You need to call this method before the | |
51 // factory is destroyed, or when you would like to get rid of the surface as | |
52 // soon as possible (otherwise, the next time you call SubmitCompositorFrame | |
53 // the old surface will be dealt with). | |
54 void EvictSurface(); | |
55 | |
56 // Submits the frame to the current surface being managed by the factory if | |
57 // the local frame ids match, or creates a new surface with the given local | |
58 // frame id, destroys the old one, and submits the frame to this new surface. | |
59 // The frame can contain references to any surface, regardless of which | |
60 // factory owns it. The callback is called the first time this frame is used | |
61 // to draw, or if the frame is discarded. | |
62 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, | |
63 CompositorFrame frame, | |
64 const DrawCallback& callback, | |
65 const WillDrawCallback& will_draw_callback); | |
66 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> copy_request); | |
67 | |
68 SurfaceFactoryClient* client() { return client_; } | |
69 | |
70 void ReceiveFromChild(const TransferableResourceArray& resources); | |
71 void RefResources(const TransferableResourceArray& resources); | |
72 void UnrefResources(const ReturnedResourceArray& resources); | |
73 | |
74 SurfaceManager* manager() { return manager_; } | |
75 | |
76 Surface* current_surface_for_testing() { return current_surface_.get(); } | |
77 | |
78 // This can be set to false if resources from this SurfaceFactory don't need | |
79 // to have sync points set on them when returned from the Display, for | |
80 // example if the Display shares a context with the creator. | |
81 bool needs_sync_points() const { return needs_sync_points_; } | |
82 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } | |
83 | |
84 private: | |
85 // PendingFrameObserver implementation. | |
86 void OnSurfaceActivated(Surface* surface) override; | |
87 void OnSurfaceDependenciesChanged( | |
88 Surface* surface, | |
89 const SurfaceDependencies& added_dependencies, | |
90 const SurfaceDependencies& removed_dependencies) override; | |
91 void OnSurfaceDiscarded(Surface* surface) override; | |
92 | |
93 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id); | |
94 void Destroy(std::unique_ptr<Surface> surface); | |
95 | |
96 const FrameSinkId frame_sink_id_; | |
97 SurfaceManager* manager_; | |
98 SurfaceFactoryClient* client_; | |
99 SurfaceResourceHolder holder_; | |
100 bool needs_sync_points_; | |
101 bool seen_first_frame_activation_ = false; | |
102 std::unique_ptr<Surface> current_surface_; | |
103 base::WeakPtrFactory<SurfaceFactory> weak_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); | |
106 }; | |
107 | |
108 } // namespace cc | |
109 | |
110 #endif // CC_SURFACES_SURFACE_FACTORY_H_ | |
OLD | NEW |