Home | History | Annotate | Download | only in test
      1 // Copyright 2012 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 #ifndef CC_TEST_TILED_LAYER_TEST_COMMON_H_
      6 #define CC_TEST_TILED_LAYER_TEST_COMMON_H_
      7 
      8 #include "cc/base/region.h"
      9 #include "cc/layers/tiled_layer.h"
     10 #include "cc/layers/tiled_layer_impl.h"
     11 #include "cc/resources/layer_updater.h"
     12 #include "cc/resources/prioritized_resource.h"
     13 #include "cc/resources/resource_provider.h"
     14 #include "cc/resources/resource_update_queue.h"
     15 #include "cc/scheduler/texture_uploader.h"
     16 #include "ui/gfx/rect.h"
     17 #include "ui/gfx/size.h"
     18 
     19 namespace cc {
     20 
     21 class FakeTiledLayer;
     22 
     23 class FakeLayerUpdater : public LayerUpdater {
     24  public:
     25   class Resource : public LayerUpdater::Resource {
     26    public:
     27     Resource(FakeLayerUpdater* updater,
     28              scoped_ptr<PrioritizedResource> resource);
     29     virtual ~Resource();
     30 
     31     virtual void Update(ResourceUpdateQueue* queue,
     32                         gfx::Rect source_rect,
     33                         gfx::Vector2d dest_offset,
     34                         bool partial_update) OVERRIDE;
     35 
     36    private:
     37     FakeLayerUpdater* layer_;
     38     SkBitmap bitmap_;
     39 
     40     DISALLOW_COPY_AND_ASSIGN(Resource);
     41   };
     42 
     43   FakeLayerUpdater();
     44 
     45   virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
     46       PrioritizedResourceManager* resource) OVERRIDE;
     47 
     48   virtual void PrepareToUpdate(gfx::Rect content_rect,
     49                                gfx::Size tile_size,
     50                                float contents_width_scale,
     51                                float contents_height_scale,
     52                                gfx::Rect* resulting_opaque_rect) OVERRIDE;
     53   // Sets the rect to invalidate during the next call to PrepareToUpdate().
     54   // After the next call to PrepareToUpdate() the rect is reset.
     55   void SetRectToInvalidate(gfx::Rect rect, FakeTiledLayer* layer);
     56   // Last rect passed to PrepareToUpdate().
     57   gfx::Rect last_update_rect() const { return last_update_rect_; }
     58 
     59   // Number of times PrepareToUpdate has been invoked.
     60   int prepare_count() const { return prepare_count_; }
     61   void ClearPrepareCount() { prepare_count_ = 0; }
     62 
     63   // Number of times Update() has been invoked on a texture.
     64   int update_count() const { return update_count_; }
     65   void ClearUpdateCount() { update_count_ = 0; }
     66   void Update() { update_count_++; }
     67 
     68   void SetOpaquePaintRect(gfx::Rect opaque_paint_rect) {
     69     opaque_paint_rect_ = opaque_paint_rect;
     70   }
     71 
     72  protected:
     73   virtual ~FakeLayerUpdater();
     74 
     75  private:
     76   int prepare_count_;
     77   int update_count_;
     78   gfx::Rect rect_to_invalidate_;
     79   gfx::Rect last_update_rect_;
     80   gfx::Rect opaque_paint_rect_;
     81   scoped_refptr<FakeTiledLayer> layer_;
     82 
     83   DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
     84 };
     85 
     86 class FakeTiledLayerImpl : public TiledLayerImpl {
     87  public:
     88   FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
     89   virtual ~FakeTiledLayerImpl();
     90 
     91   using TiledLayerImpl::HasTileAt;
     92   using TiledLayerImpl::HasResourceIdForTileAt;
     93 };
     94 
     95 class FakeTiledLayer : public TiledLayer {
     96  public:
     97   explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);
     98 
     99   static gfx::Size tile_size() { return gfx::Size(100, 100); }
    100 
    101   using TiledLayer::InvalidateContentRect;
    102   using TiledLayer::NeedsIdlePaint;
    103   using TiledLayer::SkipsDraw;
    104   using TiledLayer::NumPaintedTiles;
    105   using TiledLayer::IdlePaintRect;
    106 
    107   virtual void SetNeedsDisplayRect(const gfx::RectF& rect) OVERRIDE;
    108   const gfx::RectF& last_needs_display_rect() const {
    109     return last_needs_display_rect_;
    110   }
    111 
    112   virtual void SetTexturePriorities(
    113       const PriorityCalculator& priority_calculator) OVERRIDE;
    114 
    115   virtual PrioritizedResourceManager* ResourceManager() const OVERRIDE;
    116   FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
    117   gfx::RectF update_rect() { return update_rect_; }
    118 
    119   // Simulate CalcDrawProperties.
    120   void UpdateContentsScale(float ideal_contents_scale);
    121 
    122   void ResetNumDependentsNeedPushProperties();
    123 
    124  protected:
    125   virtual LayerUpdater* Updater() const OVERRIDE;
    126   virtual void CreateUpdaterIfNeeded() OVERRIDE {}
    127   virtual ~FakeTiledLayer();
    128 
    129  private:
    130   scoped_refptr<FakeLayerUpdater> fake_updater_;
    131   PrioritizedResourceManager* resource_manager_;
    132   gfx::RectF last_needs_display_rect_;
    133 
    134   DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
    135 };
    136 
    137 class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
    138  public:
    139   explicit FakeTiledLayerWithScaledBounds(
    140       PrioritizedResourceManager* resource_manager);
    141 
    142   void SetContentBounds(gfx::Size content_bounds);
    143   virtual void CalculateContentsScale(float ideal_contents_scale,
    144                                       float device_scale_factor,
    145                                       float page_scale_factor,
    146                                       bool animating_transform_to_screen,
    147                                       float* contents_scale_x,
    148                                       float* contents_scale_y,
    149                                       gfx::Size* content_bounds) OVERRIDE;
    150 
    151  protected:
    152   virtual ~FakeTiledLayerWithScaledBounds();
    153   gfx::Size forced_content_bounds_;
    154 
    155  private:
    156   DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
    157 };
    158 
    159 }  // namespace cc
    160 
    161 #endif  // CC_TEST_TILED_LAYER_TEST_COMMON_H_
    162