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 "base/trace_event/trace_event.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/output/copy_output_request.h"
10 #include "cc/surfaces/surface.h"
11 #include "cc/surfaces/surface_manager.h"
12 #include "ui/gfx/geometry/size.h"
15 SurfaceFactory::SurfaceFactory(SurfaceManager
* manager
,
16 SurfaceFactoryClient
* client
)
20 needs_sync_points_(true) {
23 SurfaceFactory::~SurfaceFactory() {
24 if (!surface_map_
.empty()) {
25 LOG(ERROR
) << "SurfaceFactory has " << surface_map_
.size()
26 << " entries in map on destruction.";
31 void SurfaceFactory::DestroyAll() {
32 for (auto it
= surface_map_
.begin(); it
!= surface_map_
.end(); ++it
)
33 manager_
->Destroy(surface_map_
.take(it
));
37 void SurfaceFactory::Create(SurfaceId surface_id
) {
38 scoped_ptr
<Surface
> surface(new Surface(surface_id
, this));
39 manager_
->RegisterSurface(surface
.get());
40 DCHECK(!surface_map_
.count(surface_id
));
41 surface_map_
.add(surface_id
, surface
.Pass());
44 void SurfaceFactory::Destroy(SurfaceId surface_id
) {
45 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
46 DCHECK(it
!= surface_map_
.end());
47 DCHECK(it
->second
->factory().get() == this);
48 manager_
->Destroy(surface_map_
.take_and_erase(it
));
51 void SurfaceFactory::SubmitFrame(SurfaceId surface_id
,
52 scoped_ptr
<CompositorFrame
> frame
,
53 const DrawCallback
& callback
) {
54 TRACE_EVENT0("cc", "SurfaceFactory::SubmitFrame");
55 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
56 DCHECK(it
!= surface_map_
.end());
57 DCHECK(it
->second
->factory().get() == this);
58 it
->second
->QueueFrame(frame
.Pass(), callback
);
59 if (!manager_
->SurfaceModified(surface_id
)) {
60 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD
);
61 it
->second
->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED
);
65 void SurfaceFactory::RequestCopyOfSurface(
67 scoped_ptr
<CopyOutputRequest
> copy_request
) {
68 OwningSurfaceMap::iterator it
= surface_map_
.find(surface_id
);
69 if (it
== surface_map_
.end()) {
70 copy_request
->SendEmptyResult();
73 DCHECK(it
->second
->factory().get() == this);
74 it
->second
->RequestCopyOfOutput(copy_request
.Pass());
75 manager_
->SurfaceModified(surface_id
);
78 void SurfaceFactory::ReceiveFromChild(
79 const TransferableResourceArray
& resources
) {
80 holder_
.ReceiveFromChild(resources
);
83 void SurfaceFactory::RefResources(const TransferableResourceArray
& resources
) {
84 holder_
.RefResources(resources
);
87 void SurfaceFactory::UnrefResources(const ReturnedResourceArray
& resources
) {
88 holder_
.UnrefResources(resources
);