Home | History | Annotate | Download | only in test
      1 // Copyright 2013 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/test/fake_picture_pile_impl.h"
      6 
      7 #include <limits>
      8 #include <utility>
      9 
     10 #include "cc/test/fake_rendering_stats_instrumentation.h"
     11 #include "cc/test/impl_side_painting_settings.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 namespace cc {
     15 
     16 FakePicturePileImpl::FakePicturePileImpl() {}
     17 
     18 FakePicturePileImpl::~FakePicturePileImpl() {}
     19 
     20 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile(
     21     gfx::Size tile_size,
     22     gfx::Size layer_bounds) {
     23   scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
     24   pile->tiling().SetTotalSize(layer_bounds);
     25   pile->tiling().SetMaxTextureSize(tile_size);
     26   pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
     27   for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
     28     for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
     29       pile->AddRecordingAt(x, y);
     30   }
     31   pile->UpdateRecordedRegion();
     32   return pile;
     33 }
     34 
     35 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile(
     36     gfx::Size tile_size,
     37     gfx::Size layer_bounds) {
     38   scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
     39   pile->tiling().SetTotalSize(layer_bounds);
     40   pile->tiling().SetMaxTextureSize(tile_size);
     41   pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
     42   pile->UpdateRecordedRegion();
     43   return pile;
     44 }
     45 
     46 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreatePile() {
     47   scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
     48   gfx::Size size(std::numeric_limits<int>::max(),
     49                  std::numeric_limits<int>::max());
     50   pile->Resize(size);
     51   pile->recorded_region_ = Region(gfx::Rect(size));
     52   return pile;
     53 }
     54 
     55 void FakePicturePileImpl::AddRecordingAt(int x, int y) {
     56   EXPECT_GE(x, 0);
     57   EXPECT_GE(y, 0);
     58   EXPECT_LT(x, tiling_.num_tiles_x());
     59   EXPECT_LT(y, tiling_.num_tiles_y());
     60 
     61   if (HasRecordingAt(x, y))
     62     return;
     63   gfx::Rect bounds(tiling().TileBounds(x, y));
     64   bounds.Inset(-buffer_pixels(), -buffer_pixels());
     65 
     66   FakeRenderingStatsInstrumentation stats_instrumentation;
     67 
     68   scoped_refptr<Picture> picture(Picture::Create(bounds));
     69   picture->Record(&client_, tile_grid_info_, &stats_instrumentation);
     70   picture->GatherPixelRefs(tile_grid_info_, &stats_instrumentation);
     71   picture_list_map_[std::pair<int, int>(x, y)].push_back(picture);
     72   EXPECT_TRUE(HasRecordingAt(x, y));
     73 
     74   UpdateRecordedRegion();
     75 }
     76 
     77 void FakePicturePileImpl::AddPictureToRecording(
     78     int x,
     79     int y,
     80     scoped_refptr<Picture> picture) {
     81   picture_list_map_[std::pair<int, int>(x, y)].push_back(picture);
     82 }
     83 
     84 void FakePicturePileImpl::RemoveRecordingAt(int x, int y) {
     85   EXPECT_GE(x, 0);
     86   EXPECT_GE(y, 0);
     87   EXPECT_LT(x, tiling_.num_tiles_x());
     88   EXPECT_LT(y, tiling_.num_tiles_y());
     89 
     90   if (!HasRecordingAt(x, y))
     91     return;
     92   picture_list_map_.erase(std::pair<int, int>(x, y));
     93   EXPECT_FALSE(HasRecordingAt(x, y));
     94 
     95   UpdateRecordedRegion();
     96 }
     97 
     98 void FakePicturePileImpl::RerecordPile() {
     99   for (int y = 0; y < num_tiles_y(); ++y) {
    100     for (int x = 0; x < num_tiles_x(); ++x) {
    101       RemoveRecordingAt(x, y);
    102       AddRecordingAt(x, y);
    103     }
    104   }
    105 }
    106 
    107 }  // namespace cc
    108