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

Side by Side Diff: services/gfx/compositor/renderer_state.h

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.cc ('k') | services/gfx/compositor/renderer_state.cc » ('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 #ifndef SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_ 5 #ifndef SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_
6 #define SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_ 6 #define SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "mojo/services/gfx/composition/cpp/formatting.h" 13 #include "mojo/services/gfx/composition/cpp/formatting.h"
14 #include "mojo/services/gfx/composition/interfaces/compositor.mojom.h" 14 #include "mojo/services/gfx/composition/interfaces/compositor.mojom.h"
15 #include "services/gfx/compositor/backend/output.h" 15 #include "services/gfx/compositor/backend/output.h"
16 #include "services/gfx/compositor/graph/snapshot.h" 16 #include "services/gfx/compositor/graph/snapshot.h"
17 #include "services/gfx/compositor/scene_state.h" 17 #include "services/gfx/compositor/scene_state.h"
18 18
19 namespace compositor { 19 namespace compositor {
20 20
21 class Snapshot;
22
23 // Describes the state of a particular renderer. 21 // Describes the state of a particular renderer.
24 // This object is owned by the CompositorEngine that created it. 22 // This object is owned by the CompositorEngine that created it.
25 class RendererState { 23 class RendererState {
26 public: 24 public:
27 RendererState(uint32_t id, const std::string& label); 25 RendererState(uint32_t id, const std::string& label);
28 ~RendererState(); 26 ~RendererState();
29 27
30 base::WeakPtr<RendererState> GetWeakPtr() { 28 base::WeakPtr<RendererState> GetWeakPtr() {
31 return weak_factory_.GetWeakPtr(); 29 return weak_factory_.GetWeakPtr();
32 } 30 }
33 31
34 // Sets the associated renderer implementation and takes ownership of it. 32 // Sets the associated renderer implementation and takes ownership of it.
35 void set_renderer_impl(mojo::gfx::composition::Renderer* impl) { 33 void set_renderer_impl(mojo::gfx::composition::Renderer* impl) {
36 renderer_impl_.reset(impl); 34 renderer_impl_.reset(impl);
37 } 35 }
38 36
39 // The underlying backend output. 37 // The underlying backend output.
40 void set_output(std::unique_ptr<Output> output) { 38 void set_output(std::unique_ptr<Output> output) {
41 output_ = std::move(output); 39 output_ = std::move(output);
42 } 40 }
43 Output* output() { return output_.get(); } 41 Output* output() { return output_.get(); }
44 42
45 // Gets the root scene, may be null if none set yet. 43 // Gets the root scene, may be null if none set yet.
46 SceneState* root_scene() { return root_scene_; } 44 SceneState* root_scene() { return root_scene_; }
47 uint32_t root_scene_version() { return root_scene_version_; } 45 uint32_t root_scene_version() { return root_scene_version_; }
48 const mojo::Rect& root_scene_viewport() { return root_scene_viewport_; } 46 const mojo::Rect& root_scene_viewport() { return root_scene_viewport_; }
49 47
50 // Sets the root scene and clears the current frame and cached dependencies. 48 // Sets the root scene.
51 // If different, invalidates the snapshot and returns true. 49 // If a change occurred, clears the current snapshot and returns true.
52 bool SetRootScene(SceneState* scene, 50 bool SetRootScene(SceneState* scene,
53 uint32_t version, 51 uint32_t version,
54 const mojo::Rect& viewport); 52 const mojo::Rect& viewport);
55 53
56 // Resets the root scene and clears the current frame and cached dependencies. 54 // Resets the root scene.
57 // If different, invalidates the snapshot and returns true. 55 // If a change occurred, clears the current snapshot and returns true.
58 bool ResetRootScene(); 56 bool ResetRootScene();
59 57
60 // The currently composited frame, may be null if none. 58 // The currently visible frame, or null if none.
61 const std::shared_ptr<RenderFrame>& frame() { return frame_; } 59 scoped_refptr<const Snapshot> visible_snapshot() const {
60 return visible_snapshot_;
61 }
62 62
63 // The current scene graph snapshot, may be null if none. 63 // The most recent snapshot (which may be blocked from rendering), or
64 const std::unique_ptr<Snapshot>& snapshot() { return snapshot_; } 64 // null if none.
65 scoped_refptr<const Snapshot> current_snapshot() const {
66 return current_snapshot_;
67 }
65 68
66 // Returns true if the renderer has a snapshot and it is valid. 69 // Sets the current snapshot, or null if none.
67 // This implies that |frame()| is also non-null. 70 // Always updates |current_snapshot()|.
68 bool valid() { return snapshot_ && snapshot_->valid(); } 71 // If the snapshot is not blocked, also updates |visible_snapshot()|.
69 72 void SetSnapshot(const scoped_refptr<const Snapshot>& snapshot);
70 // Sets the snapshot, or null if none.
71 // If the snapshot is valid, updates |frame()| to point to the snapshot's
72 // new frame, otherwise leaves it alone.
73 // Returns true if the snapshot is valid.
74 bool SetSnapshot(std::unique_ptr<Snapshot> snapshot);
75 73
76 const std::string& label() { return label_; } 74 const std::string& label() { return label_; }
77 std::string FormattedLabel(); 75 std::string FormattedLabel();
78 76
79 private: 77 private:
80 std::unique_ptr<Output> output_; 78 std::unique_ptr<Output> output_;
81 const uint32_t id_; 79 const uint32_t id_;
82 const std::string label_; 80 const std::string label_;
83 std::string formatted_label_cache_; 81 std::string formatted_label_cache_;
84 82
85 std::unique_ptr<mojo::gfx::composition::Renderer> renderer_impl_; 83 std::unique_ptr<mojo::gfx::composition::Renderer> renderer_impl_;
86 84
87 SceneState* root_scene_ = nullptr; 85 SceneState* root_scene_ = nullptr;
88 uint32_t root_scene_version_ = mojo::gfx::composition::kSceneVersionNone; 86 uint32_t root_scene_version_ = mojo::gfx::composition::kSceneVersionNone;
89 mojo::Rect root_scene_viewport_; 87 mojo::Rect root_scene_viewport_;
90 88
91 std::shared_ptr<RenderFrame> frame_; 89 scoped_refptr<const Snapshot> visible_snapshot_;
92 std::unique_ptr<Snapshot> snapshot_; 90 scoped_refptr<const Snapshot> current_snapshot_;
93 91
94 base::WeakPtrFactory<RendererState> weak_factory_; 92 base::WeakPtrFactory<RendererState> weak_factory_;
95 93
96 DISALLOW_COPY_AND_ASSIGN(RendererState); 94 DISALLOW_COPY_AND_ASSIGN(RendererState);
97 }; 95 };
98 96
99 std::ostream& operator<<(std::ostream& os, RendererState* renderer_state); 97 std::ostream& operator<<(std::ostream& os, RendererState* renderer_state);
100 98
101 } // namespace compositor 99 } // namespace compositor
102 100
103 #endif // SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_ 101 #endif // SERVICES_GFX_COMPOSITOR_RENDERER_STATE_H_
OLDNEW
« no previous file with comments | « services/gfx/compositor/graph/snapshot.cc ('k') | services/gfx/compositor/renderer_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698