Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / quads / shared_quad_state.cc
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
11 namespace cc {
12
13 SharedQuadState::SharedQuadState()
14     : is_clipped(false), opacity(0.f), blend_mode(SkXfermode::kSrcOver_Mode) {}
15
16 SharedQuadState::~SharedQuadState() {
17   TRACE_EVENT_OBJECT_DELETED_WITH_ID(
18       TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
19       "cc::SharedQuadState", this);
20 }
21
22 scoped_ptr<SharedQuadState> SharedQuadState::Create() {
23   return make_scoped_ptr(new SharedQuadState);
24 }
25
26 scoped_ptr<SharedQuadState> SharedQuadState::Copy() const {
27   return make_scoped_ptr(new SharedQuadState(*this));
28 }
29
30 void SharedQuadState::CopyFrom(const SharedQuadState* other) {
31   *this = *other;
32 }
33
34 void SharedQuadState::SetAll(const gfx::Transform& content_to_target_transform,
35                              const gfx::Size& content_bounds,
36                              const gfx::Rect& visible_content_rect,
37                              const gfx::Rect& clip_rect,
38                              bool is_clipped,
39                              float opacity,
40                              SkXfermode::Mode blend_mode) {
41   this->content_to_target_transform = content_to_target_transform;
42   this->content_bounds = content_bounds;
43   this->visible_content_rect = visible_content_rect;
44   this->clip_rect = clip_rect;
45   this->is_clipped = is_clipped;
46   this->opacity = opacity;
47   this->blend_mode = blend_mode;
48 }
49
50 scoped_ptr<base::Value> SharedQuadState::AsValue() const {
51   scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
52   value->Set("transform",
53              MathUtil::AsValue(content_to_target_transform).release());
54   value->Set("layer_content_bounds",
55              MathUtil::AsValue(content_bounds).release());
56   value->Set("layer_visible_content_rect",
57              MathUtil::AsValue(visible_content_rect).release());
58   value->SetBoolean("is_clipped", is_clipped);
59   value->Set("clip_rect", MathUtil::AsValue(clip_rect).release());
60   value->SetDouble("opacity", opacity);
61   value->SetString("blend_mode", SkXfermode::ModeName(blend_mode));
62   TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
63       TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
64       value.get(), "cc::SharedQuadState", this);
65   return value.PassAs<base::Value>();
66 }
67
68 }  // namespace cc