| OLD | NEW |
| 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 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
| 16 #include "cc/surfaces/pending_frame_observer.h" | 16 #include "cc/surfaces/pending_frame_observer.h" |
| 17 #include "cc/surfaces/surface_id.h" | 17 #include "cc/surfaces/surface_id.h" |
| 18 #include "cc/surfaces/surface_resource_holder.h" | 18 #include "cc/surfaces/surface_resource_holder.h" |
| 19 #include "cc/surfaces/surface_sequence.h" | 19 #include "cc/surfaces/surface_sequence.h" |
| 20 #include "cc/surfaces/surfaces_export.h" | 20 #include "cc/surfaces/surfaces_export.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 class CopyOutputRequest; | 23 class CopyOutputRequest; |
| 24 class Surface; | 24 class Surface; |
| 25 class SurfaceFactoryClient; | 25 class SurfaceFactoryClient; |
| 26 class SurfaceManager; | 26 class SurfaceManager; |
| 27 class SurfaceAggregatorClient; |
| 27 | 28 |
| 28 // This class is used for creating surfaces and submitting compositor frames to | 29 // This class is used for creating surfaces and submitting compositor frames to |
| 29 // them. Surfaces are created lazily each time SubmitCompositorFrame is | 30 // 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 // 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 // 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 // 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 // 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 // longer being used. This is the only class most users of surfaces will need to |
| 35 // directly interact with. | 36 // directly interact with. |
| 36 class CC_SURFACES_EXPORT SurfaceFactory : public PendingFrameObserver { | 37 class CC_SURFACES_EXPORT SurfaceFactory : public PendingFrameObserver { |
| 37 public: | 38 public: |
| 38 using DrawCallback = base::Callback<void()>; | 39 using DrawCallback = base::Callback<void()>; |
| 39 | 40 |
| 40 SurfaceFactory(const FrameSinkId& frame_sink_id, | 41 SurfaceFactory(const FrameSinkId& frame_sink_id, |
| 41 SurfaceManager* manager, | 42 SurfaceManager* manager, |
| 42 SurfaceFactoryClient* client); | 43 SurfaceFactoryClient* client, |
| 44 SurfaceAggregatorClient* surface_aggregator_client, |
| 45 SurfaceResourceHolderClient* resource_holder_client); |
| 43 ~SurfaceFactory() override; | 46 ~SurfaceFactory() override; |
| 44 | 47 |
| 45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 48 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
| 46 | 49 |
| 47 // Destroys the current surface. You need to call this method before the | 50 // 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 | 51 // 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 | 52 // soon as possible (otherwise, the next time you call SubmitCompositorFrame |
| 50 // the old surface will be dealt with). | 53 // the old surface will be dealt with). |
| 51 void EvictSurface(); | 54 void EvictSurface(); |
| 52 | 55 |
| 53 // Submits the frame to the current surface being managed by the factory if | 56 // 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 | 57 // 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. | 58 // 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 | 59 // 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 | 60 // factory owns it. The callback is called the first time this frame is used |
| 58 // to draw, or if the frame is discarded. | 61 // to draw, or if the frame is discarded. |
| 59 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, | 62 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, |
| 60 CompositorFrame frame, | 63 CompositorFrame frame, |
| 61 const DrawCallback& callback); | 64 const DrawCallback& callback); |
| 62 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> copy_request); | 65 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> copy_request); |
| 63 | 66 |
| 64 // Evicts the current frame on the surface. All the resources | 67 // Evicts the current frame on the surface. All the resources |
| 65 // will be released and Surface::HasFrame will return false. | 68 // will be released and Surface::HasFrame will return false. |
| 66 void ClearSurface(); | 69 void ClearSurface(); |
| 67 | 70 |
| 68 void WillDrawSurface(const LocalSurfaceId& id, const gfx::Rect& damage_rect); | |
| 69 | |
| 70 SurfaceFactoryClient* client() { return client_; } | 71 SurfaceFactoryClient* client() { return client_; } |
| 71 | 72 |
| 72 void ReceiveFromChild(const TransferableResourceArray& resources); | 73 void ReceiveFromChild(const TransferableResourceArray& resources); |
| 73 void RefResources(const TransferableResourceArray& resources); | 74 void RefResources(const TransferableResourceArray& resources); |
| 74 void UnrefResources(const ReturnedResourceArray& resources); | 75 void UnrefResources(const ReturnedResourceArray& resources); |
| 75 | 76 |
| 76 SurfaceManager* manager() { return manager_; } | 77 SurfaceManager* manager() { return manager_; } |
| 78 SurfaceAggregatorClient* surface_aggregator_client() { |
| 79 return surface_aggregator_client_; |
| 80 } |
| 77 | 81 |
| 78 Surface* current_surface_for_testing() { return current_surface_.get(); } | 82 Surface* current_surface_for_testing() { return current_surface_.get(); } |
| 79 | 83 |
| 80 // 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 |
| 81 // 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 |
| 82 // example if the Display shares a context with the creator. | 86 // example if the Display shares a context with the creator. |
| 83 bool needs_sync_points() const { return needs_sync_points_; } | 87 bool needs_sync_points() const { return needs_sync_points_; } |
| 84 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } | 88 void set_needs_sync_points(bool needs) { needs_sync_points_ = needs; } |
| 85 | 89 |
| 86 private: | 90 private: |
| 87 // PendingFrameObserver implementation. | 91 // PendingFrameObserver implementation. |
| 88 void OnSurfaceActivated(Surface* surface) override; | 92 void OnSurfaceActivated(Surface* surface) override; |
| 89 void OnSurfaceDependenciesChanged( | 93 void OnSurfaceDependenciesChanged( |
| 90 Surface* surface, | 94 Surface* surface, |
| 91 const SurfaceDependencies& added_dependencies, | 95 const SurfaceDependencies& added_dependencies, |
| 92 const SurfaceDependencies& removed_dependencies) override; | 96 const SurfaceDependencies& removed_dependencies) override; |
| 93 void OnSurfaceDiscarded(Surface* surface) override; | 97 void OnSurfaceDiscarded(Surface* surface) override; |
| 94 | 98 |
| 95 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id); | 99 std::unique_ptr<Surface> Create(const LocalSurfaceId& local_surface_id); |
| 96 void Destroy(std::unique_ptr<Surface> surface); | 100 void Destroy(std::unique_ptr<Surface> surface); |
| 97 | 101 |
| 98 const FrameSinkId frame_sink_id_; | 102 const FrameSinkId frame_sink_id_; |
| 99 SurfaceManager* manager_; | 103 SurfaceManager* manager_; |
| 100 SurfaceFactoryClient* client_; | 104 SurfaceFactoryClient* client_; |
| 105 SurfaceAggregatorClient* surface_aggregator_client_; |
| 101 SurfaceResourceHolder holder_; | 106 SurfaceResourceHolder holder_; |
| 102 bool needs_sync_points_; | 107 bool needs_sync_points_; |
| 103 bool seen_first_frame_activation_ = false; | 108 bool seen_first_frame_activation_ = false; |
| 104 std::unique_ptr<Surface> current_surface_; | 109 std::unique_ptr<Surface> current_surface_; |
| 105 base::WeakPtrFactory<SurfaceFactory> weak_factory_; | 110 base::WeakPtrFactory<SurfaceFactory> weak_factory_; |
| 106 | 111 |
| 107 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); | 112 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); |
| 108 }; | 113 }; |
| 109 | 114 |
| 110 } // namespace cc | 115 } // namespace cc |
| 111 | 116 |
| 112 #endif // CC_SURFACES_SURFACE_FACTORY_H_ | 117 #endif // CC_SURFACES_SURFACE_FACTORY_H_ |
| OLD | NEW |