190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef CC_TEST_FAKE_PICTURE_LAYER_IMPL_H_
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define CC_TEST_FAKE_PICTURE_LAYER_IMPL_H_
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "cc/layers/picture_layer_impl.h"
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace cc {
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class FakePictureLayerImpl : public PictureLayerImpl {
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static scoped_ptr<FakePictureLayerImpl> Create(
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      LayerTreeImpl* tree_impl, int id) {
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return make_scoped_ptr(new FakePictureLayerImpl(tree_impl, id));
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Create layer from a pile that covers the entire layer.
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static scoped_ptr<FakePictureLayerImpl> CreateWithPile(
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      LayerTreeImpl* tree_impl, int id, scoped_refptr<PicturePileImpl> pile) {
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return make_scoped_ptr(new FakePictureLayerImpl(tree_impl, id, pile));
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Create layer from a pile that only covers part of the layer.
270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static scoped_ptr<FakePictureLayerImpl> CreateWithPartialPile(
280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      LayerTreeImpl* tree_impl,
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      int id,
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      scoped_refptr<PicturePileImpl> pile,
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      const gfx::Size& layer_bounds) {
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return make_scoped_ptr(
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        new FakePictureLayerImpl(tree_impl, id, pile, layer_bounds));
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      OVERRIDE;
38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void AppendQuads(RenderPass* render_pass,
39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                           const OcclusionTracker<LayerImpl>& occlusion_tracker,
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           AppendQuadsData* append_quads_data) OVERRIDE;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual gfx::Size CalculateTileSize(
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const gfx::Size& content_bounds) const OVERRIDE;
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void DidBecomeActive() OVERRIDE;
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  size_t did_become_active_call_count() {
465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return did_become_active_call_count_;
475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual bool HasValidTilePriorities() const OVERRIDE;
506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void set_has_valid_tile_priorities(bool has_valid_priorities) {
516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    has_valid_tile_priorities_ = has_valid_priorities;
526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    use_set_valid_tile_priorities_flag_ = true;
536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  }
546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  using PictureLayerImpl::AddTiling;
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  using PictureLayerImpl::CleanUpTilingsOnActiveLayer;
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  using PictureLayerImpl::CanHaveTilings;
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  using PictureLayerImpl::MarkVisibleResourcesAsRequired;
593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  using PictureLayerImpl::DoPostCommitInitializationIfNeeded;
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  using PictureLayerImpl::MinimumContentsScale;
6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  using PictureLayerImpl::GetViewportForTilePriorityInContentSpace;
620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  using PictureLayerImpl::SanityCheckTilingState;
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  using PictureLayerImpl::GetRecycledTwinLayer;
645b892326406927b709cdaf6c384d4ababf456332Ben Murdoch  using PictureLayerImpl::UpdatePile;
653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
66f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  using PictureLayerImpl::UpdateIdealScales;
67f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  using PictureLayerImpl::MaximumTilingContentsScale;
68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void SetNeedsPostCommitInitialization() {
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    needs_post_commit_initialization_ = true;
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
72cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  bool needs_post_commit_initialization() const {
743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return needs_post_commit_initialization_;
753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
77f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  float raster_page_scale() const { return raster_page_scale_; }
78f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void set_raster_page_scale(float scale) { raster_page_scale_ = scale; }
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  float ideal_contents_scale() const { return ideal_contents_scale_; }
811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  float raster_contents_scale() const { return raster_contents_scale_; }
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PictureLayerTiling* HighResTiling() const;
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PictureLayerTiling* LowResTiling() const;
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  size_t num_tilings() const { return tilings_->num_tilings(); }
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  PictureLayerImpl* twin_layer() { return twin_layer_; }
8823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  void set_twin_layer(PictureLayerImpl* twin) { twin_layer_ = twin; }
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  PictureLayerTilingSet* tilings() { return tilings_.get(); }
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  PicturePileImpl* pile() { return pile_.get(); }
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  size_t append_quads_count() { return append_quads_count_; }
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  const Region& invalidation() const { return invalidation_; }
9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void set_invalidation(const Region& region) { invalidation_ = region; }
9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  gfx::Rect visible_rect_for_tile_priority() {
970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return visible_rect_for_tile_priority_;
980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  gfx::Rect viewport_rect_for_tile_priority() {
1005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return viewport_rect_for_tile_priority_;
1010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  gfx::Transform screen_space_transform_for_tile_priority() {
1030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return screen_space_transform_for_tile_priority_;
1040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void set_fixed_tile_size(const gfx::Size& size) { fixed_tile_size_ = size; }
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CreateDefaultTilingsAndTiles();
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetAllTilesVisible();
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetAllTilesReady();
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SetAllTilesReadyInTiling(PictureLayerTiling* tiling);
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void SetTileReady(Tile* tile);
113e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  void ResetAllTilesPriorities();
1145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  PictureLayerTilingSet* GetTilings() { return tilings_.get(); }
115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  size_t release_resources_count() const { return release_resources_count_; }
1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void reset_release_resources_count() { release_resources_count_ = 0; }
1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ReleaseResources() OVERRIDE;
1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) protected:
12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FakePictureLayerImpl(
12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      LayerTreeImpl* tree_impl,
12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      int id,
12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      scoped_refptr<PicturePileImpl> pile);
1260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  FakePictureLayerImpl(LayerTreeImpl* tree_impl,
1270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                       int id,
1280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                       scoped_refptr<PicturePileImpl> pile,
1290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                       const gfx::Size& layer_bounds);
13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  FakePictureLayerImpl(LayerTreeImpl* tree_impl, int id);
13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private:
13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  gfx::Size fixed_tile_size_;
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  size_t append_quads_count_;
1365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  size_t did_become_active_call_count_;
1376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool has_valid_tile_priorities_;
1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool use_set_valid_tile_priorities_flag_;
1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  size_t release_resources_count_;
14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace cc
14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // CC_TEST_FAKE_PICTURE_LAYER_IMPL_H_
145