summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_picture_pile.cc
blob: 52a70ece8ac0ce6c02e1fa60fa9af21c573bd1f0 (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
// Copyright 2014 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/test/fake_picture_pile.h"

#include <utility>

#include "cc/test/fake_picture_pile_impl.h"
#include "cc/trees/layer_tree_settings.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {

namespace {

scoped_ptr<FakePicturePile> CreatePile(const gfx::Size& tile_size,
                                       const gfx::Size& layer_bounds,
                                       bool is_filled) {
  scoped_ptr<FakePicturePile> pile(
      new FakePicturePile(LayerTreeSettings().minimum_contents_scale,
                          LayerTreeSettings().default_tile_grid_size));
  pile->tiling().SetBorderTexels(0);
  pile->tiling().SetTilingSize(layer_bounds);
  pile->tiling().SetMaxTextureSize(tile_size);
  pile->SetRecordedViewport(is_filled ? gfx::Rect(layer_bounds) : gfx::Rect());
  pile->SetHasAnyRecordings(is_filled);
  if (is_filled) {
    for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
      for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
        pile->AddRecordingAt(x, y);
    }
  }
  return pile;
}

}  // namespace

scoped_ptr<FakePicturePile> FakePicturePile::CreateFilledPile(
    const gfx::Size& tile_size,
    const gfx::Size& layer_bounds) {
  bool is_filled = true;
  return CreatePile(tile_size, layer_bounds, is_filled);
}

scoped_ptr<FakePicturePile> FakePicturePile::CreateEmptyPile(
    const gfx::Size& tile_size,
    const gfx::Size& layer_bounds) {
  bool is_filled = false;
  return CreatePile(tile_size, layer_bounds, is_filled);
}

scoped_refptr<RasterSource> FakePicturePile::CreateRasterSource(
    bool can_use_lcd_text) const {
  return FakePicturePileImpl::CreateFromPile(this, playback_allowed_event_);
}

void FakePicturePile::AddRecordingAt(int x, int y) {
  EXPECT_GE(x, 0);
  EXPECT_GE(y, 0);
  EXPECT_LT(x, tiling_.num_tiles_x());
  EXPECT_LT(y, tiling_.num_tiles_y());

  if (HasRecordingAt(x, y))
    return;
  gfx::Rect bounds(tiling().TileBounds(x, y));
  bounds.Inset(-buffer_pixels(), -buffer_pixels());

  scoped_refptr<Picture> picture(
      Picture::Create(bounds, &client_, tile_grid_size_, gather_pixel_refs_,
                      RecordingSource::RECORD_NORMALLY));
  picture_map_[std::pair<int, int>(x, y)] = picture;
  EXPECT_TRUE(HasRecordingAt(x, y));

  has_any_recordings_ = true;
}

void FakePicturePile::RemoveRecordingAt(int x, int y) {
  EXPECT_GE(x, 0);
  EXPECT_GE(y, 0);
  EXPECT_LT(x, tiling_.num_tiles_x());
  EXPECT_LT(y, tiling_.num_tiles_y());

  if (!HasRecordingAt(x, y))
    return;
  picture_map_.erase(std::pair<int, int>(x, y));
  EXPECT_FALSE(HasRecordingAt(x, y));
}

bool FakePicturePile::HasRecordingAt(int x, int y) const {
  PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y));
  return found != picture_map_.end();
}

void FakePicturePile::Rerecord() {
  for (int y = 0; y < num_tiles_y(); ++y) {
    for (int x = 0; x < num_tiles_x(); ++x) {
      RemoveRecordingAt(x, y);
      AddRecordingAt(x, y);
    }
  }
}

}  // namespace cc