Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / cc / resources / tile.cc
blob3c5ac75d5f6622e152830b855b1b48e8369c9229
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 PicturePileImpl* picture_pile,
21 const gfx::Size& tile_size,
22 const gfx::Rect& content_rect,
23 const gfx::Rect& opaque_rect,
24 float contents_scale,
25 int layer_id,
26 int source_frame_number,
27 int flags)
28 : RefCountedManaged<Tile>(tile_manager),
29 tile_manager_(tile_manager),
30 size_(tile_size),
31 content_rect_(content_rect),
32 contents_scale_(contents_scale),
33 opaque_rect_(opaque_rect),
34 layer_id_(layer_id),
35 source_frame_number_(source_frame_number),
36 flags_(flags),
37 is_shared_(false),
38 id_(s_next_id_++) {
39 set_picture_pile(picture_pile);
40 for (int i = 0; i < NUM_TREES; i++)
41 is_occluded_[i] = false;
44 Tile::~Tile() {
45 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
46 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
47 "cc::Tile", this);
50 void Tile::SetPriority(WhichTree tree, const TilePriority& priority) {
51 if (priority == priority_[tree])
52 return;
54 priority_[tree] = priority;
55 tile_manager_->DidChangeTilePriority(this);
58 void Tile::MarkRequiredForActivation() {
59 if (priority_[PENDING_TREE].required_for_activation)
60 return;
62 priority_[PENDING_TREE].required_for_activation = true;
63 tile_manager_->DidChangeTilePriority(this);
66 void Tile::AsValueInto(base::debug::TracedValue* res) const {
67 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
68 TRACE_DISABLED_BY_DEFAULT("cc.debug"), res, "cc::Tile", this);
69 TracedValue::SetIDRef(picture_pile_.get(), res, "picture_pile");
70 res->SetDouble("contents_scale", contents_scale_);
72 res->BeginArray("content_rect");
73 MathUtil::AddToTracedValue(content_rect_, res);
74 res->EndArray();
76 res->SetInteger("layer_id", layer_id_);
78 res->BeginDictionary("active_priority");
79 priority_[ACTIVE_TREE].AsValueInto(res);
80 res->EndDictionary();
82 res->BeginDictionary("pending_priority");
83 priority_[PENDING_TREE].AsValueInto(res);
84 res->EndDictionary();
86 res->BeginDictionary("managed_state");
87 managed_state_.AsValueInto(res);
88 res->EndDictionary();
90 res->SetBoolean("use_picture_analysis", use_picture_analysis());
92 res->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
95 size_t Tile::GPUMemoryUsageInBytes() const {
96 size_t total_size = 0;
97 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode)
98 total_size += managed_state_.tile_versions[mode].GPUMemoryUsageInBytes();
99 return total_size;
102 RasterMode Tile::DetermineRasterModeForTree(WhichTree tree) const {
103 return DetermineRasterModeForResolution(priority(tree).resolution);
106 RasterMode Tile::DetermineOverallRasterMode() const {
107 return DetermineRasterModeForResolution(managed_state_.resolution);
110 RasterMode Tile::DetermineRasterModeForResolution(
111 TileResolution resolution) const {
112 RasterMode current_mode = managed_state_.raster_mode;
113 RasterMode raster_mode = resolution == LOW_RESOLUTION
114 ? LOW_QUALITY_RASTER_MODE
115 : HIGH_QUALITY_RASTER_MODE;
116 return std::min(raster_mode, current_mode);
119 bool Tile::HasRasterTask() const {
120 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
121 if (managed_state_.tile_versions[mode].raster_task_)
122 return true;
124 return false;
127 } // namespace cc