| 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 SurfaceResourceHolderClient* resource_holder_client() { | |
| 71 return resource_holder_client_; | |
| 72 } | |
| 73 | |
| 74 void ReceiveFromChild(const TransferableResourceArray& resources); | |
| 75 void RefResources(const TransferableResourceArray& resources); | |
| 76 void UnrefResources(const ReturnedResourceArray& resources); | |
| 77 | |
| 78 SurfaceManager* manager() { return manager_; } | |
| 79 | |
| 80 Surface* current_surface_for_testing() { return current_surface_.get(); } | |
| 81 | |
| 82 // 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 | |
| 84 // example if the Display shares a context with the creator. | |
| 85 bool needs_sync_points() const { return needs_sync_points_; } | |
| 86 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } | |
| 87 | |
| 88 private: | |
| 89 // PendingFrameObserver implementation. | |
| 90 void OnSurfaceActivated(Surface* surface) override; | |
| 91 void OnSurfaceDependenciesChanged( | |
| 92 Surface* surface, | |
| 93 const base::flat_set<SurfaceId>& added_dependencies, | |
| 94 const base::flat_set<SurfaceId>& removed_dependencies) override; | |
| 95 void OnSurfaceDiscarded(Surface* surface) override; | |
| 96 | |
| 97 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id); | |
| 98 void Destroy(std::unique_ptr<Surface> surface); | |
| 99 | |
| 100 const FrameSinkId frame_sink_id_; | |
| 101 SurfaceManager* manager_; | |
| 102 SurfaceFactoryClient* client_; | |
| 103 SurfaceResourceHolderClient* resource_holder_client_; | |
| 104 SurfaceResourceHolder holder_; | |
| 105 bool needs_sync_points_; | |
| 106 bool seen_first_frame_activation_ = false; | |
| 107 std::unique_ptr<Surface> current_surface_; | |
| 108 base::WeakPtrFactory<SurfaceFactory> weak_factory_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); | |
| 111 }; | |
| 112 | |
| 113 } // namespace cc | |
| 114 | |
| 115 #endif // CC_SURFACES_SURFACE_FACTORY_H_ | |
| OLD | NEW |