1 // Copyright 2013 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/managed_tile_state.h"
9 #include "cc/base/math_util.h"
13 scoped_ptr
<base::Value
> ManagedTileBinAsValue(ManagedTileBin bin
) {
15 case NOW_AND_READY_TO_DRAW_BIN
:
16 return scoped_ptr
<base::Value
>(
17 new base::StringValue("NOW_AND_READY_TO_DRAW_BIN"));
19 return scoped_ptr
<base::Value
>(new base::StringValue("NOW_BIN"));
21 return scoped_ptr
<base::Value
>(
22 new base::StringValue("SOON_BIN"));
23 case EVENTUALLY_AND_ACTIVE_BIN
:
24 return scoped_ptr
<base::Value
>(
25 new base::StringValue("EVENTUALLY_AND_ACTIVE_BIN"));
27 return scoped_ptr
<base::Value
>(
28 new base::StringValue("EVENTUALLY_BIN"));
29 case AT_LAST_AND_ACTIVE_BIN
:
30 return scoped_ptr
<base::Value
>(
31 new base::StringValue("AT_LAST_AND_ACTIVE_BIN"));
33 return scoped_ptr
<base::Value
>(
34 new base::StringValue("AT_LAST_BIN"));
36 return scoped_ptr
<base::Value
>(
37 new base::StringValue("NEVER_BIN"));
40 return scoped_ptr
<base::Value
>(
41 new base::StringValue("Invalid Bin (NUM_BINS)"));
43 return scoped_ptr
<base::Value
>(
44 new base::StringValue("Invalid Bin (UNKNOWN)"));
47 ManagedTileState::ManagedTileState()
48 : raster_mode(LOW_QUALITY_RASTER_MODE
),
50 resolution(NON_IDEAL_RESOLUTION
),
51 required_for_activation(false),
52 priority_bin(TilePriority::EVENTUALLY
),
53 distance_to_visible(std::numeric_limits
<float>::infinity()),
54 visible_and_ready_to_draw(false),
55 scheduled_priority(0) {}
57 ManagedTileState::TileVersion::TileVersion()
58 : mode_(RESOURCE_MODE
), has_text_(false) {}
60 ManagedTileState::TileVersion::~TileVersion() { DCHECK(!resource_
); }
62 bool ManagedTileState::TileVersion::IsReadyToDraw() const {
66 case SOLID_COLOR_MODE
:
67 case PICTURE_PILE_MODE
:
74 size_t ManagedTileState::TileVersion::GPUMemoryUsageInBytes() const {
77 return resource_
->bytes();
80 ManagedTileState::~ManagedTileState() {}
82 scoped_ptr
<base::Value
> ManagedTileState::AsValue() const {
83 bool has_resource
= false;
84 bool has_active_task
= false;
85 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
) {
86 has_resource
|= (tile_versions
[mode
].resource_
.get() != 0);
87 has_active_task
|= (tile_versions
[mode
].raster_task_
.get() != 0);
90 bool is_using_gpu_memory
= has_resource
|| has_active_task
;
92 scoped_ptr
<base::DictionaryValue
> state(new base::DictionaryValue());
93 state
->SetBoolean("has_resource", has_resource
);
94 state
->SetBoolean("is_using_gpu_memory", is_using_gpu_memory
);
95 state
->Set("bin", ManagedTileBinAsValue(bin
).release());
96 state
->Set("resolution", TileResolutionAsValue(resolution
).release());
97 state
->Set("priority_bin", TilePriorityBinAsValue(priority_bin
).release());
98 state
->Set("distance_to_visible",
99 MathUtil::AsValueSafely(distance_to_visible
).release());
100 state
->SetBoolean("required_for_activation", required_for_activation
);
103 tile_versions
[raster_mode
].mode_
== TileVersion::SOLID_COLOR_MODE
);
106 tile_versions
[raster_mode
].mode_
== TileVersion::SOLID_COLOR_MODE
&&
107 !SkColorGetA(tile_versions
[raster_mode
].solid_color_
));
108 state
->SetInteger("scheduled_priority", scheduled_priority
);
109 return state
.PassAs
<base::Value
>();