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/resources/tile_priority.h" 6 7 #include "base/values.h" 8 #include "cc/base/math_util.h" 9 10 namespace cc { 11 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>")); 22 } 23 } 24 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")); 35 } 36 DCHECK(false) << "Unrecognized TileResolution value " << resolution; 37 return scoped_ptr<base::Value>(new base::StringValue( 38 "<unknown TileResolution value>")); 39 } 40 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")); 50 } 51 DCHECK(false) << "Unrecognized TilePriority::PriorityBin value " << bin; 52 return scoped_ptr<base::Value>(base::Value::CreateStringValue( 53 "<unknown TilePriority::PriorityBin value>")); 54 } 55 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>(); 63 } 64 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>")); 83 } 84 } 85 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")); 97 } 98 DCHECK(false) << "Unrecognized priority value " << prio; 99 return scoped_ptr<base::Value>(new base::StringValue( 100 "<unknown>")); 101 } 102 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>(); 112 } 113 114 } // namespace cc 115