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"
9 #include "cc/base/math_util.h"
10 #include "cc/debug/traced_value.h"
11 #include "cc/resources/tile_manager.h"
12 #include "third_party/khronos/GLES2/gl2.h"
16 Tile::Id
Tile::s_next_id_
= 0;
18 Tile::Tile(TileManager
* tile_manager
,
19 PicturePileImpl
* picture_pile
,
20 const gfx::Size
& tile_size
,
21 const gfx::Rect
& content_rect
,
22 const gfx::Rect
& opaque_rect
,
25 int source_frame_number
,
27 : RefCountedManaged
<Tile
>(tile_manager
),
28 tile_manager_(tile_manager
),
29 tile_size_(tile_size
),
30 content_rect_(content_rect
),
31 contents_scale_(contents_scale
),
32 opaque_rect_(opaque_rect
),
34 source_frame_number_(source_frame_number
),
37 set_picture_pile(picture_pile
);
41 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
42 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
46 void Tile::SetPriority(WhichTree tree
, const TilePriority
& priority
) {
47 if (priority
== priority_
[tree
])
50 priority_
[tree
] = priority
;
51 tile_manager_
->DidChangeTilePriority(this);
54 void Tile::MarkRequiredForActivation() {
55 if (priority_
[PENDING_TREE
].required_for_activation
)
58 priority_
[PENDING_TREE
].required_for_activation
= true;
59 tile_manager_
->DidChangeTilePriority(this);
62 scoped_ptr
<base::Value
> Tile::AsValue() const {
63 scoped_ptr
<base::DictionaryValue
> res(new base::DictionaryValue());
64 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
65 TRACE_DISABLED_BY_DEFAULT("cc.debug"), res
.get(), "cc::Tile", this);
66 res
->Set("picture_pile",
67 TracedValue::CreateIDRef(picture_pile_
.get()).release());
68 res
->SetDouble("contents_scale", contents_scale_
);
69 res
->Set("content_rect", MathUtil::AsValue(content_rect_
).release());
70 res
->SetInteger("layer_id", layer_id_
);
71 res
->Set("active_priority", priority_
[ACTIVE_TREE
].AsValue().release());
72 res
->Set("pending_priority", priority_
[PENDING_TREE
].AsValue().release());
73 res
->Set("managed_state", managed_state_
.AsValue().release());
74 res
->SetBoolean("can_use_lcd_text", can_use_lcd_text());
75 res
->SetBoolean("use_gpu_rasterization", use_gpu_rasterization());
76 return res
.PassAs
<base::Value
>();
79 size_t Tile::GPUMemoryUsageInBytes() const {
80 size_t total_size
= 0;
81 for (int mode
= 0; mode
< NUM_RASTER_MODES
; ++mode
)
82 total_size
+= managed_state_
.tile_versions
[mode
].GPUMemoryUsageInBytes();
86 RasterMode
Tile::DetermineRasterModeForTree(WhichTree tree
) const {
87 return DetermineRasterModeForResolution(priority(tree
).resolution
);
90 RasterMode
Tile::DetermineOverallRasterMode() const {
91 return DetermineRasterModeForResolution(managed_state_
.resolution
);
94 RasterMode
Tile::DetermineRasterModeForResolution(
95 TileResolution resolution
) const {
96 RasterMode current_mode
= managed_state_
.raster_mode
;
97 RasterMode raster_mode
= HIGH_QUALITY_RASTER_MODE
;
98 if (resolution
== LOW_RESOLUTION
)
99 raster_mode
= LOW_QUALITY_RASTER_MODE
;
100 else if (can_use_lcd_text())
101 raster_mode
= HIGH_QUALITY_RASTER_MODE
;
102 else if (managed_state_
.tile_versions
[current_mode
].has_text_
||
103 !managed_state_
.tile_versions
[current_mode
].IsReadyToDraw())
104 raster_mode
= HIGH_QUALITY_NO_LCD_RASTER_MODE
;
106 return std::min(raster_mode
, current_mode
);