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.
5 #ifndef CC_SURFACES_SURFACE_FACTORY_H_
6 #define CC_SURFACES_SURFACE_FACTORY_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "cc/surfaces/surface_id.h"
12 #include "cc/surfaces/surface_resource_holder.h"
13 #include "cc/surfaces/surfaces_export.h"
20 class CompositorFrame
;
22 class SurfaceFactoryClient
;
25 // A SurfaceFactory is used to create surfaces that may share resources and
26 // receive returned resources for frames submitted to those surfaces. Resources
27 // submitted to frames created by a particular factory will be returned to that
28 // factory's client when they are no longer being used. This is the only class
29 // most users of surfaces will need to directly interact with.
30 class CC_SURFACES_EXPORT SurfaceFactory
31 : public base::SupportsWeakPtr
<SurfaceFactory
> {
33 SurfaceFactory(SurfaceManager
* manager
, SurfaceFactoryClient
* client
);
36 void Create(SurfaceId surface_id
, const gfx::Size
& size
);
37 void Destroy(SurfaceId surface_id
);
38 // A frame can only be submitted to a surface created by this factory,
39 // although the frame may reference surfaces created by other factories.
40 void SubmitFrame(SurfaceId surface_id
, scoped_ptr
<CompositorFrame
> frame
);
42 SurfaceFactoryClient
* client() { return client_
; }
44 void ReceiveFromChild(const TransferableResourceArray
& resources
);
45 void RefResources(const TransferableResourceArray
& resources
);
46 void UnrefResources(const ReturnedResourceArray
& resources
);
49 SurfaceManager
* manager_
;
50 SurfaceFactoryClient
* client_
;
51 typedef base::ScopedPtrHashMap
<SurfaceId
, Surface
> OwningSurfaceMap
;
52 base::ScopedPtrHashMap
<SurfaceId
, Surface
> surface_map_
;
54 SurfaceResourceHolder holder_
;
56 DISALLOW_COPY_AND_ASSIGN(SurfaceFactory
);
61 #endif // CC_SURFACES_SURFACE_FACTORY_H_