Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / cc / resources / managed_tile_state.cc
blob7109237b6127b5b2b1f1c3c193f5c0dbe63acad5
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"
7 #include <limits>
8 #include <string>
10 #include "base/debug/trace_event_argument.h"
11 #include "cc/base/math_util.h"
13 namespace cc {
15 std::string ManagedTileBinToString(ManagedTileBin bin) {
16 switch (bin) {
17 case NOW_AND_READY_TO_DRAW_BIN:
18 return "NOW_AND_READY_TO_DRAW_BIN";
19 case NOW_BIN:
20 return "NOW_BIN";
21 case SOON_BIN:
22 return "SOON_BIN";
23 case EVENTUALLY_AND_ACTIVE_BIN:
24 return "EVENTUALLY_AND_ACTIVE_BIN";
25 case EVENTUALLY_BIN:
26 return "EVENTUALLY_BIN";
27 case AT_LAST_AND_ACTIVE_BIN:
28 return "AT_LAST_AND_ACTIVE_BIN";
29 case AT_LAST_BIN:
30 return "AT_LAST_BIN";
31 case NEVER_BIN:
32 return "NEVER_BIN";
33 case NUM_BINS:
34 NOTREACHED();
35 return "Invalid Bin (NUM_BINS)";
37 return "Invalid Bin (UNKNOWN)";
40 ManagedTileState::ManagedTileState()
41 : raster_mode(LOW_QUALITY_RASTER_MODE),
42 bin(NEVER_BIN),
43 resolution(NON_IDEAL_RESOLUTION),
44 required_for_activation(false),
45 priority_bin(TilePriority::EVENTUALLY),
46 distance_to_visible(std::numeric_limits<float>::infinity()),
47 visible_and_ready_to_draw(false),
48 scheduled_priority(0) {}
50 ManagedTileState::TileVersion::TileVersion()
51 : mode_(RESOURCE_MODE), solid_color_(SK_ColorWHITE) {
54 ManagedTileState::TileVersion::~TileVersion() { DCHECK(!resource_); }
56 bool ManagedTileState::TileVersion::IsReadyToDraw() const {
57 switch (mode_) {
58 case RESOURCE_MODE:
59 return !!resource_;
60 case SOLID_COLOR_MODE:
61 case PICTURE_PILE_MODE:
62 return true;
64 NOTREACHED();
65 return false;
68 size_t ManagedTileState::TileVersion::GPUMemoryUsageInBytes() const {
69 if (!resource_)
70 return 0;
71 return resource_->bytes();
74 ManagedTileState::~ManagedTileState() {}
76 void ManagedTileState::AsValueInto(base::debug::TracedValue* state) const {
77 bool has_resource = false;
78 bool has_active_task = false;
79 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
80 has_resource |= (tile_versions[mode].resource_.get() != 0);
81 has_active_task |= (tile_versions[mode].raster_task_.get() != 0);
84 bool is_using_gpu_memory = has_resource || has_active_task;
86 state->SetBoolean("has_resource", has_resource);
87 state->SetBoolean("is_using_gpu_memory", is_using_gpu_memory);
88 state->SetString("bin", ManagedTileBinToString(bin));
89 state->SetString("resolution", TileResolutionToString(resolution));
90 state->SetString("priority_bin", TilePriorityBinToString(priority_bin));
91 state->SetDouble("distance_to_visible",
92 MathUtil::AsFloatSafely(distance_to_visible));
93 state->SetBoolean("required_for_activation", required_for_activation);
94 state->SetBoolean(
95 "is_solid_color",
96 tile_versions[raster_mode].mode_ == TileVersion::SOLID_COLOR_MODE);
97 state->SetBoolean(
98 "is_transparent",
99 tile_versions[raster_mode].mode_ == TileVersion::SOLID_COLOR_MODE &&
100 !SkColorGetA(tile_versions[raster_mode].solid_color_));
101 state->SetInteger("scheduled_priority", scheduled_priority);
104 } // namespace cc