| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/node_def.h" | 5 #include "services/gfx/compositor/graph/nodes.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/services/gfx/composition/cpp/formatting.h" | 10 #include "mojo/services/gfx/composition/cpp/formatting.h" |
| 11 #include "mojo/skia/type_converters.h" | 11 #include "mojo/skia/type_converters.h" |
| 12 #include "services/gfx/compositor/graph/scene_content.h" | 12 #include "services/gfx/compositor/graph/scene_content.h" |
| 13 #include "services/gfx/compositor/graph/scene_def.h" | 13 #include "services/gfx/compositor/graph/scene_def.h" |
| 14 #include "services/gfx/compositor/graph/snapshot.h" | 14 #include "services/gfx/compositor/graph/snapshot.h" |
| 15 #include "services/gfx/compositor/graph/transform_pair.h" | 15 #include "services/gfx/compositor/graph/transform_pair.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 33 if (blend) | 33 if (blend) |
| 34 paint->setAlpha(blend->alpha); | 34 paint->setAlpha(blend->alpha); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool Contains(const SkRect& bounds, const SkPoint& point) { | 37 bool Contains(const SkRect& bounds, const SkPoint& point) { |
| 38 return point.x() >= bounds.left() && point.x() < bounds.right() && | 38 return point.x() >= bounds.left() && point.x() < bounds.right() && |
| 39 point.y() >= bounds.top() && point.y() < bounds.bottom(); | 39 point.y() >= bounds.top() && point.y() < bounds.bottom(); |
| 40 } | 40 } |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 NodeDef::NodeDef(uint32_t node_id, | 43 Node::Node(uint32_t node_id, |
| 44 std::unique_ptr<TransformPair> content_transform, | 44 std::unique_ptr<TransformPair> content_transform, |
| 45 mojo::RectFPtr content_clip, | 45 mojo::RectFPtr content_clip, |
| 46 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 46 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 47 Combinator combinator, | 47 Combinator combinator, |
| 48 const std::vector<uint32_t>& child_node_ids) | 48 const std::vector<uint32_t>& child_node_ids) |
| 49 : node_id_(node_id), | 49 : node_id_(node_id), |
| 50 content_transform_(std::move(content_transform)), | 50 content_transform_(std::move(content_transform)), |
| 51 content_clip_(content_clip.Pass()), | 51 content_clip_(content_clip.Pass()), |
| 52 hit_test_behavior_(hit_test_behavior.Pass()), | 52 hit_test_behavior_(hit_test_behavior.Pass()), |
| 53 combinator_(combinator), | 53 combinator_(combinator), |
| 54 child_node_ids_(child_node_ids) {} | 54 child_node_ids_(child_node_ids) {} |
| 55 | 55 |
| 56 NodeDef::~NodeDef() {} | 56 Node::~Node() {} |
| 57 | 57 |
| 58 std::string NodeDef::FormattedLabel(const SceneContent* content) const { | 58 std::string Node::FormattedLabel(const SceneContent* content) const { |
| 59 return content->FormattedLabelForNode(node_id_); | 59 return content->FormattedLabelForNode(node_id_); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool NodeDef::RecordContent(SceneContentBuilder* builder) const { | 62 bool Node::RecordContent(SceneContentBuilder* builder) const { |
| 63 DCHECK(builder); | 63 DCHECK(builder); |
| 64 | 64 |
| 65 for (const auto& child_node_id : child_node_ids_) { | 65 for (const auto& child_node_id : child_node_ids_) { |
| 66 if (!builder->RequireNode(child_node_id, node_id_)) | 66 if (!builder->RequireNode(child_node_id, node_id_)) |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 Snapshot::Disposition NodeDef::RecordSnapshot(const SceneContent* content, | 72 Snapshot::Disposition Node::RecordSnapshot(const SceneContent* content, |
| 73 SnapshotBuilder* builder) const { | 73 SnapshotBuilder* builder) const { |
| 74 DCHECK(content); | 74 DCHECK(content); |
| 75 DCHECK(builder); | 75 DCHECK(builder); |
| 76 | 76 |
| 77 switch (combinator_) { | 77 switch (combinator_) { |
| 78 // MERGE: All or nothing. | 78 // MERGE: All or nothing. |
| 79 case Combinator::MERGE: { | 79 case Combinator::MERGE: { |
| 80 for (uint32_t child_node_id : child_node_ids_) { | 80 for (uint32_t child_node_id : child_node_ids_) { |
| 81 const NodeDef* child_node = content->GetNode(child_node_id); | 81 const Node* child_node = content->GetNode(child_node_id); |
| 82 DCHECK(child_node); | 82 DCHECK(child_node); |
| 83 Snapshot::Disposition disposition = | 83 Snapshot::Disposition disposition = |
| 84 builder->SnapshotNode(child_node, content); | 84 builder->SnapshotNode(child_node, content); |
| 85 if (disposition == Snapshot::Disposition::kCycle) | 85 if (disposition == Snapshot::Disposition::kCycle) |
| 86 return disposition; | 86 return disposition; |
| 87 if (disposition == Snapshot::Disposition::kBlocked) { | 87 if (disposition == Snapshot::Disposition::kBlocked) { |
| 88 if (builder->block_log()) { | 88 if (builder->block_log()) { |
| 89 *builder->block_log() | 89 *builder->block_log() |
| 90 << "Node with MERGE combinator blocked since " | 90 << "Node with MERGE combinator blocked since " |
| 91 "one of its children is blocked: " | 91 "one of its children is blocked: " |
| 92 << FormattedLabel(content) << ", blocked child " | 92 << FormattedLabel(content) << ", blocked child " |
| 93 << child_node->FormattedLabel(content) << std::endl; | 93 << child_node->FormattedLabel(content) << std::endl; |
| 94 } | 94 } |
| 95 return disposition; | 95 return disposition; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 return Snapshot::Disposition::kSuccess; | 98 return Snapshot::Disposition::kSuccess; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // PRUNE: Silently discard blocked children. | 101 // PRUNE: Silently discard blocked children. |
| 102 case Combinator::PRUNE: { | 102 case Combinator::PRUNE: { |
| 103 for (uint32_t child_node_id : child_node_ids_) { | 103 for (uint32_t child_node_id : child_node_ids_) { |
| 104 const NodeDef* child_node = content->GetNode(child_node_id); | 104 const Node* child_node = content->GetNode(child_node_id); |
| 105 DCHECK(child_node); | 105 DCHECK(child_node); |
| 106 Snapshot::Disposition disposition = | 106 Snapshot::Disposition disposition = |
| 107 builder->SnapshotNode(child_node, content); | 107 builder->SnapshotNode(child_node, content); |
| 108 if (disposition == Snapshot::Disposition::kCycle) | 108 if (disposition == Snapshot::Disposition::kCycle) |
| 109 return disposition; | 109 return disposition; |
| 110 } | 110 } |
| 111 return Snapshot::Disposition::kSuccess; | 111 return Snapshot::Disposition::kSuccess; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // FALLBACK: Keep only the first unblocked child. | 114 // FALLBACK: Keep only the first unblocked child. |
| 115 case Combinator::FALLBACK: { | 115 case Combinator::FALLBACK: { |
| 116 if (child_node_ids_.empty()) | 116 if (child_node_ids_.empty()) |
| 117 return Snapshot::Disposition::kSuccess; | 117 return Snapshot::Disposition::kSuccess; |
| 118 for (uint32_t child_node_id : child_node_ids_) { | 118 for (uint32_t child_node_id : child_node_ids_) { |
| 119 const NodeDef* child_node = content->GetNode(child_node_id); | 119 const Node* child_node = content->GetNode(child_node_id); |
| 120 DCHECK(child_node); | 120 DCHECK(child_node); |
| 121 Snapshot::Disposition disposition = | 121 Snapshot::Disposition disposition = |
| 122 builder->SnapshotNode(child_node, content); | 122 builder->SnapshotNode(child_node, content); |
| 123 if (disposition != Snapshot::Disposition::kBlocked) | 123 if (disposition != Snapshot::Disposition::kBlocked) |
| 124 return disposition; | 124 return disposition; |
| 125 } | 125 } |
| 126 if (builder->block_log()) { | 126 if (builder->block_log()) { |
| 127 *builder->block_log() << "Node with FALLBACK combinator blocked since " | 127 *builder->block_log() << "Node with FALLBACK combinator blocked since " |
| 128 "all of its children are blocked: " | 128 "all of its children are blocked: " |
| 129 << FormattedLabel(content) << std::endl; | 129 << FormattedLabel(content) << std::endl; |
| 130 } | 130 } |
| 131 return Snapshot::Disposition::kBlocked; | 131 return Snapshot::Disposition::kBlocked; |
| 132 } | 132 } |
| 133 | 133 |
| 134 default: { | 134 default: { |
| 135 if (builder->block_log()) { | 135 if (builder->block_log()) { |
| 136 *builder->block_log() | 136 *builder->block_log() |
| 137 << "Unrecognized combinator: " << FormattedLabel(content) | 137 << "Unrecognized combinator: " << FormattedLabel(content) |
| 138 << std::endl; | 138 << std::endl; |
| 139 } | 139 } |
| 140 return Snapshot::Disposition::kBlocked; | 140 return Snapshot::Disposition::kBlocked; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 template <typename Func> | 145 template <typename Func> |
| 146 void NodeDef::TraverseSnapshottedChildren(const SceneContent* content, | 146 void Node::TraverseSnapshottedChildren(const SceneContent* content, |
| 147 const Snapshot* snapshot, | 147 const Snapshot* snapshot, |
| 148 const Func& func) const { | 148 const Func& func) const { |
| 149 DCHECK(content); | 149 DCHECK(content); |
| 150 DCHECK(snapshot); | 150 DCHECK(snapshot); |
| 151 | 151 |
| 152 switch (combinator_) { | 152 switch (combinator_) { |
| 153 // MERGE: All or nothing. | 153 // MERGE: All or nothing. |
| 154 case Combinator::MERGE: { | 154 case Combinator::MERGE: { |
| 155 for (uint32_t child_node_id : child_node_ids_) { | 155 for (uint32_t child_node_id : child_node_ids_) { |
| 156 const NodeDef* child_node = content->GetNode(child_node_id); | 156 const Node* child_node = content->GetNode(child_node_id); |
| 157 DCHECK(child_node); | 157 DCHECK(child_node); |
| 158 DCHECK(!snapshot->IsNodeBlocked(child_node)); | 158 DCHECK(!snapshot->IsNodeBlocked(child_node)); |
| 159 if (!func(child_node)) | 159 if (!func(child_node)) |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // PRUNE: Silently discard blocked children. | 165 // PRUNE: Silently discard blocked children. |
| 166 case Combinator::PRUNE: { | 166 case Combinator::PRUNE: { |
| 167 for (uint32_t child_node_id : child_node_ids_) { | 167 for (uint32_t child_node_id : child_node_ids_) { |
| 168 const NodeDef* child_node = content->GetNode(child_node_id); | 168 const Node* child_node = content->GetNode(child_node_id); |
| 169 DCHECK(child_node); | 169 DCHECK(child_node); |
| 170 if (!snapshot->IsNodeBlocked(child_node) && !func(child_node)) | 170 if (!snapshot->IsNodeBlocked(child_node) && !func(child_node)) |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 // FALLBACK: Keep only the first unblocked child. | 176 // FALLBACK: Keep only the first unblocked child. |
| 177 case Combinator::FALLBACK: { | 177 case Combinator::FALLBACK: { |
| 178 if (child_node_ids_.empty()) | 178 if (child_node_ids_.empty()) |
| 179 return; | 179 return; |
| 180 for (uint32_t child_node_id : child_node_ids_) { | 180 for (uint32_t child_node_id : child_node_ids_) { |
| 181 const NodeDef* child_node = content->GetNode(child_node_id); | 181 const Node* child_node = content->GetNode(child_node_id); |
| 182 DCHECK(child_node); | 182 DCHECK(child_node); |
| 183 if (!snapshot->IsNodeBlocked(child_node)) { | 183 if (!snapshot->IsNodeBlocked(child_node)) { |
| 184 func(child_node); // don't care about the result because we | 184 func(child_node); // don't care about the result because we |
| 185 return; // always stop after the first one | 185 return; // always stop after the first one |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 NOTREACHED(); | 188 NOTREACHED(); |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 | 191 |
| 192 default: { | 192 default: { |
| 193 NOTREACHED(); | 193 NOTREACHED(); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void NodeDef::RecordPicture(const SceneContent* content, | 199 void Node::RecordPicture(const SceneContent* content, |
| 200 const Snapshot* snapshot, | 200 const Snapshot* snapshot, |
| 201 SkCanvas* canvas) const { | 201 SkCanvas* canvas) const { |
| 202 DCHECK(content); | 202 DCHECK(content); |
| 203 DCHECK(snapshot); | 203 DCHECK(snapshot); |
| 204 DCHECK(canvas); | 204 DCHECK(canvas); |
| 205 | 205 |
| 206 const bool must_save = content_transform_ || content_clip_; | 206 const bool must_save = content_transform_ || content_clip_; |
| 207 if (must_save) { | 207 if (must_save) { |
| 208 canvas->save(); | 208 canvas->save(); |
| 209 if (content_transform_) | 209 if (content_transform_) |
| 210 canvas->concat(content_transform_->forward()); | 210 canvas->concat(content_transform_->forward()); |
| 211 if (content_clip_) | 211 if (content_clip_) |
| 212 canvas->clipRect(content_clip_->To<SkRect>()); | 212 canvas->clipRect(content_clip_->To<SkRect>()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 RecordPictureInner(content, snapshot, canvas); | 215 RecordPictureInner(content, snapshot, canvas); |
| 216 | 216 |
| 217 if (must_save) | 217 if (must_save) |
| 218 canvas->restore(); | 218 canvas->restore(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void NodeDef::RecordPictureInner(const SceneContent* content, | 221 void Node::RecordPictureInner(const SceneContent* content, |
| 222 const Snapshot* snapshot, | 222 const Snapshot* snapshot, |
| 223 SkCanvas* canvas) const { | 223 SkCanvas* canvas) const { |
| 224 DCHECK(content); | 224 DCHECK(content); |
| 225 DCHECK(snapshot); | 225 DCHECK(snapshot); |
| 226 DCHECK(canvas); | 226 DCHECK(canvas); |
| 227 | 227 |
| 228 TraverseSnapshottedChildren( | 228 TraverseSnapshottedChildren( |
| 229 content, snapshot, | 229 content, snapshot, |
| 230 [this, content, snapshot, canvas](const NodeDef* child_node) -> bool { | 230 [this, content, snapshot, canvas](const Node* child_node) -> bool { |
| 231 child_node->RecordPicture(content, snapshot, canvas); | 231 child_node->RecordPicture(content, snapshot, canvas); |
| 232 return true; | 232 return true; |
| 233 }); | 233 }); |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool NodeDef::HitTest(const SceneContent* content, | 236 bool Node::HitTest(const SceneContent* content, |
| 237 const Snapshot* snapshot, | 237 const Snapshot* snapshot, |
| 238 const SkPoint& parent_point, | 238 const SkPoint& parent_point, |
| 239 const SkMatrix44& global_to_parent_transform, | 239 const SkMatrix44& global_to_parent_transform, |
| 240 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { | 240 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { |
| 241 DCHECK(content); | 241 DCHECK(content); |
| 242 DCHECK(snapshot); | 242 DCHECK(snapshot); |
| 243 DCHECK(hits); | 243 DCHECK(hits); |
| 244 | 244 |
| 245 // TODO(jeffbrown): These calculations should probably be happening using | 245 // TODO(jeffbrown): These calculations should probably be happening using |
| 246 // a 4x4 matrix instead. | 246 // a 4x4 matrix instead. |
| 247 SkPoint local_point(parent_point); | 247 SkPoint local_point(parent_point); |
| 248 SkMatrix global_to_local_transform(global_to_parent_transform); | 248 SkMatrix global_to_local_transform(global_to_parent_transform); |
| 249 if (content_transform_) { | 249 if (content_transform_) { |
| 250 // TODO(jeffbrown): Defer matrix multiplications using a matrix stack. | 250 // TODO(jeffbrown): Defer matrix multiplications using a matrix stack. |
| 251 local_point = content_transform_->InverseMapPoint(parent_point); | 251 local_point = content_transform_->InverseMapPoint(parent_point); |
| 252 global_to_local_transform.preConcat(content_transform_->GetInverse()); | 252 global_to_local_transform.preConcat(content_transform_->GetInverse()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 if (content_clip_ && !Contains(content_clip_->To<SkRect>(), local_point)) | 255 if (content_clip_ && !Contains(content_clip_->To<SkRect>(), local_point)) |
| 256 return false; | 256 return false; |
| 257 | 257 |
| 258 bool opaque_children = false; | 258 bool opaque_children = false; |
| 259 if (!hit_test_behavior_ || !hit_test_behavior_->prune) { | 259 if (!hit_test_behavior_ || !hit_test_behavior_->prune) { |
| 260 opaque_children = HitTestInner(content, snapshot, local_point, | 260 opaque_children = HitTestInner(content, snapshot, local_point, |
| 261 global_to_local_transform, hits); | 261 global_to_local_transform, hits); |
| 262 } | 262 } |
| 263 | 263 |
| 264 return HitTestSelf(content, snapshot, local_point, global_to_local_transform, | 264 return HitTestSelf(content, snapshot, local_point, global_to_local_transform, |
| 265 hits) || | 265 hits) || |
| 266 opaque_children; | 266 opaque_children; |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool NodeDef::HitTestInner( | 269 bool Node::HitTestInner( |
| 270 const SceneContent* content, | 270 const SceneContent* content, |
| 271 const Snapshot* snapshot, | 271 const Snapshot* snapshot, |
| 272 const SkPoint& local_point, | 272 const SkPoint& local_point, |
| 273 const SkMatrix44& global_to_local_transform, | 273 const SkMatrix44& global_to_local_transform, |
| 274 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { | 274 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { |
| 275 DCHECK(content); | 275 DCHECK(content); |
| 276 DCHECK(snapshot); | 276 DCHECK(snapshot); |
| 277 DCHECK(hits); | 277 DCHECK(hits); |
| 278 | 278 |
| 279 // TODO(jeffbrown): Implement a more efficient way to traverse children in | 279 // TODO(jeffbrown): Implement a more efficient way to traverse children in |
| 280 // reverse order. | 280 // reverse order. |
| 281 std::vector<const NodeDef*> children; | 281 std::vector<const Node*> children; |
| 282 TraverseSnapshottedChildren( | 282 TraverseSnapshottedChildren( |
| 283 content, snapshot, [this, &children](const NodeDef* child_node) -> bool { | 283 content, snapshot, [this, &children](const Node* child_node) -> bool { |
| 284 children.push_back(child_node); | 284 children.push_back(child_node); |
| 285 return true; | 285 return true; |
| 286 }); | 286 }); |
| 287 | 287 |
| 288 for (auto it = children.crbegin(); it != children.crend(); ++it) { | 288 for (auto it = children.crbegin(); it != children.crend(); ++it) { |
| 289 if ((*it)->HitTest(content, snapshot, local_point, | 289 if ((*it)->HitTest(content, snapshot, local_point, |
| 290 global_to_local_transform, hits)) | 290 global_to_local_transform, hits)) |
| 291 return true; // opaque child covering siblings | 291 return true; // opaque child covering siblings |
| 292 } | 292 } |
| 293 return false; | 293 return false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 bool NodeDef::HitTestSelf( | 296 bool Node::HitTestSelf( |
| 297 const SceneContent* content, | 297 const SceneContent* content, |
| 298 const Snapshot* snapshot, | 298 const Snapshot* snapshot, |
| 299 const SkPoint& local_point, | 299 const SkPoint& local_point, |
| 300 const SkMatrix44& global_to_local_transform, | 300 const SkMatrix44& global_to_local_transform, |
| 301 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { | 301 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { |
| 302 DCHECK(content); | 302 DCHECK(content); |
| 303 DCHECK(snapshot); | 303 DCHECK(snapshot); |
| 304 DCHECK(hits); | 304 DCHECK(hits); |
| 305 | 305 |
| 306 if (!hit_test_behavior_ || | 306 if (!hit_test_behavior_ || |
| 307 hit_test_behavior_->visibility == | 307 hit_test_behavior_->visibility == |
| 308 mojo::gfx::composition::HitTestBehavior::Visibility::INVISIBLE) | 308 mojo::gfx::composition::HitTestBehavior::Visibility::INVISIBLE) |
| 309 return false; | 309 return false; |
| 310 | 310 |
| 311 if (hit_test_behavior_->hit_rect && | 311 if (hit_test_behavior_->hit_rect && |
| 312 !Contains(hit_test_behavior_->hit_rect->To<SkRect>(), local_point)) | 312 !Contains(hit_test_behavior_->hit_rect->To<SkRect>(), local_point)) |
| 313 return false; | 313 return false; |
| 314 | 314 |
| 315 auto hit = mojo::gfx::composition::Hit::New(); | 315 auto hit = mojo::gfx::composition::Hit::New(); |
| 316 hit->set_node(mojo::gfx::composition::NodeHit::New()); | 316 hit->set_node(mojo::gfx::composition::NodeHit::New()); |
| 317 hit->get_node()->node_id = node_id_; | 317 hit->get_node()->node_id = node_id_; |
| 318 hit->get_node()->transform = | 318 hit->get_node()->transform = |
| 319 mojo::ConvertTo<mojo::TransformPtr>(global_to_local_transform); | 319 mojo::ConvertTo<mojo::TransformPtr>(global_to_local_transform); |
| 320 hits->push_back(hit.Pass()); | 320 hits->push_back(hit.Pass()); |
| 321 return hit_test_behavior_->visibility == | 321 return hit_test_behavior_->visibility == |
| 322 mojo::gfx::composition::HitTestBehavior::Visibility::OPAQUE; | 322 mojo::gfx::composition::HitTestBehavior::Visibility::OPAQUE; |
| 323 } | 323 } |
| 324 | 324 |
| 325 RectNodeDef::RectNodeDef( | 325 RectNode::RectNode(uint32_t node_id, |
| 326 uint32_t node_id, | 326 std::unique_ptr<TransformPair> content_transform, |
| 327 std::unique_ptr<TransformPair> content_transform, | 327 mojo::RectFPtr content_clip, |
| 328 mojo::RectFPtr content_clip, | 328 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 329 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 329 Combinator combinator, |
| 330 Combinator combinator, | 330 const std::vector<uint32_t>& child_node_ids, |
| 331 const std::vector<uint32_t>& child_node_ids, | 331 const mojo::RectF& content_rect, |
| 332 const mojo::RectF& content_rect, | 332 const mojo::gfx::composition::Color& color) |
| 333 const mojo::gfx::composition::Color& color) | 333 : Node(node_id, |
| 334 : NodeDef(node_id, | 334 std::move(content_transform), |
| 335 std::move(content_transform), | 335 content_clip.Pass(), |
| 336 content_clip.Pass(), | 336 hit_test_behavior.Pass(), |
| 337 hit_test_behavior.Pass(), | 337 combinator, |
| 338 combinator, | 338 child_node_ids), |
| 339 child_node_ids), | |
| 340 content_rect_(content_rect), | 339 content_rect_(content_rect), |
| 341 color_(color) {} | 340 color_(color) {} |
| 342 | 341 |
| 343 RectNodeDef::~RectNodeDef() {} | 342 RectNode::~RectNode() {} |
| 344 | 343 |
| 345 void RectNodeDef::RecordPictureInner(const SceneContent* content, | 344 void RectNode::RecordPictureInner(const SceneContent* content, |
| 346 const Snapshot* snapshot, | 345 const Snapshot* snapshot, |
| 347 SkCanvas* canvas) const { | 346 SkCanvas* canvas) const { |
| 348 DCHECK(content); | 347 DCHECK(content); |
| 349 DCHECK(snapshot); | 348 DCHECK(snapshot); |
| 350 DCHECK(canvas); | 349 DCHECK(canvas); |
| 351 | 350 |
| 352 SkPaint paint; | 351 SkPaint paint; |
| 353 paint.setColor(MakeSkColor(color_)); | 352 paint.setColor(MakeSkColor(color_)); |
| 354 canvas->drawRect(content_rect_.To<SkRect>(), paint); | 353 canvas->drawRect(content_rect_.To<SkRect>(), paint); |
| 355 | 354 |
| 356 NodeDef::RecordPictureInner(content, snapshot, canvas); | 355 Node::RecordPictureInner(content, snapshot, canvas); |
| 357 } | 356 } |
| 358 | 357 |
| 359 ImageNodeDef::ImageNodeDef( | 358 ImageNode::ImageNode( |
| 360 uint32_t node_id, | 359 uint32_t node_id, |
| 361 std::unique_ptr<TransformPair> content_transform, | 360 std::unique_ptr<TransformPair> content_transform, |
| 362 mojo::RectFPtr content_clip, | 361 mojo::RectFPtr content_clip, |
| 363 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 362 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 364 Combinator combinator, | 363 Combinator combinator, |
| 365 const std::vector<uint32_t>& child_node_ids, | 364 const std::vector<uint32_t>& child_node_ids, |
| 366 const mojo::RectF& content_rect, | 365 const mojo::RectF& content_rect, |
| 367 mojo::RectFPtr image_rect, | 366 mojo::RectFPtr image_rect, |
| 368 uint32 image_resource_id, | 367 uint32 image_resource_id, |
| 369 mojo::gfx::composition::BlendPtr blend) | 368 mojo::gfx::composition::BlendPtr blend) |
| 370 : NodeDef(node_id, | 369 : Node(node_id, |
| 371 std::move(content_transform), | 370 std::move(content_transform), |
| 372 content_clip.Pass(), | 371 content_clip.Pass(), |
| 373 hit_test_behavior.Pass(), | 372 hit_test_behavior.Pass(), |
| 374 combinator, | 373 combinator, |
| 375 child_node_ids), | 374 child_node_ids), |
| 376 content_rect_(content_rect), | 375 content_rect_(content_rect), |
| 377 image_rect_(image_rect.Pass()), | 376 image_rect_(image_rect.Pass()), |
| 378 image_resource_id_(image_resource_id), | 377 image_resource_id_(image_resource_id), |
| 379 blend_(blend.Pass()) {} | 378 blend_(blend.Pass()) {} |
| 380 | 379 |
| 381 ImageNodeDef::~ImageNodeDef() {} | 380 ImageNode::~ImageNode() {} |
| 382 | 381 |
| 383 bool ImageNodeDef::RecordContent(SceneContentBuilder* builder) const { | 382 bool ImageNode::RecordContent(SceneContentBuilder* builder) const { |
| 384 DCHECK(builder); | 383 DCHECK(builder); |
| 385 | 384 |
| 386 return NodeDef::RecordContent(builder) && | 385 return Node::RecordContent(builder) && |
| 387 builder->RequireResource(image_resource_id_, ResourceDef::Type::kImage, | 386 builder->RequireResource(image_resource_id_, Resource::Type::kImage, |
| 388 node_id()); | 387 node_id()); |
| 389 } | 388 } |
| 390 | 389 |
| 391 void ImageNodeDef::RecordPictureInner(const SceneContent* content, | 390 void ImageNode::RecordPictureInner(const SceneContent* content, |
| 392 const Snapshot* snapshot, | 391 const Snapshot* snapshot, |
| 393 SkCanvas* canvas) const { | 392 SkCanvas* canvas) const { |
| 394 DCHECK(content); | 393 DCHECK(content); |
| 395 DCHECK(snapshot); | 394 DCHECK(snapshot); |
| 396 DCHECK(canvas); | 395 DCHECK(canvas); |
| 397 | 396 |
| 398 auto image_resource = static_cast<const ImageResourceDef*>( | 397 auto image_resource = static_cast<const ImageResource*>( |
| 399 content->GetResource(image_resource_id_, ResourceDef::Type::kImage)); | 398 content->GetResource(image_resource_id_, Resource::Type::kImage)); |
| 400 DCHECK(image_resource); | 399 DCHECK(image_resource); |
| 401 | 400 |
| 402 SkPaint paint; | 401 SkPaint paint; |
| 403 SetPaintForBlend(&paint, blend_.get()); | 402 SetPaintForBlend(&paint, blend_.get()); |
| 404 | 403 |
| 405 canvas->drawImageRect(image_resource->image()->image().get(), | 404 canvas->drawImageRect(image_resource->image()->image().get(), |
| 406 image_rect_ | 405 image_rect_ |
| 407 ? image_rect_->To<SkRect>() | 406 ? image_rect_->To<SkRect>() |
| 408 : SkRect::MakeWH(image_resource->image()->width(), | 407 : SkRect::MakeWH(image_resource->image()->width(), |
| 409 image_resource->image()->height()), | 408 image_resource->image()->height()), |
| 410 content_rect_.To<SkRect>(), &paint); | 409 content_rect_.To<SkRect>(), &paint); |
| 411 | 410 |
| 412 NodeDef::RecordPictureInner(content, snapshot, canvas); | 411 Node::RecordPictureInner(content, snapshot, canvas); |
| 413 } | 412 } |
| 414 | 413 |
| 415 SceneNodeDef::SceneNodeDef( | 414 SceneNode::SceneNode( |
| 416 uint32_t node_id, | 415 uint32_t node_id, |
| 417 std::unique_ptr<TransformPair> content_transform, | 416 std::unique_ptr<TransformPair> content_transform, |
| 418 mojo::RectFPtr content_clip, | 417 mojo::RectFPtr content_clip, |
| 419 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 418 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 420 Combinator combinator, | 419 Combinator combinator, |
| 421 const std::vector<uint32_t>& child_node_ids, | 420 const std::vector<uint32_t>& child_node_ids, |
| 422 uint32_t scene_resource_id, | 421 uint32_t scene_resource_id, |
| 423 uint32_t scene_version) | 422 uint32_t scene_version) |
| 424 : NodeDef(node_id, | 423 : Node(node_id, |
| 425 std::move(content_transform), | 424 std::move(content_transform), |
| 426 content_clip.Pass(), | 425 content_clip.Pass(), |
| 427 hit_test_behavior.Pass(), | 426 hit_test_behavior.Pass(), |
| 428 combinator, | 427 combinator, |
| 429 child_node_ids), | 428 child_node_ids), |
| 430 scene_resource_id_(scene_resource_id), | 429 scene_resource_id_(scene_resource_id), |
| 431 scene_version_(scene_version) {} | 430 scene_version_(scene_version) {} |
| 432 | 431 |
| 433 SceneNodeDef::~SceneNodeDef() {} | 432 SceneNode::~SceneNode() {} |
| 434 | 433 |
| 435 bool SceneNodeDef::RecordContent(SceneContentBuilder* builder) const { | 434 bool SceneNode::RecordContent(SceneContentBuilder* builder) const { |
| 436 DCHECK(builder); | 435 DCHECK(builder); |
| 437 | 436 |
| 438 return NodeDef::RecordContent(builder) && | 437 return Node::RecordContent(builder) && |
| 439 builder->RequireResource(scene_resource_id_, ResourceDef::Type::kScene, | 438 builder->RequireResource(scene_resource_id_, Resource::Type::kScene, |
| 440 node_id()); | 439 node_id()); |
| 441 } | 440 } |
| 442 | 441 |
| 443 Snapshot::Disposition SceneNodeDef::RecordSnapshot( | 442 Snapshot::Disposition SceneNode::RecordSnapshot( |
| 444 const SceneContent* content, | 443 const SceneContent* content, |
| 445 SnapshotBuilder* builder) const { | 444 SnapshotBuilder* builder) const { |
| 446 DCHECK(content); | 445 DCHECK(content); |
| 447 DCHECK(builder); | 446 DCHECK(builder); |
| 448 | 447 |
| 449 auto scene_resource = static_cast<const SceneResourceDef*>( | 448 auto scene_resource = static_cast<const SceneResource*>( |
| 450 content->GetResource(scene_resource_id_, ResourceDef::Type::kScene)); | 449 content->GetResource(scene_resource_id_, Resource::Type::kScene)); |
| 451 DCHECK(scene_resource); | 450 DCHECK(scene_resource); |
| 452 | 451 |
| 453 SceneDef* referenced_scene = scene_resource->referenced_scene().get(); | 452 SceneDef* referenced_scene = scene_resource->referenced_scene().get(); |
| 454 if (!referenced_scene) { | 453 if (!referenced_scene) { |
| 455 if (builder->block_log()) { | 454 if (builder->block_log()) { |
| 456 *builder->block_log() | 455 *builder->block_log() |
| 457 << "Scene node blocked because its referenced scene is unavailable: " | 456 << "Scene node blocked because its referenced scene is unavailable: " |
| 458 << FormattedLabel(content) << std::endl; | 457 << FormattedLabel(content) << std::endl; |
| 459 } | 458 } |
| 460 return Snapshot::Disposition::kBlocked; | 459 return Snapshot::Disposition::kBlocked; |
| 461 } | 460 } |
| 462 | 461 |
| 463 Snapshot::Disposition disposition = | 462 Snapshot::Disposition disposition = |
| 464 builder->SnapshotScene(referenced_scene, scene_version_, this, content); | 463 builder->SnapshotScene(referenced_scene, scene_version_, this, content); |
| 465 if (disposition != Snapshot::Disposition::kSuccess) | 464 if (disposition != Snapshot::Disposition::kSuccess) |
| 466 return disposition; | 465 return disposition; |
| 467 return NodeDef::RecordSnapshot(content, builder); | 466 return Node::RecordSnapshot(content, builder); |
| 468 } | 467 } |
| 469 | 468 |
| 470 void SceneNodeDef::RecordPictureInner(const SceneContent* content, | 469 void SceneNode::RecordPictureInner(const SceneContent* content, |
| 471 const Snapshot* snapshot, | 470 const Snapshot* snapshot, |
| 472 SkCanvas* canvas) const { | 471 SkCanvas* canvas) const { |
| 473 DCHECK(content); | 472 DCHECK(content); |
| 474 DCHECK(snapshot); | 473 DCHECK(snapshot); |
| 475 DCHECK(canvas); | 474 DCHECK(canvas); |
| 476 | 475 |
| 477 const SceneContent* resolved_content = | 476 const SceneContent* resolved_content = |
| 478 snapshot->GetResolvedSceneContent(this); | 477 snapshot->GetResolvedSceneContent(this); |
| 479 DCHECK(resolved_content); | 478 DCHECK(resolved_content); |
| 480 resolved_content->RecordPicture(snapshot, canvas); | 479 resolved_content->RecordPicture(snapshot, canvas); |
| 481 | 480 |
| 482 NodeDef::RecordPictureInner(content, snapshot, canvas); | 481 Node::RecordPictureInner(content, snapshot, canvas); |
| 483 } | 482 } |
| 484 | 483 |
| 485 bool SceneNodeDef::HitTestInner( | 484 bool SceneNode::HitTestInner( |
| 486 const SceneContent* content, | 485 const SceneContent* content, |
| 487 const Snapshot* snapshot, | 486 const Snapshot* snapshot, |
| 488 const SkPoint& local_point, | 487 const SkPoint& local_point, |
| 489 const SkMatrix44& global_to_local_transform, | 488 const SkMatrix44& global_to_local_transform, |
| 490 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { | 489 mojo::Array<mojo::gfx::composition::HitPtr>* hits) const { |
| 491 DCHECK(content); | 490 DCHECK(content); |
| 492 DCHECK(snapshot); | 491 DCHECK(snapshot); |
| 493 DCHECK(hits); | 492 DCHECK(hits); |
| 494 | 493 |
| 495 if (NodeDef::HitTestInner(content, snapshot, local_point, | 494 if (Node::HitTestInner(content, snapshot, local_point, |
| 496 global_to_local_transform, hits)) | 495 global_to_local_transform, hits)) |
| 497 return true; // opaque child covering referenced scene | 496 return true; // opaque child covering referenced scene |
| 498 | 497 |
| 499 const SceneContent* resolved_content = | 498 const SceneContent* resolved_content = |
| 500 snapshot->GetResolvedSceneContent(this); | 499 snapshot->GetResolvedSceneContent(this); |
| 501 DCHECK(resolved_content); | 500 DCHECK(resolved_content); |
| 502 | 501 |
| 503 mojo::gfx::composition::SceneHitPtr scene_hit; | 502 mojo::gfx::composition::SceneHitPtr scene_hit; |
| 504 bool opaque = resolved_content->HitTest( | 503 bool opaque = resolved_content->HitTest( |
| 505 snapshot, local_point, global_to_local_transform, &scene_hit); | 504 snapshot, local_point, global_to_local_transform, &scene_hit); |
| 506 if (scene_hit) { | 505 if (scene_hit) { |
| 507 auto hit = mojo::gfx::composition::Hit::New(); | 506 auto hit = mojo::gfx::composition::Hit::New(); |
| 508 hit->set_scene(scene_hit.Pass()); | 507 hit->set_scene(scene_hit.Pass()); |
| 509 hits->push_back(hit.Pass()); | 508 hits->push_back(hit.Pass()); |
| 510 } | 509 } |
| 511 return opaque; | 510 return opaque; |
| 512 } | 511 } |
| 513 | 512 |
| 514 LayerNodeDef::LayerNodeDef( | 513 LayerNode::LayerNode( |
| 515 uint32_t node_id, | 514 uint32_t node_id, |
| 516 std::unique_ptr<TransformPair> content_transform, | 515 std::unique_ptr<TransformPair> content_transform, |
| 517 mojo::RectFPtr content_clip, | 516 mojo::RectFPtr content_clip, |
| 518 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, | 517 mojo::gfx::composition::HitTestBehaviorPtr hit_test_behavior, |
| 519 Combinator combinator, | 518 Combinator combinator, |
| 520 const std::vector<uint32_t>& child_node_ids, | 519 const std::vector<uint32_t>& child_node_ids, |
| 521 const mojo::RectF& layer_rect, | 520 const mojo::RectF& layer_rect, |
| 522 mojo::gfx::composition::BlendPtr blend) | 521 mojo::gfx::composition::BlendPtr blend) |
| 523 : NodeDef(node_id, | 522 : Node(node_id, |
| 524 std::move(content_transform), | 523 std::move(content_transform), |
| 525 content_clip.Pass(), | 524 content_clip.Pass(), |
| 526 hit_test_behavior.Pass(), | 525 hit_test_behavior.Pass(), |
| 527 combinator, | 526 combinator, |
| 528 child_node_ids), | 527 child_node_ids), |
| 529 layer_rect_(layer_rect), | 528 layer_rect_(layer_rect), |
| 530 blend_(blend.Pass()) {} | 529 blend_(blend.Pass()) {} |
| 531 | 530 |
| 532 LayerNodeDef::~LayerNodeDef() {} | 531 LayerNode::~LayerNode() {} |
| 533 | 532 |
| 534 void LayerNodeDef::RecordPictureInner(const SceneContent* content, | 533 void LayerNode::RecordPictureInner(const SceneContent* content, |
| 535 const Snapshot* snapshot, | 534 const Snapshot* snapshot, |
| 536 SkCanvas* canvas) const { | 535 SkCanvas* canvas) const { |
| 537 DCHECK(content); | 536 DCHECK(content); |
| 538 DCHECK(snapshot); | 537 DCHECK(snapshot); |
| 539 DCHECK(canvas); | 538 DCHECK(canvas); |
| 540 | 539 |
| 541 SkPaint paint; | 540 SkPaint paint; |
| 542 SetPaintForBlend(&paint, blend_.get()); | 541 SetPaintForBlend(&paint, blend_.get()); |
| 543 | 542 |
| 544 canvas->saveLayer(layer_rect_.To<SkRect>(), &paint); | 543 canvas->saveLayer(layer_rect_.To<SkRect>(), &paint); |
| 545 NodeDef::RecordPictureInner(content, snapshot, canvas); | 544 Node::RecordPictureInner(content, snapshot, canvas); |
| 546 canvas->restore(); | 545 canvas->restore(); |
| 547 } | 546 } |
| 548 | 547 |
| 549 } // namespace compositor | 548 } // namespace compositor |
| OLD | NEW |