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"
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"
17 Tile::Tile(TileManager
* tile_manager
,
18 const CreateInfo
& info
,
20 int source_frame_number
,
22 : tile_manager_(tile_manager
),
23 content_rect_(info
.content_rect
),
24 enclosing_layer_rect_(info
.enclosing_layer_rect
),
25 contents_scale_(info
.contents_scale
),
27 source_frame_number_(source_frame_number
),
29 tiling_i_index_(info
.tiling_i_index
),
30 tiling_j_index_(info
.tiling_j_index
),
31 required_for_activation_(false),
32 required_for_draw_(false),
33 id_(tile_manager
->GetUniqueTileId()),
35 scheduled_priority_(0) {}
38 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
39 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
43 void Tile::AsValueInto(base::trace_event::TracedValue
* value
) const {
44 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
45 TRACE_DISABLED_BY_DEFAULT("cc.debug"), value
, "cc::Tile", this);
46 value
->SetDouble("contents_scale", contents_scale_
);
48 MathUtil::AddToTracedValue("content_rect", content_rect_
, value
);
50 value
->SetInteger("layer_id", layer_id_
);
52 value
->BeginDictionary("draw_info");
53 draw_info_
.AsValueInto(value
);
54 value
->EndDictionary();
56 value
->SetBoolean("has_resource", draw_info().has_resource());
57 value
->SetBoolean("is_using_gpu_memory",
58 draw_info().has_resource() || HasRasterTask());
59 value
->SetInteger("scheduled_priority", scheduled_priority_
);
60 value
->SetBoolean("use_picture_analysis", use_picture_analysis());
61 value
->SetInteger("gpu_memory_usage",
62 base::saturated_cast
<int>(GPUMemoryUsageInBytes()));
65 size_t Tile::GPUMemoryUsageInBytes() const {
66 if (draw_info_
.resource_
) {
67 // We can use UncheckedSizeInBytes, since the tile size is determined by the
69 return ResourceUtil::UncheckedSizeInBytes
<size_t>(
70 draw_info_
.resource_
->size(), draw_info_
.resource_
->format());
75 void Tile::Deleter::operator()(Tile
* tile
) const {
76 tile
->tile_manager_
->Release(tile
);