Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / cc / test / tiled_layer_test_common.h
blob11666d3ab6ec61a9141293b2d9cbcf80224bb059
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/output/texture_copier.h"
12 #include "cc/resources/layer_updater.h"
13 #include "cc/resources/prioritized_resource.h"
14 #include "cc/resources/resource_provider.h"
15 #include "cc/resources/resource_update_queue.h"
16 #include "cc/scheduler/texture_uploader.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/size.h"
20 namespace cc {
22 class FakeTiledLayer;
24 class FakeLayerUpdater : public LayerUpdater {
25 public:
26 class Resource : public LayerUpdater::Resource {
27 public:
28 Resource(FakeLayerUpdater* updater,
29 scoped_ptr<PrioritizedResource> resource);
30 virtual ~Resource();
32 virtual void Update(ResourceUpdateQueue* queue,
33 gfx::Rect source_rect,
34 gfx::Vector2d dest_offset,
35 bool partial_update,
36 RenderingStats* stats) OVERRIDE;
38 private:
39 FakeLayerUpdater* layer_;
40 SkBitmap bitmap_;
42 DISALLOW_COPY_AND_ASSIGN(Resource);
45 FakeLayerUpdater();
47 virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
48 PrioritizedResourceManager* resource) OVERRIDE;
50 virtual void PrepareToUpdate(gfx::Rect content_rect,
51 gfx::Size tile_size,
52 float contents_width_scale,
53 float contents_height_scale,
54 gfx::Rect* resulting_opaque_rect,
55 RenderingStats* stats) OVERRIDE;
56 // Sets the rect to invalidate during the next call to PrepareToUpdate().
57 // After the next call to PrepareToUpdate() the rect is reset.
58 void SetRectToInvalidate(gfx::Rect rect, FakeTiledLayer* layer);
59 // Last rect passed to PrepareToUpdate().
60 gfx::Rect last_update_rect() const { return last_update_rect_; }
62 // Number of times PrepareToUpdate has been invoked.
63 int prepare_count() const { return prepare_count_; }
64 void ClearPrepareCount() { prepare_count_ = 0; }
66 // Number of times Update() has been invoked on a texture.
67 int update_count() const { return update_count_; }
68 void ClearUpdateCount() { update_count_ = 0; }
69 void Update() { update_count_++; }
71 void SetOpaquePaintRect(gfx::Rect opaque_paint_rect) {
72 opaque_paint_rect_ = opaque_paint_rect;
75 protected:
76 virtual ~FakeLayerUpdater();
78 private:
79 int prepare_count_;
80 int update_count_;
81 gfx::Rect rect_to_invalidate_;
82 gfx::Rect last_update_rect_;
83 gfx::Rect opaque_paint_rect_;
84 scoped_refptr<FakeTiledLayer> layer_;
86 DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
89 class FakeTiledLayerImpl : public TiledLayerImpl {
90 public:
91 FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
92 virtual ~FakeTiledLayerImpl();
94 using TiledLayerImpl::HasTileAt;
95 using TiledLayerImpl::HasResourceIdForTileAt;
98 class FakeTiledLayer : public TiledLayer {
99 public:
100 explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);
102 static gfx::Size tile_size() { return gfx::Size(100, 100); }
104 using TiledLayer::InvalidateContentRect;
105 using TiledLayer::NeedsIdlePaint;
106 using TiledLayer::SkipsDraw;
107 using TiledLayer::NumPaintedTiles;
108 using TiledLayer::IdlePaintRect;
110 virtual void SetNeedsDisplayRect(const gfx::RectF& rect) OVERRIDE;
111 const gfx::RectF& last_needs_display_rect() const {
112 return last_needs_display_rect_;
115 virtual void SetTexturePriorities(
116 const PriorityCalculator& priority_calculator) OVERRIDE;
118 virtual PrioritizedResourceManager* ResourceManager() const OVERRIDE;
119 FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
120 gfx::RectF update_rect() { return update_rect_; }
122 // Simulate CalcDrawProperties.
123 void UpdateContentsScale(float ideal_contents_scale);
125 protected:
126 virtual LayerUpdater* Updater() const OVERRIDE;
127 virtual void CreateUpdaterIfNeeded() OVERRIDE {}
128 virtual ~FakeTiledLayer();
130 private:
131 scoped_refptr<FakeLayerUpdater> fake_updater_;
132 PrioritizedResourceManager* resource_manager_;
133 gfx::RectF last_needs_display_rect_;
135 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
138 class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
139 public:
140 explicit FakeTiledLayerWithScaledBounds(
141 PrioritizedResourceManager* resource_manager);
143 void SetContentBounds(gfx::Size content_bounds);
144 virtual void CalculateContentsScale(float ideal_contents_scale,
145 bool animating_transform_to_screen,
146 float* contents_scale_x,
147 float* contents_scale_y,
148 gfx::Size* content_bounds) OVERRIDE;
150 protected:
151 virtual ~FakeTiledLayerWithScaledBounds();
152 gfx::Size forced_content_bounds_;
154 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
157 } // namespace cc
159 #endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_