Home | History | Annotate | Download | only in debug
      1 // Copyright (c) 2013 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 "cc/debug/traced_picture.h"
      6 
      7 #include "base/json/json_writer.h"
      8 #include "base/strings/stringprintf.h"
      9 #include "base/values.h"
     10 #include "cc/debug/traced_value.h"
     11 
     12 namespace cc {
     13 
     14 TracedPicture::TracedPicture(scoped_refptr<const Picture> picture)
     15     : picture_(picture), is_alias_(false) {}
     16 
     17 TracedPicture::~TracedPicture() {
     18 }
     19 
     20 scoped_refptr<base::debug::ConvertableToTraceFormat>
     21 TracedPicture::AsTraceablePicture(const Picture* picture) {
     22   return scoped_refptr<base::debug::ConvertableToTraceFormat>(
     23       new TracedPicture(picture));
     24 }
     25 
     26 scoped_refptr<base::debug::ConvertableToTraceFormat>
     27 TracedPicture::AsTraceablePictureAlias(const Picture* original) {
     28   scoped_refptr<TracedPicture> ptr = new TracedPicture(original);
     29   ptr->is_alias_ = true;
     30   return scoped_refptr<base::debug::ConvertableToTraceFormat>(ptr);
     31 }
     32 
     33 void TracedPicture::AppendAsTraceFormat(std::string* out) const {
     34   if (is_alias_)
     35     AppendPictureAlias(out);
     36   else
     37     AppendPicture(out);
     38 }
     39 
     40 void TracedPicture::AppendPictureAlias(std::string* out) const {
     41   scoped_ptr<base::DictionaryValue> alias(new base::DictionaryValue());
     42   alias->SetString("id_ref", base::StringPrintf("%p", picture_.get()));
     43 
     44   scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
     45   res->Set("alias", alias.release());
     46 
     47   std::string tmp;
     48   base::JSONWriter::Write(res.get(), &tmp);
     49   out->append(tmp);
     50 }
     51 
     52 void TracedPicture::AppendPicture(std::string* out) const {
     53   scoped_ptr<base::Value> value = picture_->AsValue();
     54   std::string tmp;
     55   base::JSONWriter::Write(value.get(), &tmp);
     56   out->append(tmp);
     57 }
     58 
     59 }  // namespace cc
     60