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.
5 #include "cc/resources/tile_priority.h"
7 #include "base/values.h"
8 #include "cc/base/math_util.h"
12 scoped_ptr
<base::Value
> WhichTreeAsValue(WhichTree tree
) {
15 return scoped_ptr
<base::Value
>(new base::StringValue("ACTIVE_TREE"));
17 return scoped_ptr
<base::Value
>(new base::StringValue("PENDING_TREE"));
19 DCHECK(false) << "Unrecognized WhichTree value " << tree
;
20 return scoped_ptr
<base::Value
>(new base::StringValue(
21 "<unknown WhichTree value>"));
25 scoped_ptr
<base::Value
> TileResolutionAsValue(
26 TileResolution resolution
) {
29 return scoped_ptr
<base::Value
>(new base::StringValue("LOW_RESOLUTION"));
31 return scoped_ptr
<base::Value
>(new base::StringValue("HIGH_RESOLUTION"));
32 case NON_IDEAL_RESOLUTION
:
33 return scoped_ptr
<base::Value
>(new base::StringValue(
34 "NON_IDEAL_RESOLUTION"));
36 DCHECK(false) << "Unrecognized TileResolution value " << resolution
;
37 return scoped_ptr
<base::Value
>(new base::StringValue(
38 "<unknown TileResolution value>"));
41 scoped_ptr
<base::Value
> TilePriorityBinAsValue(TilePriority::PriorityBin bin
) {
43 case TilePriority::NOW
:
44 return scoped_ptr
<base::Value
>(base::Value::CreateStringValue("NOW"));
45 case TilePriority::SOON
:
46 return scoped_ptr
<base::Value
>(base::Value::CreateStringValue("SOON"));
47 case TilePriority::EVENTUALLY
:
48 return scoped_ptr
<base::Value
>(
49 base::Value::CreateStringValue("EVENTUALLY"));
51 DCHECK(false) << "Unrecognized TilePriority::PriorityBin value " << bin
;
52 return scoped_ptr
<base::Value
>(base::Value::CreateStringValue(
53 "<unknown TilePriority::PriorityBin value>"));
56 scoped_ptr
<base::Value
> TilePriority::AsValue() const {
57 scoped_ptr
<base::DictionaryValue
> state(new base::DictionaryValue());
58 state
->Set("resolution", TileResolutionAsValue(resolution
).release());
59 state
->Set("priority_bin", TilePriorityBinAsValue(priority_bin
).release());
60 state
->Set("distance_to_visible",
61 MathUtil::AsValueSafely(distance_to_visible
).release());
62 return state
.PassAs
<base::Value
>();
65 scoped_ptr
<base::Value
> TileMemoryLimitPolicyAsValue(
66 TileMemoryLimitPolicy policy
) {
69 return scoped_ptr
<base::Value
>(new base::StringValue("ALLOW_NOTHING"));
70 case ALLOW_ABSOLUTE_MINIMUM
:
71 return scoped_ptr
<base::Value
>(new base::StringValue(
72 "ALLOW_ABSOLUTE_MINIMUM"));
73 case ALLOW_PREPAINT_ONLY
:
74 return scoped_ptr
<base::Value
>(new base::StringValue(
75 "ALLOW_PREPAINT_ONLY"));
77 return scoped_ptr
<base::Value
>(new base::StringValue(
80 DCHECK(false) << "Unrecognized policy value";
81 return scoped_ptr
<base::Value
>(new base::StringValue(
86 scoped_ptr
<base::Value
> TreePriorityAsValue(TreePriority prio
) {
88 case SAME_PRIORITY_FOR_BOTH_TREES
:
89 return scoped_ptr
<base::Value
>(new base::StringValue(
90 "SAME_PRIORITY_FOR_BOTH_TREES"));
91 case SMOOTHNESS_TAKES_PRIORITY
:
92 return scoped_ptr
<base::Value
>(new base::StringValue(
93 "SMOOTHNESS_TAKES_PRIORITY"));
94 case NEW_CONTENT_TAKES_PRIORITY
:
95 return scoped_ptr
<base::Value
>(new base::StringValue(
96 "NEW_CONTENT_TAKES_PRIORITY"));
98 DCHECK(false) << "Unrecognized priority value " << prio
;
99 return scoped_ptr
<base::Value
>(new base::StringValue(
103 scoped_ptr
<base::Value
> GlobalStateThatImpactsTilePriority::AsValue() const {
104 scoped_ptr
<base::DictionaryValue
> state(new base::DictionaryValue());
105 state
->Set("memory_limit_policy",
106 TileMemoryLimitPolicyAsValue(memory_limit_policy
).release());
107 state
->SetInteger("soft_memory_limit_in_bytes", soft_memory_limit_in_bytes
);
108 state
->SetInteger("hard_memory_limit_in_bytes", hard_memory_limit_in_bytes
);
109 state
->SetInteger("num_resources_limit", num_resources_limit
);
110 state
->Set("tree_priority", TreePriorityAsValue(tree_priority
).release());
111 return state
.PassAs
<base::Value
>();