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 #include "cc/surfaces/surface_factory.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/surfaces/surface.h"
10 #include "cc/surfaces/surface_manager.h"
11 #include "ui/gfx/geometry/size.h"
14 SurfaceFactory::SurfaceFactory(SurfaceManager
* manager
,
15 SurfaceFactoryClient
* client
)
19 needs_sync_points_(true) {
22 SurfaceFactory::~SurfaceFactory() {
23 if (!surface_map_
.empty()) {
24 LOG(ERROR
) << "SurfaceFactory has " << surface_map_
.size()
25 << " entries in map on destruction.";
30 void SurfaceFactory::DestroyAll() {
31 for (auto it
= surface_map_
.begin(); it
!= surface_map_
.end(); ++it
)
32 manager_
->Destroy(surface_map_
.take(it
));
36 void SurfaceFactory::Create(SurfaceId surface_id
) {
37 scoped_ptr
<Surface
> surface(new Surface(surface_id
, this));
38 manager_
->RegisterSurface(surface
.get());
39 DCHECK(!surface_map_
.count(surface_id
));
40 surface_map_
.add(surface_id
, surface
.Pass());
43 void SurfaceFactory::Destroy(SurfaceId surface_id
) {
44 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
45 DCHECK(it
!= surface_map_
.end());
46 DCHECK(it
->second
->factory().get() == this);
47 manager_
->Destroy(surface_map_
.take_and_erase(it
));
50 void SurfaceFactory::SubmitFrame(SurfaceId surface_id
,
51 scoped_ptr
<CompositorFrame
> frame
,
52 const DrawCallback
& callback
) {
53 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
54 DCHECK(it
!= surface_map_
.end());
55 DCHECK(it
->second
->factory().get() == this);
56 it
->second
->QueueFrame(frame
.Pass(), callback
);
57 if (!manager_
->SurfaceModified(surface_id
))
58 it
->second
->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED
);
61 void SurfaceFactory::RequestCopyOfSurface(
63 scoped_ptr
<CopyOutputRequest
> copy_request
) {
64 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
65 if (it
== surface_map_
.end()) {
66 copy_request
->SendEmptyResult();
69 DCHECK(it
->second
->factory().get() == this);
70 it
->second
->RequestCopyOfOutput(copy_request
.Pass());
71 manager_
->SurfaceModified(surface_id
);
74 void SurfaceFactory::ReceiveFromChild(
75 const TransferableResourceArray
& resources
) {
76 holder_
.ReceiveFromChild(resources
);
79 void SurfaceFactory::RefResources(const TransferableResourceArray
& resources
) {
80 holder_
.RefResources(resources
);
83 void SurfaceFactory::UnrefResources(const ReturnedResourceArray
& resources
) {
84 holder_
.UnrefResources(resources
);