summaryrefslogtreecommitdiffstats
path: root/cc/resources/tile.cc
blob: 87e1e46eb2b1ce213839a1b6883612111fc11d0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/resources/tile.h"

#include <algorithm>

#include "base/debug/trace_event_argument.h"
#include "cc/base/math_util.h"
#include "cc/debug/traced_value.h"
#include "cc/resources/tile_manager.h"
#include "third_party/khronos/GLES2/gl2.h"

namespace cc {

Tile::Id Tile::s_next_id_ = 0;

Tile::Tile(TileManager* tile_manager,
           PicturePileImpl* picture_pile,
           const gfx::Size& tile_size,
           const gfx::Rect& content_rect,
           const gfx::Rect& opaque_rect,
           float contents_scale,
           int layer_id,
           int source_frame_number,
           int flags)
    : RefCountedManaged<Tile>(tile_manager),
      tile_manager_(tile_manager),
      size_(tile_size),
      content_rect_(content_rect),
      contents_scale_(contents_scale),
      opaque_rect_(opaque_rect),
      layer_id_(layer_id),
      source_frame_number_(source_frame_number),
      flags_(flags),
      id_(s_next_id_++) {
  set_picture_pile(picture_pile);
  for (int i = 0; i < NUM_TREES; i++)
    is_occluded_[i] = false;
}

Tile::~Tile() {
  TRACE_EVENT_OBJECT_DELETED_WITH_ID(
      TRACE_DISABLED_BY_DEFAULT("cc.debug"),
      "cc::Tile", this);
}

void Tile::SetPriority(WhichTree tree, const TilePriority& priority) {
  if (priority == priority_[tree])
    return;

  priority_[tree] = priority;
  tile_manager_->DidChangeTilePriority(this);
}

void Tile::MarkRequiredForActivation() {
  if (priority_[PENDING_TREE].required_for_activation)
    return;

  priority_[PENDING_TREE].required_for_activation = true;
  tile_manager_->DidChangeTilePriority(this);
}

void Tile::AsValueInto(base::debug::TracedValue* res) const {
  TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
      TRACE_DISABLED_BY_DEFAULT("cc.debug"), res, "cc::Tile", this);
  TracedValue::SetIDRef(picture_pile_.get(), res, "picture_pile");
  res->SetDouble("contents_scale", contents_scale_);

  res->BeginArray("content_rect");
  MathUtil::AddToTracedValue(content_rect_, res);
  res->EndArray();

  res->SetInteger("layer_id", layer_id_);

  res->BeginDictionary("active_priority");
  priority_[ACTIVE_TREE].AsValueInto(res);
  res->EndDictionary();

  res->BeginDictionary("pending_priority");
  priority_[PENDING_TREE].AsValueInto(res);
  res->EndDictionary();

  res->BeginDictionary("managed_state");
  managed_state_.AsValueInto(res);
  res->EndDictionary();

  res->SetBoolean("use_picture_analysis", use_picture_analysis());

  res->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
}

size_t Tile::GPUMemoryUsageInBytes() const {
  size_t total_size = 0;
  for (int mode = 0; mode < NUM_RASTER_MODES; ++mode)
    total_size += managed_state_.tile_versions[mode].GPUMemoryUsageInBytes();
  return total_size;
}

RasterMode Tile::DetermineRasterModeForTree(WhichTree tree) const {
  return DetermineRasterModeForResolution(priority(tree).resolution);
}

RasterMode Tile::DetermineOverallRasterMode() const {
  return DetermineRasterModeForResolution(managed_state_.resolution);
}

RasterMode Tile::DetermineRasterModeForResolution(
    TileResolution resolution) const {
  RasterMode current_mode = managed_state_.raster_mode;
  RasterMode raster_mode = resolution == LOW_RESOLUTION
                               ? LOW_QUALITY_RASTER_MODE
                               : HIGH_QUALITY_RASTER_MODE;
  return std::min(raster_mode, current_mode);
}

bool Tile::HasRasterTask() const {
  for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
    if (managed_state_.tile_versions[mode].raster_task_)
      return true;
  }
  return false;
}

}  // namespace cc