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 root_scene_content_->HitTest(this, point.To<SkPoint>(), SkMatrix::I(), |
| 47 &result->root); |
| 48 } |
| 49 |
43 bool Snapshot::IsNodeBlocked(const NodeDef* node) const { | 50 bool Snapshot::IsNodeBlocked(const NodeDef* node) const { |
44 DCHECK(!is_blocked()); | 51 DCHECK(!is_blocked()); |
45 | 52 |
46 auto it = node_dispositions_.find(node); | 53 auto it = node_dispositions_.find(node); |
47 DCHECK(it != node_dispositions_.end()); | 54 DCHECK(it != node_dispositions_.end()); |
48 DCHECK(it->second == Disposition::kSuccess || | 55 DCHECK(it->second == Disposition::kSuccess || |
49 it->second == Disposition::kBlocked); | 56 it->second == Disposition::kBlocked); |
50 return it->second == Disposition::kBlocked; | 57 return it->second == Disposition::kBlocked; |
51 } | 58 } |
52 | 59 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 212 |
206 if (snapshot_->is_blocked()) { | 213 if (snapshot_->is_blocked()) { |
207 snapshot_->root_scene_content_ = nullptr; | 214 snapshot_->root_scene_content_ = nullptr; |
208 snapshot_->resolved_scene_contents_.clear(); | 215 snapshot_->resolved_scene_contents_.clear(); |
209 snapshot_->node_dispositions_.clear(); | 216 snapshot_->node_dispositions_.clear(); |
210 } | 217 } |
211 return std::move(snapshot_); | 218 return std::move(snapshot_); |
212 } | 219 } |
213 | 220 |
214 } // namespace compositor | 221 } // namespace compositor |
OLD | NEW |