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_layer_impl.h"
      6 
      7 #include <vector>
      8 #include "cc/resources/tile.h"
      9 #include "cc/trees/layer_tree_impl.h"
     10 
     11 namespace cc {
     12 
     13 FakePictureLayerImpl::FakePictureLayerImpl(
     14     LayerTreeImpl* tree_impl,
     15     int id,
     16     scoped_refptr<PicturePileImpl> pile)
     17     : PictureLayerImpl(tree_impl, id),
     18       append_quads_count_(0) {
     19   pile_ = pile;
     20   SetBounds(pile_->size());
     21 }
     22 
     23 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, int id)
     24     : PictureLayerImpl(tree_impl, id), append_quads_count_(0) {}
     25 
     26 scoped_ptr<LayerImpl> FakePictureLayerImpl::CreateLayerImpl(
     27     LayerTreeImpl* tree_impl) {
     28   return make_scoped_ptr(
     29       new FakePictureLayerImpl(tree_impl, id())).PassAs<LayerImpl>();
     30 }
     31 
     32 void FakePictureLayerImpl::AppendQuads(QuadSink* quad_sink,
     33                                        AppendQuadsData* append_quads_data) {
     34   PictureLayerImpl::AppendQuads(quad_sink, append_quads_data);
     35   ++append_quads_count_;
     36 }
     37 
     38 gfx::Size FakePictureLayerImpl::CalculateTileSize(
     39     gfx::Size content_bounds) const {
     40   if (fixed_tile_size_.IsEmpty()) {
     41     return PictureLayerImpl::CalculateTileSize(content_bounds);
     42   }
     43 
     44   return fixed_tile_size_;
     45 }
     46 
     47 PictureLayerTiling* FakePictureLayerImpl::HighResTiling() const {
     48   PictureLayerTiling* result = NULL;
     49   for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
     50     PictureLayerTiling* tiling = tilings_->tiling_at(i);
     51     if (tiling->resolution() == HIGH_RESOLUTION) {
     52       // There should be only one high res tiling.
     53       CHECK(!result);
     54       result = tiling;
     55     }
     56   }
     57   return result;
     58 }
     59 
     60 PictureLayerTiling* FakePictureLayerImpl::LowResTiling() const {
     61   PictureLayerTiling* result = NULL;
     62   for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
     63     PictureLayerTiling* tiling = tilings_->tiling_at(i);
     64     if (tiling->resolution() == LOW_RESOLUTION) {
     65       // There should be only one low res tiling.
     66       CHECK(!result);
     67       result = tiling;
     68     }
     69   }
     70   return result;
     71 }
     72 
     73 void FakePictureLayerImpl::SetAllTilesVisible() {
     74   WhichTree tree =
     75       layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
     76 
     77   for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
     78        ++tiling_idx) {
     79     PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
     80     std::vector<Tile*> tiles = tiling->AllTilesForTesting();
     81     for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
     82       Tile* tile = tiles[tile_idx];
     83       TilePriority priority;
     84       priority.resolution = HIGH_RESOLUTION;
     85       priority.time_to_visible_in_seconds = 0.f;
     86       priority.distance_to_visible_in_pixels = 0.f;
     87       tile->SetPriority(tree, priority);
     88     }
     89   }
     90 }
     91 
     92 void FakePictureLayerImpl::SetAllTilesReady() {
     93   for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
     94        ++tiling_idx) {
     95     PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
     96     SetAllTilesReadyInTiling(tiling);
     97   }
     98 }
     99 
    100 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
    101     PictureLayerTiling* tiling) {
    102   std::vector<Tile*> tiles = tiling->AllTilesForTesting();
    103   for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
    104     Tile* tile = tiles[tile_idx];
    105     ManagedTileState& state = tile->managed_state();
    106     for (size_t mode_idx = 0; mode_idx < NUM_RASTER_MODES; ++mode_idx)
    107       state.tile_versions[mode_idx].SetSolidColorForTesting(true);
    108     DCHECK(tile->IsReadyToDraw());
    109   }
    110 }
    111 
    112 void FakePictureLayerImpl::CreateDefaultTilingsAndTiles() {
    113   layer_tree_impl()->UpdateDrawProperties();
    114 
    115   if (CanHaveTilings()) {
    116     DCHECK_EQ(tilings()->num_tilings(), 2u);
    117     DCHECK_EQ(tilings()->tiling_at(0)->resolution(), HIGH_RESOLUTION);
    118     DCHECK_EQ(tilings()->tiling_at(1)->resolution(), LOW_RESOLUTION);
    119     HighResTiling()->CreateAllTilesForTesting();
    120     LowResTiling()->CreateAllTilesForTesting();
    121   } else {
    122     DCHECK_EQ(tilings()->num_tilings(), 0u);
    123   }
    124 }
    125 
    126 }  // namespace cc
    127