Index: services/gfx/compositor/renderer_state.cc |
diff --git a/services/gfx/compositor/renderer_state.cc b/services/gfx/compositor/renderer_state.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..46c8443a66c66727d824eb19eb80b29347972a3e |
--- /dev/null |
+++ b/services/gfx/compositor/renderer_state.cc |
@@ -0,0 +1,63 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "services/gfx/compositor/renderer_state.h" |
+ |
+#include <sstream> |
+ |
+#include "base/logging.h" |
+ |
+namespace compositor { |
+ |
+RendererState::RendererState(uint32_t id, const std::string& label) |
+ : id_(id), label_(label), weak_factory_(this) {} |
+ |
+RendererState::~RendererState() {} |
+ |
+bool RendererState::SetRootScene(SceneState* scene, |
+ uint32_t version, |
+ const mojo::Rect& viewport) { |
+ DCHECK(scene); |
+ DCHECK(version); |
+ |
+ if (root_scene_ != scene || root_scene_version_ != version || |
+ !root_scene_viewport_.Equals(viewport)) { |
+ root_scene_ = scene; |
+ root_scene_version_ = version; |
+ root_scene_viewport_ = viewport; |
+ SetSnapshot(nullptr); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool RendererState::SetSnapshot(std::unique_ptr<Snapshot> snapshot) { |
+ snapshot_ = std::move(snapshot); |
+ if (snapshot_ && snapshot_->valid()) { |
+ frame_ = snapshot_->frame(); |
+ DCHECK(frame_); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+std::string RendererState::FormattedLabel() { |
+ if (formatted_label_cache_.empty()) { |
+ std::ostringstream s; |
+ s << "<" << id_; |
+ if (!label_.empty()) |
+ s << ":" << label_; |
+ s << ">"; |
+ formatted_label_cache_ = s.str(); |
+ } |
+ return formatted_label_cache_; |
+} |
+ |
+std::ostream& operator<<(std::ostream& os, RendererState* renderer_state) { |
+ if (!renderer_state) |
+ return os << "null"; |
+ return os << renderer_state->FormattedLabel(); |
+} |
+ |
+} // namespace compositor |