Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / cc / resources / tile.cc
blob4cbc7586ec2e84b5f7df89d315a8a6fa6ec6b33e
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/resources/tile.h"
7 #include <algorithm>
9 #include "base/debug/trace_event_argument.h"
10 #include "cc/base/math_util.h"
11 #include "cc/debug/traced_value.h"
12 #include "cc/resources/tile_manager.h"
13 #include "third_party/khronos/GLES2/gl2.h"
15 namespace cc {
17 Tile::Id Tile::s_next_id_ = 0;
19 Tile::Tile(TileManager* tile_manager,
20 RasterSource* raster_source,
21 const gfx::Size& tile_size,
22 const gfx::Rect& content_rect,
23 float contents_scale,
24 int layer_id,
25 int source_frame_number,
26 int flags)
27 : RefCountedManaged<Tile>(tile_manager),
28 tile_manager_(tile_manager),
29 size_(tile_size),
30 content_rect_(content_rect),
31 contents_scale_(contents_scale),
32 layer_id_(layer_id),
33 source_frame_number_(source_frame_number),
34 flags_(flags),
35 is_shared_(false),
36 tiling_i_index_(-1),
37 tiling_j_index_(-1),
38 required_for_activation_(false),
39 required_for_draw_(false),
40 id_(s_next_id_++) {
41 set_raster_source(raster_source);
42 for (int i = 0; i < NUM_TREES; i++)
43 is_occluded_[i] = false;
46 Tile::~Tile() {
47 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
48 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
49 "cc::Tile", this);
52 void Tile::AsValueInto(base::debug::TracedValue* res) const {
53 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
54 TRACE_DISABLED_BY_DEFAULT("cc.debug"), res, "cc::Tile", this);
55 TracedValue::SetIDRef(raster_source_.get(), res, "picture_pile");
56 res->SetDouble("contents_scale", contents_scale_);
58 res->BeginArray("content_rect");
59 MathUtil::AddToTracedValue(content_rect_, res);
60 res->EndArray();
62 res->SetInteger("layer_id", layer_id_);
64 res->BeginDictionary("active_priority");
65 priority_[ACTIVE_TREE].AsValueInto(res);
66 res->EndDictionary();
68 res->BeginDictionary("pending_priority");
69 priority_[PENDING_TREE].AsValueInto(res);
70 res->EndDictionary();
72 res->BeginDictionary("managed_state");
73 managed_state_.AsValueInto(res);
74 res->EndDictionary();
76 res->SetBoolean("use_picture_analysis", use_picture_analysis());
78 res->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
81 size_t Tile::GPUMemoryUsageInBytes() const {
82 if (managed_state_.draw_info.resource_)
83 return managed_state_.draw_info.resource_->bytes();
84 return 0;
87 bool Tile::HasRasterTask() const {
88 return !!managed_state_.raster_task.get();
91 } // namespace cc