| 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/renderer_state.h" | 5 #include "services/gfx/compositor/renderer_state.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 | 9 |
| 10 namespace compositor { | 10 namespace compositor { |
| 11 | 11 |
| 12 RendererState::RendererState(uint32_t id, const std::string& label) | 12 RendererState::RendererState(uint32_t id, const std::string& label) |
| 13 : id_(id), label_(label), weak_factory_(this) {} | 13 : id_(id), label_(label), weak_factory_(this) {} |
| 14 | 14 |
| 15 RendererState::~RendererState() {} | 15 RendererState::~RendererState() {} |
| 16 | 16 |
| 17 bool RendererState::SetRootScene(SceneState* scene, | 17 bool RendererState::SetRootScene(SceneState* scene, |
| 18 uint32_t version, | 18 uint32_t version, |
| 19 const mojo::Rect& viewport) { | 19 const mojo::Rect& viewport) { |
| 20 DCHECK(scene); | 20 DCHECK(scene); |
| 21 DCHECK(version); | |
| 22 | 21 |
| 23 if (root_scene_ != scene || root_scene_version_ != version || | 22 if (root_scene_ != scene || root_scene_version_ != version || |
| 24 !root_scene_viewport_.Equals(viewport)) { | 23 !root_scene_viewport_.Equals(viewport)) { |
| 25 root_scene_ = scene; | 24 root_scene_ = scene; |
| 26 root_scene_version_ = version; | 25 root_scene_version_ = version; |
| 27 root_scene_viewport_ = viewport; | 26 root_scene_viewport_ = viewport; |
| 28 SetSnapshot(nullptr); | 27 SetSnapshot(nullptr); |
| 29 return true; | 28 return true; |
| 30 } | 29 } |
| 31 return false; | 30 return false; |
| 32 } | 31 } |
| 33 | 32 |
| 33 bool RendererState::ResetRootScene() { |
| 34 if (root_scene_) { |
| 35 root_scene_ = nullptr; |
| 36 SetSnapshot(nullptr); |
| 37 return true; |
| 38 } |
| 39 return false; |
| 40 } |
| 41 |
| 34 bool RendererState::SetSnapshot(std::unique_ptr<Snapshot> snapshot) { | 42 bool RendererState::SetSnapshot(std::unique_ptr<Snapshot> snapshot) { |
| 35 snapshot_ = std::move(snapshot); | 43 snapshot_ = std::move(snapshot); |
| 36 if (snapshot_ && snapshot_->valid()) { | 44 if (snapshot_ && snapshot_->valid()) { |
| 37 frame_ = snapshot_->frame(); | 45 frame_ = snapshot_->frame(); |
| 38 DCHECK(frame_); | 46 DCHECK(frame_); |
| 39 return true; | 47 return true; |
| 40 } | 48 } |
| 41 return false; | 49 return false; |
| 42 } | 50 } |
| 43 | 51 |
| 44 std::string RendererState::FormattedLabel() { | 52 std::string RendererState::FormattedLabel() { |
| 45 if (formatted_label_cache_.empty()) { | 53 if (formatted_label_cache_.empty()) { |
| 46 formatted_label_cache_ = | 54 formatted_label_cache_ = |
| 47 label_.empty() ? base::StringPrintf("<%d>", id_) | 55 label_.empty() ? base::StringPrintf("<%d>", id_) |
| 48 : base::StringPrintf("<%d:%s>", id_, label_.c_str()); | 56 : base::StringPrintf("<%d:%s>", id_, label_.c_str()); |
| 49 } | 57 } |
| 50 return formatted_label_cache_; | 58 return formatted_label_cache_; |
| 51 } | 59 } |
| 52 | 60 |
| 53 std::ostream& operator<<(std::ostream& os, RendererState* renderer_state) { | 61 std::ostream& operator<<(std::ostream& os, RendererState* renderer_state) { |
| 54 if (!renderer_state) | 62 if (!renderer_state) |
| 55 return os << "null"; | 63 return os << "null"; |
| 56 return os << renderer_state->FormattedLabel(); | 64 return os << renderer_state->FormattedLabel(); |
| 57 } | 65 } |
| 58 | 66 |
| 59 } // namespace compositor | 67 } // namespace compositor |
| OLD | NEW |