Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: services/gfx/compositor/graph/scene_content.cc

Issue 1873573003: Mozart: Ensure time always runs forward. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-3
Patch Set: fix build error on Android Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/gfx/compositor/graph/scene_content.h" 5 #include "services/gfx/compositor/graph/scene_content.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "services/gfx/compositor/graph/scene_def.h" 10 #include "services/gfx/compositor/graph/scene_def.h"
11 11
12 namespace compositor { 12 namespace compositor {
13 13
14 SceneContent::SceneContent(const SceneLabel& label, 14 SceneContent::SceneContent(const SceneLabel& label,
15 uint32_t version, 15 uint32_t version,
16 int64_t presentation_time,
16 size_t max_resources, 17 size_t max_resources,
17 size_t max_nodes) 18 size_t max_nodes)
18 : label_(label), 19 : label_(label),
19 version_(version), 20 version_(version),
21 presentation_time_(presentation_time),
20 resources_(max_resources), 22 resources_(max_resources),
21 nodes_(max_nodes) {} 23 nodes_(max_nodes) {}
22 24
23 SceneContent::~SceneContent() {} 25 SceneContent::~SceneContent() {}
24 26
27 bool SceneContent::MatchesVersion(uint32_t requested_version) const {
28 return requested_version == mojo::gfx::composition::kSceneVersionNone ||
29 requested_version == version_ ||
30 version_ == mojo::gfx::composition::kSceneVersionNone;
31 }
32
25 void SceneContent::RecordPicture(const Snapshot* snapshot, 33 void SceneContent::RecordPicture(const Snapshot* snapshot,
26 SkCanvas* canvas) const { 34 SkCanvas* canvas) const {
27 const Node* root = GetRootNodeIfExists(); 35 const Node* root = GetRootNodeIfExists();
28 if (root) 36 if (root)
29 root->RecordPicture(this, snapshot, canvas); 37 root->RecordPicture(this, snapshot, canvas);
30 } 38 }
31 39
32 bool SceneContent::HitTest( 40 bool SceneContent::HitTest(
33 const Snapshot* snapshot, 41 const Snapshot* snapshot,
34 const SkPoint& scene_point, 42 const SkPoint& scene_point,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 auto it = nodes_.find(node_id); 75 auto it = nodes_.find(node_id);
68 DCHECK(it != nodes_.end()); 76 DCHECK(it != nodes_.end());
69 return it->second.get(); 77 return it->second.get();
70 } 78 }
71 79
72 const Node* SceneContent::GetRootNodeIfExists() const { 80 const Node* SceneContent::GetRootNodeIfExists() const {
73 auto it = nodes_.find(mojo::gfx::composition::kSceneRootNodeId); 81 auto it = nodes_.find(mojo::gfx::composition::kSceneRootNodeId);
74 return it != nodes_.end() ? it->second.get() : nullptr; 82 return it != nodes_.end() ? it->second.get() : nullptr;
75 } 83 }
76 84
77 SceneContentBuilder::SceneContentBuilder(const SceneDef* scene, 85 SceneContentBuilder::SceneContentBuilder(const SceneLabel& label,
78 uint32_t version, 86 uint32_t version,
79 std::ostream& err, 87 int64_t presentation_time,
80 size_t max_resources, 88 size_t max_resources,
81 size_t max_nodes) 89 size_t max_nodes,
82 : content_( 90 std::ostream& err)
83 new SceneContent(scene->label(), version, max_resources, max_nodes)), 91 : content_(new SceneContent(label,
84 scene_(scene), 92 version,
85 err_(err) { 93 presentation_time,
86 DCHECK(scene); 94 max_resources,
87 } 95 max_nodes)),
96 err_(err) {}
88 97
89 SceneContentBuilder::~SceneContentBuilder() {} 98 SceneContentBuilder::~SceneContentBuilder() {}
90 99
91 const Resource* SceneContentBuilder::RequireResource( 100 const Resource* SceneContentBuilder::RequireResource(
92 uint32_t resource_id, 101 uint32_t resource_id,
93 Resource::Type resource_type, 102 Resource::Type resource_type,
94 uint32_t referrer_node_id) { 103 uint32_t referrer_node_id) {
95 DCHECK(content_); 104 DCHECK(content_);
96 105
97 auto it = content_->resources_.find(resource_id); 106 auto it = content_->resources_.find(resource_id);
98 if (it != content_->resources_.end()) 107 if (it != content_->resources_.end())
99 return it->second.get(); 108 return it->second.get();
100 109
101 const Resource* resource = scene_->FindResource(resource_id); 110 const Resource* resource = FindResource(resource_id);
102 if (!resource) { 111 if (!resource) {
103 err_ << "Missing resource " << resource_id << " referenced from node " 112 err_ << "Missing resource " << resource_id << " referenced from node "
104 << content_->FormattedLabelForNode(referrer_node_id); 113 << content_->FormattedLabelForNode(referrer_node_id) << std::endl;
105 return nullptr; 114 return nullptr;
106 } 115 }
107 116
108 if (resource->type() != resource_type) { 117 if (resource->type() != resource_type) {
109 err_ << "Resource " << resource_id << " referenced from node " 118 err_ << "Resource " << resource_id << " referenced from node "
110 << content_->FormattedLabelForNode(referrer_node_id) 119 << content_->FormattedLabelForNode(referrer_node_id)
111 << " has incorrect type for its intended usage"; 120 << " has incorrect type for its intended usage" << std::endl;
112 return nullptr; 121 return nullptr;
113 } 122 }
114 123
115 content_->resources_.emplace(std::make_pair(resource_id, resource)); 124 content_->resources_.emplace(std::make_pair(resource_id, resource));
116 return resource; 125 return resource;
117 } 126 }
118 127
119 const Node* SceneContentBuilder::RequireNode(uint32_t node_id, 128 const Node* SceneContentBuilder::RequireNode(uint32_t node_id,
120 uint32_t referrer_node_id) { 129 uint32_t referrer_node_id) {
121 DCHECK(content_); 130 DCHECK(content_);
122 131
123 auto it = content_->nodes_.find(node_id); 132 auto it = content_->nodes_.find(node_id);
124 if (it != content_->nodes_.end()) { 133 if (it != content_->nodes_.end()) {
125 if (it->second) 134 if (it->second)
126 return it->second.get(); 135 return it->second.get();
127 err_ << "Cycle detected at node " << node_id << " referenced from node " 136 err_ << "Cycle detected at node " << node_id << " referenced from node "
128 << content_->FormattedLabelForNode(referrer_node_id); 137 << content_->FormattedLabelForNode(referrer_node_id) << std::endl;
129 return nullptr; 138 return nullptr;
130 } 139 }
131 140
132 const Node* node = scene_->FindNode(node_id); 141 const Node* node = FindNode(node_id);
133 if (!node) { 142 if (!node) {
134 err_ << "Missing node " << node_id << " referenced from node " 143 err_ << "Missing node " << node_id << " referenced from node "
135 << content_->FormattedLabelForNode(referrer_node_id); 144 << content_->FormattedLabelForNode(referrer_node_id) << std::endl;
136 return nullptr; 145 return nullptr;
137 } 146 }
138 147
139 return AddNode(node) ? node : nullptr; 148 return AddNode(node) ? node : nullptr;
140 } 149 }
141 150
142 bool SceneContentBuilder::AddNode(const Node* node) { 151 bool SceneContentBuilder::AddNode(const Node* node) {
143 DCHECK(content_); 152 DCHECK(content_);
144 DCHECK(node); 153 DCHECK(node);
145 154
(...skipping 14 matching lines...) Expand all
160 // nodes may have been added since the map's bucket count was initialized 169 // nodes may have been added since the map's bucket count was initialized
161 // at creation time to the total number of nodes so it should never be 170 // at creation time to the total number of nodes so it should never be
162 // rehashed during this traversal. 171 // rehashed during this traversal.
163 storage.first->second = node; 172 storage.first->second = node;
164 return true; 173 return true;
165 } 174 }
166 175
167 scoped_refptr<const SceneContent> SceneContentBuilder::Build() { 176 scoped_refptr<const SceneContent> SceneContentBuilder::Build() {
168 DCHECK(content_); 177 DCHECK(content_);
169 178
170 const Node* root = scene_->FindRootNode(); 179 const Node* root = FindNode(mojo::gfx::composition::kSceneRootNodeId);
171 return !root || AddNode(root) ? std::move(content_) : nullptr; 180 return !root || AddNode(root) ? std::move(content_) : nullptr;
172 } 181 }
173 182
174 } // namespace compositor 183 } // namespace compositor
OLDNEW
« no previous file with comments | « services/gfx/compositor/graph/scene_content.h ('k') | services/gfx/compositor/graph/scene_def.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698