summaryrefslogtreecommitdiffstats
path: root/cc/tiles/raster_tile_priority_queue_required.cc
blob: bccc34bc6c36e06f53febe9985797458c2790fa9 (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
// Copyright 2015 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/tiles/raster_tile_priority_queue_required.h"

#include "cc/tiles/tiling_set_raster_queue_required.h"

namespace cc {

namespace {

void AppendTilingSetRequiredQueues(
    const std::vector<PictureLayerImpl*>& layers,
    ScopedPtrVector<TilingSetRasterQueueRequired>* queues) {
  for (auto* layer : layers) {
    if (!layer->HasValidTilePriorities())
      continue;

    scoped_ptr<TilingSetRasterQueueRequired> tiling_set_queue(
        new TilingSetRasterQueueRequired(
            layer->picture_layer_tiling_set(),
            RasterTilePriorityQueueRequired::Type::REQUIRED_FOR_ACTIVATION));
    if (!tiling_set_queue->IsEmpty())
      queues->push_back(tiling_set_queue.Pass());
  }
}

}  // namespace

RasterTilePriorityQueueRequired::RasterTilePriorityQueueRequired() {
}

RasterTilePriorityQueueRequired::~RasterTilePriorityQueueRequired() {
}

void RasterTilePriorityQueueRequired::Build(
    const std::vector<PictureLayerImpl*>& active_layers,
    const std::vector<PictureLayerImpl*>& pending_layers,
    Type type) {
  DCHECK_NE(static_cast<int>(type), static_cast<int>(Type::ALL));
  if (type == Type::REQUIRED_FOR_DRAW)
    BuildRequiredForDraw(active_layers);
  else
    BuildRequiredForActivation(active_layers, pending_layers);
}

void RasterTilePriorityQueueRequired::BuildRequiredForDraw(
    const std::vector<PictureLayerImpl*>& active_layers) {
  for (const auto& layer : active_layers) {
    if (!layer->HasValidTilePriorities())
      continue;

    scoped_ptr<TilingSetRasterQueueRequired> tiling_set_queue(
        new TilingSetRasterQueueRequired(layer->picture_layer_tiling_set(),
                                         Type::REQUIRED_FOR_DRAW));
    if (!tiling_set_queue->IsEmpty())
      tiling_set_queues_.push_back(tiling_set_queue.Pass());
  }
}

void RasterTilePriorityQueueRequired::BuildRequiredForActivation(
    const std::vector<PictureLayerImpl*>& active_layers,
    const std::vector<PictureLayerImpl*>& pending_layers) {
  AppendTilingSetRequiredQueues(active_layers, &tiling_set_queues_);
  AppendTilingSetRequiredQueues(pending_layers, &tiling_set_queues_);
}

bool RasterTilePriorityQueueRequired::IsEmpty() const {
  return tiling_set_queues_.empty();
}

const PrioritizedTile& RasterTilePriorityQueueRequired::Top() const {
  DCHECK(!IsEmpty());
  return tiling_set_queues_.back()->Top();
}

void RasterTilePriorityQueueRequired::Pop() {
  DCHECK(!IsEmpty());
  tiling_set_queues_.back()->Pop();
  if (tiling_set_queues_.back()->IsEmpty())
    tiling_set_queues_.pop_back();
}

}  // namespace cc