| 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/snapshot.h" | 5 #include "services/gfx/compositor/graph/snapshot.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/skia/type_converters.h" |
| 8 #include "services/gfx/compositor/graph/scene_content.h" | 9 #include "services/gfx/compositor/graph/scene_content.h" |
| 9 #include "services/gfx/compositor/graph/scene_def.h" | 10 #include "services/gfx/compositor/graph/scene_def.h" |
| 10 #include "services/gfx/compositor/render/render_frame.h" | 11 #include "services/gfx/compositor/render/render_frame.h" |
| 12 #include "third_party/skia/include/core/SkMatrix.h" |
| 11 #include "third_party/skia/include/core/SkPictureRecorder.h" | 13 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 12 #include "third_party/skia/include/core/SkRect.h" | 14 #include "third_party/skia/include/core/SkRect.h" |
| 13 | 15 |
| 14 namespace compositor { | 16 namespace compositor { |
| 15 | 17 |
| 16 Snapshot::Snapshot() {} | 18 Snapshot::Snapshot() {} |
| 17 | 19 |
| 18 Snapshot::~Snapshot() {} | 20 Snapshot::~Snapshot() {} |
| 19 | 21 |
| 20 bool Snapshot::HasDependency(const SceneDef* scene) const { | 22 bool Snapshot::HasDependency(const SceneDef* scene) const { |
| 21 return dependencies_.find(scene->label().token()) != dependencies_.end(); | 23 return dependencies_.find(scene->label().token()) != dependencies_.end(); |
| 22 } | 24 } |
| 23 | 25 |
| 24 std::shared_ptr<RenderFrame> Snapshot::CreateFrame( | 26 std::shared_ptr<RenderFrame> Snapshot::CreateFrame( |
| 25 const mojo::Rect& viewport, | 27 const mojo::Rect& viewport, |
| 26 const mojo::gfx::composition::FrameInfo& frame_info) const { | 28 const mojo::gfx::composition::FrameInfo& frame_info) const { |
| 27 DCHECK(!is_blocked()); | 29 DCHECK(!is_blocked()); |
| 30 DCHECK(root_scene_content_); |
| 28 | 31 |
| 29 SkRect sk_viewport = | 32 SkRect sk_viewport = viewport.To<SkRect>(); |
| 30 SkRect::MakeXYWH(viewport.x, viewport.y, viewport.width, viewport.height); | |
| 31 SkPictureRecorder recorder; | 33 SkPictureRecorder recorder; |
| 32 recorder.beginRecording(sk_viewport); | 34 recorder.beginRecording(sk_viewport); |
| 33 | 35 root_scene_content_->RecordPicture(this, recorder.getRecordingCanvas()); |
| 34 const NodeDef* root_node = root_scene_content_->GetRootNodeIfExists(); | |
| 35 DCHECK(root_node); // otherwise would have failed to snapshot | |
| 36 root_node->RecordPicture(root_scene_content_.get(), this, | |
| 37 recorder.getRecordingCanvas()); | |
| 38 | |
| 39 return RenderFrame::Create(skia::AdoptRef(recorder.endRecordingAsPicture()), | 36 return RenderFrame::Create(skia::AdoptRef(recorder.endRecordingAsPicture()), |
| 40 sk_viewport, frame_info); | 37 sk_viewport, frame_info); |
| 41 } | 38 } |
| 42 | 39 |
| 40 void Snapshot::HitTest(const mojo::Point& point, |
| 41 mojo::gfx::composition::HitTestResult* result) const { |
| 42 DCHECK(result); |
| 43 DCHECK(!is_blocked()); |
| 44 DCHECK(root_scene_content_); |
| 45 |
| 46 bool opaque = false; |
| 47 result->root = root_scene_content_->HitTest(this, point.To<SkPoint>(), |
| 48 SkMatrix::I(), &opaque); |
| 49 } |
| 50 |
| 43 bool Snapshot::IsNodeBlocked(const NodeDef* node) const { | 51 bool Snapshot::IsNodeBlocked(const NodeDef* node) const { |
| 44 DCHECK(!is_blocked()); | 52 DCHECK(!is_blocked()); |
| 45 | 53 |
| 46 auto it = node_dispositions_.find(node); | 54 auto it = node_dispositions_.find(node); |
| 47 DCHECK(it != node_dispositions_.end()); | 55 DCHECK(it != node_dispositions_.end()); |
| 48 DCHECK(it->second == Disposition::kSuccess || | 56 DCHECK(it->second == Disposition::kSuccess || |
| 49 it->second == Disposition::kBlocked); | 57 it->second == Disposition::kBlocked); |
| 50 return it->second == Disposition::kBlocked; | 58 return it->second == Disposition::kBlocked; |
| 51 } | 59 } |
| 52 | 60 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 213 |
| 206 if (snapshot_->is_blocked()) { | 214 if (snapshot_->is_blocked()) { |
| 207 snapshot_->root_scene_content_ = nullptr; | 215 snapshot_->root_scene_content_ = nullptr; |
| 208 snapshot_->resolved_scene_contents_.clear(); | 216 snapshot_->resolved_scene_contents_.clear(); |
| 209 snapshot_->node_dispositions_.clear(); | 217 snapshot_->node_dispositions_.clear(); |
| 210 } | 218 } |
| 211 return std::move(snapshot_); | 219 return std::move(snapshot_); |
| 212 } | 220 } |
| 213 | 221 |
| 214 } // namespace compositor | 222 } // namespace compositor |
| OLD | NEW |