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