Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / cc / resources / tile.cc
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 <algorithm>
8
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"
14
15 namespace cc {
16
17 Tile::Id Tile::s_next_id_ = 0;
18
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       id_(s_next_id_++) {
38   set_picture_pile(picture_pile);
39   for (int i = 0; i < NUM_TREES; i++)
40     is_occluded_[i] = false;
41 }
42
43 Tile::~Tile() {
44   TRACE_EVENT_OBJECT_DELETED_WITH_ID(
45       TRACE_DISABLED_BY_DEFAULT("cc.debug"),
46       "cc::Tile", this);
47 }
48
49 void Tile::SetPriority(WhichTree tree, const TilePriority& priority) {
50   if (priority == priority_[tree])
51     return;
52
53   priority_[tree] = priority;
54   tile_manager_->DidChangeTilePriority(this);
55 }
56
57 void Tile::MarkRequiredForActivation() {
58   if (priority_[PENDING_TREE].required_for_activation)
59     return;
60
61   priority_[PENDING_TREE].required_for_activation = true;
62   tile_manager_->DidChangeTilePriority(this);
63 }
64
65 void Tile::AsValueInto(base::debug::TracedValue* res) const {
66   TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
67       TRACE_DISABLED_BY_DEFAULT("cc.debug"), res, "cc::Tile", this);
68   TracedValue::SetIDRef(picture_pile_.get(), res, "picture_pile");
69   res->SetDouble("contents_scale", contents_scale_);
70
71   res->BeginArray("content_rect");
72   MathUtil::AddToTracedValue(content_rect_, res);
73   res->EndArray();
74
75   res->SetInteger("layer_id", layer_id_);
76
77   res->BeginDictionary("active_priority");
78   priority_[ACTIVE_TREE].AsValueInto(res);
79   res->EndDictionary();
80
81   res->BeginDictionary("pending_priority");
82   priority_[PENDING_TREE].AsValueInto(res);
83   res->EndDictionary();
84
85   res->BeginDictionary("managed_state");
86   managed_state_.AsValueInto(res);
87   res->EndDictionary();
88
89   res->SetBoolean("use_picture_analysis", use_picture_analysis());
90
91   res->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
92 }
93
94 size_t Tile::GPUMemoryUsageInBytes() const {
95   size_t total_size = 0;
96   for (int mode = 0; mode < NUM_RASTER_MODES; ++mode)
97     total_size += managed_state_.tile_versions[mode].GPUMemoryUsageInBytes();
98   return total_size;
99 }
100
101 RasterMode Tile::DetermineRasterModeForTree(WhichTree tree) const {
102   return DetermineRasterModeForResolution(priority(tree).resolution);
103 }
104
105 RasterMode Tile::DetermineOverallRasterMode() const {
106   return DetermineRasterModeForResolution(managed_state_.resolution);
107 }
108
109 RasterMode Tile::DetermineRasterModeForResolution(
110     TileResolution resolution) const {
111   RasterMode current_mode = managed_state_.raster_mode;
112   RasterMode raster_mode = resolution == LOW_RESOLUTION
113                                ? LOW_QUALITY_RASTER_MODE
114                                : HIGH_QUALITY_RASTER_MODE;
115   return std::min(raster_mode, current_mode);
116 }
117
118 bool Tile::HasRasterTask() const {
119   for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
120     if (managed_state_.tile_versions[mode].raster_task_)
121       return true;
122   }
123   return false;
124 }
125
126 }  // namespace cc