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