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

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

Issue 1778793002: Mozart: Make Snapshot immutable. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-2
Patch Set: Created 4 years, 9 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
« no previous file with comments | « services/gfx/compositor/graph/snapshot.h ('k') | services/gfx/compositor/renderer_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/gfx/compositor/graph/scene_content.h" 8 #include "services/gfx/compositor/graph/scene_content.h"
9 #include "services/gfx/compositor/graph/scene_def.h" 9 #include "services/gfx/compositor/graph/scene_def.h"
10 #include "services/gfx/compositor/render/render_frame.h" 10 #include "services/gfx/compositor/render/render_frame.h"
11 #include "third_party/skia/include/core/SkPictureRecorder.h" 11 #include "third_party/skia/include/core/SkPictureRecorder.h"
12 #include "third_party/skia/include/core/SkRect.h" 12 #include "third_party/skia/include/core/SkRect.h"
13 13
14 namespace compositor { 14 namespace compositor {
15 15
16 Snapshot::Snapshot() {} 16 Snapshot::Snapshot() {}
17 17
18 Snapshot::~Snapshot() {} 18 Snapshot::~Snapshot() {}
19 19
20 bool Snapshot::Invalidate() { 20 bool Snapshot::HasDependency(const SceneDef* scene) const {
21 if (valid_) { 21 return dependencies_.find(scene->label().token()) != dependencies_.end();
22 valid_ = false;
23 dependencies_.clear();
24 ClearContent();
25 return true;
26 }
27 return false;
28 } 22 }
29 23
30 bool Snapshot::InvalidateScene(const SceneDef* scene_def) { 24 std::shared_ptr<RenderFrame> Snapshot::CreateFrame(
31 DCHECK(scene_def); 25 const mojo::Rect& viewport,
32 return valid_ && 26 const mojo::gfx::composition::FrameInfo& frame_info) const {
33 dependencies_.find(scene_def->label().token()) != 27 DCHECK(!is_blocked());
34 dependencies_.end() && 28
35 Invalidate(); 29 SkRect sk_viewport =
30 SkRect::MakeXYWH(viewport.x, viewport.y, viewport.width, viewport.height);
31 SkPictureRecorder recorder;
32 recorder.beginRecording(sk_viewport);
33
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()),
40 sk_viewport, frame_info);
36 } 41 }
37 42
38 void Snapshot::ClearContent() { 43 bool Snapshot::IsNodeBlocked(const NodeDef* node) const {
39 root_scene_content_ = nullptr; 44 DCHECK(!is_blocked());
40 resolved_scene_contents_.clear();
41 node_dispositions_.clear();
42 frame_.reset();
43 }
44 45
45 bool Snapshot::IsBlocked(const NodeDef* node) const {
46 DCHECK(valid_);
47 auto it = node_dispositions_.find(node); 46 auto it = node_dispositions_.find(node);
48 DCHECK(it != node_dispositions_.end()); 47 DCHECK(it != node_dispositions_.end());
49 DCHECK(it->second == Disposition::kSuccess || 48 DCHECK(it->second == Disposition::kSuccess ||
50 it->second == Disposition::kBlocked); 49 it->second == Disposition::kBlocked);
51 return it->second == Disposition::kBlocked; 50 return it->second == Disposition::kBlocked;
52 } 51 }
53 52
54 const SceneContent* Snapshot::GetResolvedSceneContent( 53 const SceneContent* Snapshot::GetResolvedSceneContent(
55 const SceneNodeDef* scene_node) const { 54 const SceneNodeDef* scene_node) const {
56 DCHECK(valid_); 55 DCHECK(!is_blocked());
56
57 auto it = resolved_scene_contents_.find(scene_node); 57 auto it = resolved_scene_contents_.find(scene_node);
58 DCHECK(it != resolved_scene_contents_.end()); 58 DCHECK(it != resolved_scene_contents_.end());
59 return it->second.get(); 59 return it->second.get();
60 } 60 }
61 61
62 SnapshotBuilder::SnapshotBuilder(std::ostream* block_log) 62 SnapshotBuilder::SnapshotBuilder(std::ostream* block_log)
63 : block_log_(block_log), snapshot_(new Snapshot()) {} 63 : block_log_(block_log), snapshot_(new Snapshot()) {}
64 64
65 SnapshotBuilder::~SnapshotBuilder() {} 65 SnapshotBuilder::~SnapshotBuilder() {}
66 66
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 *block_log_ << "Rendering blocked the root scene has no root node: " 188 *block_log_ << "Rendering blocked the root scene has no root node: "
189 << content->FormattedLabel() << std::endl; 189 << content->FormattedLabel() << std::endl;
190 } 190 }
191 return Snapshot::Disposition::kBlocked; 191 return Snapshot::Disposition::kBlocked;
192 } 192 }
193 193
194 snapshot_->root_scene_content_ = content; 194 snapshot_->root_scene_content_ = content;
195 return SnapshotRootAndDetectCycles(root, content); 195 return SnapshotRootAndDetectCycles(root, content);
196 } 196 }
197 197
198 std::unique_ptr<Snapshot> SnapshotBuilder::Build( 198 scoped_refptr<const Snapshot> SnapshotBuilder::Build(
199 const SceneDef* root_scene, 199 const SceneDef* root_scene) {
200 const mojo::Rect& viewport,
201 const mojo::gfx::composition::FrameInfo& frame_info) {
202 DCHECK(snapshot_); 200 DCHECK(snapshot_);
203 DCHECK(root_scene); 201 DCHECK(root_scene);
204 202
205 Snapshot::Disposition disposition = SnapshotRenderer(root_scene); 203 snapshot_->disposition_ = SnapshotRenderer(root_scene);
206 DCHECK(!cycle_); // must have properly unwound any cycles by now 204 DCHECK(!cycle_); // must have properly unwound any cycles by now
207 205
208 if (disposition == Snapshot::Disposition::kSuccess) { 206 if (snapshot_->is_blocked()) {
209 SkRect sk_viewport = SkRect::MakeXYWH(viewport.x, viewport.y, 207 snapshot_->root_scene_content_ = nullptr;
210 viewport.width, viewport.height); 208 snapshot_->resolved_scene_contents_.clear();
211 SkPictureRecorder recorder; 209 snapshot_->node_dispositions_.clear();
212 recorder.beginRecording(sk_viewport);
213
214 const NodeDef* root_node =
215 snapshot_->root_scene_content_->GetRootNodeIfExists();
216 DCHECK(root_node); // otherwise would have failed to snapshot
217 root_node->RecordPicture(snapshot_->root_scene_content_.get(),
218 snapshot_.get(), recorder.getRecordingCanvas());
219
220 snapshot_->frame_ =
221 RenderFrame::Create(skia::AdoptRef(recorder.endRecordingAsPicture()),
222 sk_viewport, frame_info);
223 } else {
224 snapshot_->ClearContent();
225 } 210 }
226 return std::move(snapshot_); 211 return std::move(snapshot_);
227 } 212 }
228 213
229 } // namespace compositor 214 } // namespace compositor
OLDNEW
« no previous file with comments | « services/gfx/compositor/graph/snapshot.h ('k') | services/gfx/compositor/renderer_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698