Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / cc / tiles / tile.cc
blobad50dd1c91f502d2033a3fabab00d482d3a06175
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/tiles/tile.h"
7 #include <algorithm>
9 #include "base/numerics/safe_conversions.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "cc/base/math_util.h"
12 #include "cc/debug/traced_value.h"
13 #include "cc/tiles/tile_manager.h"
15 namespace cc {
17 Tile::Id Tile::s_next_id_ = 1;
19 Tile::Tile(TileManager* tile_manager,
20 const gfx::Size& desired_texture_size,
21 const gfx::Rect& content_rect,
22 float contents_scale,
23 int layer_id,
24 int source_frame_number,
25 int flags)
26 : tile_manager_(tile_manager),
27 desired_texture_size_(desired_texture_size),
28 content_rect_(content_rect),
29 contents_scale_(contents_scale),
30 layer_id_(layer_id),
31 source_frame_number_(source_frame_number),
32 flags_(flags),
33 tiling_i_index_(-1),
34 tiling_j_index_(-1),
35 required_for_activation_(false),
36 required_for_draw_(false),
37 id_(s_next_id_++),
38 invalidated_id_(0),
39 scheduled_priority_(0) {
42 Tile::~Tile() {
43 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
44 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
45 "cc::Tile", this);
48 void Tile::AsValueInto(base::trace_event::TracedValue* value) const {
49 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
50 TRACE_DISABLED_BY_DEFAULT("cc.debug"), value, "cc::Tile", this);
51 value->SetDouble("contents_scale", contents_scale_);
53 MathUtil::AddToTracedValue("content_rect", content_rect_, value);
55 value->SetInteger("layer_id", layer_id_);
57 value->BeginDictionary("draw_info");
58 draw_info_.AsValueInto(value);
59 value->EndDictionary();
61 value->SetBoolean("has_resource", draw_info().has_resource());
62 value->SetBoolean("is_using_gpu_memory",
63 draw_info().has_resource() || HasRasterTask());
64 value->SetInteger("scheduled_priority", scheduled_priority_);
65 value->SetBoolean("use_picture_analysis", use_picture_analysis());
66 value->SetInteger("gpu_memory_usage",
67 base::saturated_cast<int>(GPUMemoryUsageInBytes()));
70 size_t Tile::GPUMemoryUsageInBytes() const {
71 if (draw_info_.resource_) {
72 // We can use UncheckedSizeInBytes, since the tile size is determined by the
73 // compositor.
74 return ResourceUtil::UncheckedSizeInBytes<size_t>(
75 draw_info_.resource_->size(), draw_info_.resource_->format());
77 return 0;
80 void Tile::Deleter::operator()(Tile* tile) const {
81 TileManager* tile_manager = tile->tile_manager_;
82 tile_manager->Release(tile);
85 } // namespace cc