blob: abf2de4c29708abda484da3f363035c253441a6a [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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"
James Robinson30d547e2014-10-23 18:20:06 -070015#include "ui/gfx/geometry/rect.h"
16#include "ui/gfx/geometry/size.h"
James Robinson646469d2014-10-03 15:33:28 -070017
18namespace cc {
19
20class FakeTiledLayer;
21
22class FakeLayerUpdater : public LayerUpdater {
23 public:
24 class Resource : public LayerUpdater::Resource {
25 public:
26 Resource(FakeLayerUpdater* updater,
27 scoped_ptr<PrioritizedResource> resource);
James Robinsone1b30cf2014-10-21 12:25:40 -070028 ~Resource() override;
James Robinson646469d2014-10-03 15:33:28 -070029
James Robinsone1b30cf2014-10-21 12:25:40 -070030 void Update(ResourceUpdateQueue* queue,
31 const gfx::Rect& source_rect,
32 const gfx::Vector2d& dest_offset,
33 bool partial_update) override;
James Robinson646469d2014-10-03 15:33:28 -070034
35 private:
36 FakeLayerUpdater* layer_;
37 SkBitmap bitmap_;
38
39 DISALLOW_COPY_AND_ASSIGN(Resource);
40 };
41
42 FakeLayerUpdater();
43
James Robinsone1b30cf2014-10-21 12:25:40 -070044 scoped_ptr<LayerUpdater::Resource> CreateResource(
James Robinsonbaf71d32014-10-08 13:00:20 -070045 PrioritizedResourceManager* resource) override;
James Robinson646469d2014-10-03 15:33:28 -070046
James Robinsone1b30cf2014-10-21 12:25:40 -070047 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;
James Robinson646469d2014-10-03 15:33:28 -070052 // 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 // Value of |contents_width_scale| last passed to PrepareToUpdate().
59 float last_contents_width_scale() const { return last_contents_width_scale_; }
60
61 // Number of times PrepareToUpdate has been invoked.
62 int prepare_count() const { return prepare_count_; }
63 void ClearPrepareCount() { prepare_count_ = 0; }
64
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_++; }
69
70 protected:
James Robinsone1b30cf2014-10-21 12:25:40 -070071 ~FakeLayerUpdater() override;
James Robinson646469d2014-10-03 15:33:28 -070072
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_;
80
81 DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
82};
83
84class FakeTiledLayerImpl : public TiledLayerImpl {
85 public:
86 FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
James Robinsone1b30cf2014-10-21 12:25:40 -070087 ~FakeTiledLayerImpl() override;
James Robinson646469d2014-10-03 15:33:28 -070088
89 using TiledLayerImpl::HasTileAt;
90 using TiledLayerImpl::HasResourceIdForTileAt;
91};
92
93class FakeTiledLayer : public TiledLayer {
94 public:
95 explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);
96
97 static gfx::Size tile_size() { return gfx::Size(100, 100); }
98
99 using TiledLayer::InvalidateContentRect;
100 using TiledLayer::NeedsIdlePaint;
101 using TiledLayer::SkipsDraw;
102 using TiledLayer::NumPaintedTiles;
103 using TiledLayer::IdlePaintRect;
104
James Robinsone1b30cf2014-10-21 12:25:40 -0700105 void SetNeedsDisplayRect(const gfx::Rect& rect) override;
James Robinsone2ac7e82014-10-15 13:21:59 -0700106 const gfx::Rect& last_needs_display_rect() const {
James Robinson646469d2014-10-03 15:33:28 -0700107 return last_needs_display_rect_;
108 }
109
James Robinsone1b30cf2014-10-21 12:25:40 -0700110 void SetTexturePriorities(
James Robinsonbaf71d32014-10-08 13:00:20 -0700111 const PriorityCalculator& priority_calculator) override;
James Robinson646469d2014-10-03 15:33:28 -0700112
James Robinsone1b30cf2014-10-21 12:25:40 -0700113 PrioritizedResourceManager* ResourceManager() override;
James Robinson646469d2014-10-03 15:33:28 -0700114 FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
115 gfx::RectF update_rect() { return update_rect_; }
116
117 // Simulate CalcDrawProperties.
118 void UpdateContentsScale(float ideal_contents_scale);
119
120 void ResetNumDependentsNeedPushProperties();
121
122 protected:
James Robinsone1b30cf2014-10-21 12:25:40 -0700123 LayerUpdater* Updater() const override;
124 void CreateUpdaterIfNeeded() override {}
125 ~FakeTiledLayer() override;
James Robinson646469d2014-10-03 15:33:28 -0700126
127 private:
128 scoped_refptr<FakeLayerUpdater> fake_updater_;
129 PrioritizedResourceManager* resource_manager_;
James Robinsone2ac7e82014-10-15 13:21:59 -0700130 gfx::Rect last_needs_display_rect_;
James Robinson646469d2014-10-03 15:33:28 -0700131
132 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
133};
134
135class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
136 public:
137 explicit FakeTiledLayerWithScaledBounds(
138 PrioritizedResourceManager* resource_manager);
139
140 void SetContentBounds(const gfx::Size& content_bounds);
James Robinsone1b30cf2014-10-21 12:25:40 -0700141 void CalculateContentsScale(float ideal_contents_scale,
142 float* contents_scale_x,
143 float* contents_scale_y,
144 gfx::Size* content_bounds) override;
James Robinson646469d2014-10-03 15:33:28 -0700145
146 protected:
James Robinsone1b30cf2014-10-21 12:25:40 -0700147 ~FakeTiledLayerWithScaledBounds() override;
James Robinson646469d2014-10-03 15:33:28 -0700148 gfx::Size forced_content_bounds_;
149
150 private:
151 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
152};
153
154} // namespace cc
155
156#endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_