James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 | |
James Robinson | 74f9f1f | 2014-11-04 11:17:49 -0800 | [diff] [blame] | 8 | #include <set> |
| 9 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
| 11 | #include "base/containers/scoped_ptr_hash_map.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "base/memory/weak_ptr.h" |
| 14 | #include "cc/surfaces/surface_id.h" |
| 15 | #include "cc/surfaces/surface_resource_holder.h" |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 16 | #include "cc/surfaces/surface_sequence.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 17 | #include "cc/surfaces/surfaces_export.h" |
| 18 | |
| 19 | namespace gfx { |
| 20 | class Size; |
| 21 | } |
| 22 | |
| 23 | namespace cc { |
| 24 | class CompositorFrame; |
| 25 | class CopyOutputRequest; |
| 26 | class Surface; |
| 27 | class SurfaceFactoryClient; |
| 28 | class SurfaceManager; |
| 29 | |
Elliot Glaysher | eae4929 | 2015-01-28 10:47:32 -0800 | [diff] [blame] | 30 | enum class SurfaceDrawStatus { DRAW_SKIPPED, DRAWN }; |
| 31 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 32 | // A SurfaceFactory is used to create surfaces that may share resources and |
| 33 | // receive returned resources for frames submitted to those surfaces. Resources |
| 34 | // submitted to frames created by a particular factory will be returned to that |
| 35 | // factory's client when they are no longer being used. This is the only class |
| 36 | // most users of surfaces will need to directly interact with. |
| 37 | class CC_SURFACES_EXPORT SurfaceFactory |
| 38 | : public base::SupportsWeakPtr<SurfaceFactory> { |
| 39 | public: |
Elliot Glaysher | eae4929 | 2015-01-28 10:47:32 -0800 | [diff] [blame] | 40 | using DrawCallback = base::Callback<void(SurfaceDrawStatus)>; |
Etienne Membrives | b1556b3 | 2014-12-16 13:56:09 +0100 | [diff] [blame] | 41 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 42 | SurfaceFactory(SurfaceManager* manager, SurfaceFactoryClient* client); |
| 43 | ~SurfaceFactory(); |
| 44 | |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame] | 45 | void Create(SurfaceId surface_id); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 46 | void Destroy(SurfaceId surface_id); |
James Robinson | 74f9f1f | 2014-11-04 11:17:49 -0800 | [diff] [blame] | 47 | void DestroyAll(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 48 | // A frame can only be submitted to a surface created by this factory, |
| 49 | // although the frame may reference surfaces created by other factories. |
Etienne Membrives | b1556b3 | 2014-12-16 13:56:09 +0100 | [diff] [blame] | 50 | // The callback is called the first time this frame is used to draw, or if |
| 51 | // the frame is discarded. |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 52 | void SubmitFrame(SurfaceId surface_id, |
| 53 | scoped_ptr<CompositorFrame> frame, |
Etienne Membrives | b1556b3 | 2014-12-16 13:56:09 +0100 | [diff] [blame] | 54 | const DrawCallback& callback); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 55 | void RequestCopyOfSurface(SurfaceId surface_id, |
| 56 | scoped_ptr<CopyOutputRequest> copy_request); |
| 57 | |
| 58 | SurfaceFactoryClient* client() { return client_; } |
| 59 | |
| 60 | void ReceiveFromChild(const TransferableResourceArray& resources); |
| 61 | void RefResources(const TransferableResourceArray& resources); |
| 62 | void UnrefResources(const ReturnedResourceArray& resources); |
| 63 | |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 64 | SurfaceManager* manager() { return manager_; } |
| 65 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 66 | private: |
| 67 | SurfaceManager* manager_; |
| 68 | SurfaceFactoryClient* client_; |
| 69 | SurfaceResourceHolder holder_; |
| 70 | |
James Robinson | f19b102 | 2015-05-05 18:12:15 -0700 | [diff] [blame] | 71 | typedef base::ScopedPtrHashMap<SurfaceId, scoped_ptr<Surface>> OwningSurfaceMap; |
| 72 | OwningSurfaceMap surface_map_; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(SurfaceFactory); |
| 75 | }; |
| 76 | |
| 77 | } // namespace cc |
| 78 | |
| 79 | #endif // CC_SURFACES_SURFACE_FACTORY_H_ |