1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/surfaces/surface_factory.h"
#include <utility>
#include "base/trace_event/trace_event.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/copy_output_request.h"
#include "cc/surfaces/surface.h"
#include "cc/surfaces/surface_factory_client.h"
#include "cc/surfaces/surface_manager.h"
#include "ui/gfx/geometry/size.h"
namespace cc {
SurfaceFactory::SurfaceFactory(SurfaceManager* manager,
SurfaceFactoryClient* client)
: manager_(manager),
client_(client),
holder_(client),
needs_sync_points_(true) {
}
SurfaceFactory::~SurfaceFactory() {
if (!surface_map_.empty()) {
LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
<< " entries in map on destruction.";
}
DestroyAll();
client_->SetBeginFrameSource(SurfaceId(), nullptr);
}
void SurfaceFactory::DestroyAll() {
for (auto& pair : surface_map_)
manager_->Destroy(std::move(pair.second));
surface_map_.clear();
}
void SurfaceFactory::Create(SurfaceId surface_id) {
scoped_ptr<Surface> surface(new Surface(surface_id, this));
manager_->RegisterSurface(surface.get());
DCHECK(!surface_map_.count(surface_id));
surface_map_[surface_id] = std::move(surface);
}
void SurfaceFactory::Destroy(SurfaceId surface_id) {
OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
DCHECK(it != surface_map_.end());
DCHECK(it->second->factory().get() == this);
scoped_ptr<Surface> surface(std::move(it->second));
surface_map_.erase(it);
manager_->Destroy(std::move(surface));
}
void SurfaceFactory::SetBeginFrameSource(SurfaceId surface_id,
BeginFrameSource* begin_frame_source) {
client_->SetBeginFrameSource(surface_id, begin_frame_source);
}
void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id,
scoped_ptr<CompositorFrame> frame,
const DrawCallback& callback) {
TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame");
OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
DCHECK(it != surface_map_.end());
DCHECK(it->second->factory().get() == this);
it->second->QueueFrame(std::move(frame), callback);
if (!manager_->SurfaceModified(surface_id)) {
TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD);
it->second->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED);
}
}
void SurfaceFactory::RequestCopyOfSurface(
SurfaceId surface_id,
scoped_ptr<CopyOutputRequest> copy_request) {
OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
if (it == surface_map_.end()) {
copy_request->SendEmptyResult();
return;
}
DCHECK(it->second->factory().get() == this);
it->second->RequestCopyOfOutput(std::move(copy_request));
manager_->SurfaceModified(surface_id);
}
void SurfaceFactory::WillDrawSurface(SurfaceId id,
const gfx::Rect& damage_rect) {
client_->WillDrawSurface(id, damage_rect);
}
void SurfaceFactory::ReceiveFromChild(
const TransferableResourceArray& resources) {
holder_.ReceiveFromChild(resources);
}
void SurfaceFactory::RefResources(const TransferableResourceArray& resources) {
holder_.RefResources(resources);
}
void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) {
holder_.UnrefResources(resources);
}
} // namespace cc
|