Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / resources / tile_priority.cc
blob3bf29680766bd782d3ac414a3b47f55d60851c96
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"
10 namespace cc {
12 scoped_ptr<base::Value> WhichTreeAsValue(WhichTree tree) {
13 switch (tree) {
14 case ACTIVE_TREE:
15 return scoped_ptr<base::Value>(new base::StringValue("ACTIVE_TREE"));
16 case PENDING_TREE:
17 return scoped_ptr<base::Value>(new base::StringValue("PENDING_TREE"));
18 default:
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) {
27 switch (resolution) {
28 case LOW_RESOLUTION:
29 return scoped_ptr<base::Value>(new base::StringValue("LOW_RESOLUTION"));
30 case HIGH_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) {
42 switch (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) {
67 switch (policy) {
68 case ALLOW_NOTHING:
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"));
76 case ALLOW_ANYTHING:
77 return scoped_ptr<base::Value>(new base::StringValue(
78 "ALLOW_ANYTHING"));
79 default:
80 DCHECK(false) << "Unrecognized policy value";
81 return scoped_ptr<base::Value>(new base::StringValue(
82 "<unknown>"));
86 scoped_ptr<base::Value> TreePriorityAsValue(TreePriority prio) {
87 switch (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(
100 "<unknown>"));
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>();
114 } // namespace cc