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.
4
5 #include "cc/resources/tile.h"
6
7 #include "cc/base/math_util.h"
8 #include "cc/debug/traced_value.h"
9 #include "cc/resources/tile_manager.h"
10 #include "third_party/khronos/GLES2/gl2.h"
11
12 namespace cc {
13
14 Tile::Id Tile::s_next_id_ = 0;
15
Tile(TileManager * tile_manager,PicturePileImpl * picture_pile,gfx::Size tile_size,gfx::Rect content_rect,gfx::Rect opaque_rect,float contents_scale,int layer_id,int source_frame_number,int flags)16 Tile::Tile(TileManager* tile_manager,
17 PicturePileImpl* picture_pile,
18 gfx::Size tile_size,
19 gfx::Rect content_rect,
20 gfx::Rect opaque_rect,
21 float contents_scale,
22 int layer_id,
23 int source_frame_number,
24 int flags)
25 : RefCountedManaged<Tile>(tile_manager),
26 tile_manager_(tile_manager),
27 tile_size_(tile_size),
28 content_rect_(content_rect),
29 contents_scale_(contents_scale),
30 opaque_rect_(opaque_rect),
31 layer_id_(layer_id),
32 source_frame_number_(source_frame_number),
33 flags_(flags),
34 id_(s_next_id_++) {
35 set_picture_pile(picture_pile);
36 }
37
~Tile()38 Tile::~Tile() {
39 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
40 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
41 "cc::Tile", this);
42 }
43
SetPriority(WhichTree tree,const TilePriority & priority)44 void Tile::SetPriority(WhichTree tree, const TilePriority& priority) {
45 if (priority == priority_[tree])
46 return;
47
48 priority_[tree] = priority;
49 tile_manager_->DidChangeTilePriority(this);
50 }
51
MarkRequiredForActivation()52 void Tile::MarkRequiredForActivation() {
53 if (priority_[PENDING_TREE].required_for_activation)
54 return;
55
56 priority_[PENDING_TREE].required_for_activation = true;
57 tile_manager_->DidChangeTilePriority(this);
58 }
59
AsValue() const60 scoped_ptr<base::Value> Tile::AsValue() const {
61 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
62 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
63 TRACE_DISABLED_BY_DEFAULT("cc.debug"), res.get(), "cc::Tile", this);
64 res->Set("picture_pile",
65 TracedValue::CreateIDRef(picture_pile_.get()).release());
66 res->SetDouble("contents_scale", contents_scale_);
67 res->Set("content_rect", MathUtil::AsValue(content_rect_).release());
68 res->SetInteger("layer_id", layer_id_);
69 res->Set("active_priority", priority_[ACTIVE_TREE].AsValue().release());
70 res->Set("pending_priority", priority_[PENDING_TREE].AsValue().release());
71 res->Set("managed_state", managed_state_.AsValue().release());
72 res->SetBoolean("can_use_lcd_text", can_use_lcd_text());
73 res->SetBoolean("use_gpu_rasterization", use_gpu_rasterization());
74 return res.PassAs<base::Value>();
75 }
76
GPUMemoryUsageInBytes() const77 size_t Tile::GPUMemoryUsageInBytes() const {
78 size_t total_size = 0;
79 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode)
80 total_size += managed_state_.tile_versions[mode].GPUMemoryUsageInBytes();
81 return total_size;
82 }
83
84 } // namespace cc
85