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<Picture> picture)
     15   : picture_(picture),
     16     is_alias_(false) {
     17 }
     18 
     19 TracedPicture::~TracedPicture() {
     20 }
     21 
     22 scoped_refptr<base::debug::ConvertableToTraceFormat>
     23     TracedPicture::AsTraceablePicture(Picture* picture) {
     24   return scoped_refptr<base::debug::ConvertableToTraceFormat>(
     25       new TracedPicture(picture));
     26 }
     27 
     28 scoped_refptr<base::debug::ConvertableToTraceFormat>
     29     TracedPicture::AsTraceablePictureAlias(Picture* original) {
     30   scoped_refptr<TracedPicture> ptr = new TracedPicture(original);
     31   ptr->is_alias_ = true;
     32   return scoped_refptr<base::debug::ConvertableToTraceFormat>(ptr);
     33 }
     34 
     35 void TracedPicture::AppendAsTraceFormat(std::string* out) const {
     36   if (is_alias_)
     37     AppendPictureAlias(out);
     38   else
     39     AppendPicture(out);
     40 }
     41 
     42 void TracedPicture::AppendPictureAlias(std::string* out) const {
     43   scoped_ptr<base::DictionaryValue> alias(new base::DictionaryValue());
     44   alias->SetString("id_ref", base::StringPrintf("%p", picture_.get()));
     45 
     46   scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
     47   res->Set("alias", alias.release());
     48 
     49   std::string tmp;
     50   base::JSONWriter::Write(res.get(), &tmp);
     51   out->append(tmp);
     52 }
     53 
     54 void TracedPicture::AppendPicture(std::string* out) const {
     55   scoped_ptr<base::Value> value = picture_->AsValue();
     56   std::string tmp;
     57   base::JSONWriter::Write(value.get(), &tmp);
     58   out->append(tmp);
     59 }
     60 
     61 }  // namespace cc
     62