cc: Don't activate rasterize on demand when we have 0 memory.
[chromium-blink-merge.git] / cc / test / tiled_layer_test_common.h
blob26346212af5b9653bc3f0fd21cf83f059113465f
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.
5 #ifndef CC_TEST_TILED_LAYER_TEST_COMMON_H_
6 #define CC_TEST_TILED_LAYER_TEST_COMMON_H_
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"
18 namespace cc {
20 class FakeTiledLayer;
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();
30 virtual void Update(ResourceUpdateQueue* queue,
31 const gfx::Rect& source_rect,
32 const gfx::Vector2d& dest_offset,
33 bool partial_update) OVERRIDE;
35 private:
36 FakeLayerUpdater* layer_;
37 SkBitmap bitmap_;
39 DISALLOW_COPY_AND_ASSIGN(Resource);
42 FakeLayerUpdater();
44 virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
45 PrioritizedResourceManager* resource) OVERRIDE;
47 virtual void PrepareToUpdate(const gfx::Size& content_size,
48 const gfx::Rect& paint_rect,
49 const gfx::Size& tile_size,
50 float contents_width_scale,
51 float contents_height_scale) 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_; }
58 // Value of |contents_width_scale| last passed to PrepareToUpdate().
59 float last_contents_width_scale() const { return last_contents_width_scale_; }
61 // Number of times PrepareToUpdate has been invoked.
62 int prepare_count() const { return prepare_count_; }
63 void ClearPrepareCount() { prepare_count_ = 0; }
65 // Number of times Update() has been invoked on a texture.
66 int update_count() const { return update_count_; }
67 void ClearUpdateCount() { update_count_ = 0; }
68 void Update() { update_count_++; }
70 protected:
71 virtual ~FakeLayerUpdater();
73 private:
74 int prepare_count_;
75 int update_count_;
76 gfx::Rect rect_to_invalidate_;
77 gfx::Rect last_update_rect_;
78 float last_contents_width_scale_;
79 scoped_refptr<FakeTiledLayer> layer_;
81 DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
84 class FakeTiledLayerImpl : public TiledLayerImpl {
85 public:
86 FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
87 virtual ~FakeTiledLayerImpl();
89 using TiledLayerImpl::HasTileAt;
90 using TiledLayerImpl::HasResourceIdForTileAt;
93 class FakeTiledLayer : public TiledLayer {
94 public:
95 explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);
97 static gfx::Size tile_size() { return gfx::Size(100, 100); }
99 using TiledLayer::InvalidateContentRect;
100 using TiledLayer::NeedsIdlePaint;
101 using TiledLayer::SkipsDraw;
102 using TiledLayer::NumPaintedTiles;
103 using TiledLayer::IdlePaintRect;
105 virtual void SetNeedsDisplayRect(const gfx::RectF& rect) OVERRIDE;
106 const gfx::RectF& last_needs_display_rect() const {
107 return last_needs_display_rect_;
110 virtual void SetTexturePriorities(
111 const PriorityCalculator& priority_calculator) OVERRIDE;
113 virtual PrioritizedResourceManager* ResourceManager() OVERRIDE;
114 FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
115 gfx::RectF update_rect() { return update_rect_; }
117 // Simulate CalcDrawProperties.
118 void UpdateContentsScale(float ideal_contents_scale);
120 void ResetNumDependentsNeedPushProperties();
122 protected:
123 virtual LayerUpdater* Updater() const OVERRIDE;
124 virtual void CreateUpdaterIfNeeded() OVERRIDE {}
125 virtual ~FakeTiledLayer();
127 private:
128 scoped_refptr<FakeLayerUpdater> fake_updater_;
129 PrioritizedResourceManager* resource_manager_;
130 gfx::RectF last_needs_display_rect_;
132 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
135 class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
136 public:
137 explicit FakeTiledLayerWithScaledBounds(
138 PrioritizedResourceManager* resource_manager);
140 void SetContentBounds(const gfx::Size& content_bounds);
141 virtual void CalculateContentsScale(float ideal_contents_scale,
142 float* contents_scale_x,
143 float* contents_scale_y,
144 gfx::Size* content_bounds) OVERRIDE;
146 protected:
147 virtual ~FakeTiledLayerWithScaledBounds();
148 gfx::Size forced_content_bounds_;
150 private:
151 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
154 } // namespace cc
156 #endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_