1// Copyright 2012 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/quads/shared_quad_state.h"
6
7#include "base/values.h"
8#include "cc/base/math_util.h"
9#include "cc/debug/traced_value.h"
10
11namespace cc {
12
13SharedQuadState::SharedQuadState() : is_clipped(false), opacity(0.f) {}
14
15SharedQuadState::~SharedQuadState() {
16  TRACE_EVENT_OBJECT_DELETED_WITH_ID(
17      TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
18      "cc::SharedQuadState", this);
19}
20
21scoped_ptr<SharedQuadState> SharedQuadState::Create() {
22  return make_scoped_ptr(new SharedQuadState);
23}
24
25scoped_ptr<SharedQuadState> SharedQuadState::Copy() const {
26  return make_scoped_ptr(new SharedQuadState(*this));
27}
28
29void SharedQuadState::SetAll(
30    const gfx::Transform& content_to_target_transform,
31    gfx::Size content_bounds,
32    gfx::Rect visible_content_rect,
33    gfx::Rect clip_rect,
34    bool is_clipped,
35    float opacity) {
36  this->content_to_target_transform = content_to_target_transform;
37  this->content_bounds = content_bounds;
38  this->visible_content_rect = visible_content_rect;
39  this->clip_rect = clip_rect;
40  this->is_clipped = is_clipped;
41  this->opacity = opacity;
42}
43
44scoped_ptr<base::Value> SharedQuadState::AsValue() const {
45  scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
46  value->Set("transform",
47             MathUtil::AsValue(content_to_target_transform).release());
48  value->Set("layer_content_bounds",
49             MathUtil::AsValue(content_bounds).release());
50  value->Set("layer_visible_content_rect",
51             MathUtil::AsValue(visible_content_rect).release());
52  value->SetBoolean("is_clipped", is_clipped);
53  value->Set("clip_rect", MathUtil::AsValue(clip_rect).release());
54  value->SetDouble("opacity", opacity);
55  TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
56      TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
57      value.get(), "cc::SharedQuadState", this);
58  return value.PassAs<base::Value>();
59}
60
61}  // namespace cc
62