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