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::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
,
24 int source_frame_number
,
26 : tile_manager_(tile_manager
),
27 desired_texture_size_(desired_texture_size
),
28 content_rect_(content_rect
),
29 contents_scale_(contents_scale
),
31 source_frame_number_(source_frame_number
),
35 required_for_activation_(false),
36 required_for_draw_(false),
39 scheduled_priority_(0) {
43 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
44 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
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
74 return ResourceUtil::UncheckedSizeInBytes
<size_t>(
75 draw_info_
.resource_
->size(), draw_info_
.resource_
->format());
80 void Tile::Deleter::operator()(Tile
* tile
) const {
81 TileManager
* tile_manager
= tile
->tile_manager_
;
82 tile_manager
->Release(tile
);