summaryrefslogtreecommitdiffstats
path: root/cc/test/tiled_layer_test_common.h
blob: f7e01584404cabc86d9ea3b467189006adbd193e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TEST_TILED_LAYER_TEST_COMMON_H_
#define CC_TEST_TILED_LAYER_TEST_COMMON_H_

#include "cc/base/region.h"
#include "cc/layers/tiled_layer.h"
#include "cc/layers/tiled_layer_impl.h"
#include "cc/resources/layer_updater.h"
#include "cc/resources/prioritized_resource.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/resource_update_queue.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"

namespace cc {

class FakeTiledLayer;

class FakeLayerUpdater : public LayerUpdater {
 public:
  class Resource : public LayerUpdater::Resource {
   public:
    Resource(FakeLayerUpdater* updater,
             scoped_ptr<PrioritizedResource> resource);
    virtual ~Resource();

    virtual void Update(ResourceUpdateQueue* queue,
                        const gfx::Rect& source_rect,
                        const gfx::Vector2d& dest_offset,
                        bool partial_update) OVERRIDE;

   private:
    FakeLayerUpdater* layer_;
    SkBitmap bitmap_;

    DISALLOW_COPY_AND_ASSIGN(Resource);
  };

  FakeLayerUpdater();

  virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
      PrioritizedResourceManager* resource) OVERRIDE;

  virtual void PrepareToUpdate(const gfx::Rect& content_rect,
                               const gfx::Size& tile_size,
                               float contents_width_scale,
                               float contents_height_scale,
                               gfx::Rect* resulting_opaque_rect) OVERRIDE;
  // Sets the rect to invalidate during the next call to PrepareToUpdate().
  // After the next call to PrepareToUpdate() the rect is reset.
  void SetRectToInvalidate(const gfx::Rect& rect, FakeTiledLayer* layer);
  // Last rect passed to PrepareToUpdate().
  gfx::Rect last_update_rect() const { return last_update_rect_; }

  // Number of times PrepareToUpdate has been invoked.
  int prepare_count() const { return prepare_count_; }
  void ClearPrepareCount() { prepare_count_ = 0; }

  // Number of times Update() has been invoked on a texture.
  int update_count() const { return update_count_; }
  void ClearUpdateCount() { update_count_ = 0; }
  void Update() { update_count_++; }

  void SetOpaquePaintRect(const gfx::Rect& opaque_paint_rect) {
    opaque_paint_rect_ = opaque_paint_rect;
  }

 protected:
  virtual ~FakeLayerUpdater();

 private:
  int prepare_count_;
  int update_count_;
  gfx::Rect rect_to_invalidate_;
  gfx::Rect last_update_rect_;
  gfx::Rect opaque_paint_rect_;
  scoped_refptr<FakeTiledLayer> layer_;

  DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater);
};

class FakeTiledLayerImpl : public TiledLayerImpl {
 public:
  FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id);
  virtual ~FakeTiledLayerImpl();

  using TiledLayerImpl::HasTileAt;
  using TiledLayerImpl::HasResourceIdForTileAt;
};

class FakeTiledLayer : public TiledLayer {
 public:
  explicit FakeTiledLayer(PrioritizedResourceManager* resource_manager);

  static gfx::Size tile_size() { return gfx::Size(100, 100); }

  using TiledLayer::InvalidateContentRect;
  using TiledLayer::NeedsIdlePaint;
  using TiledLayer::SkipsDraw;
  using TiledLayer::NumPaintedTiles;
  using TiledLayer::IdlePaintRect;

  virtual void SetNeedsDisplayRect(const gfx::RectF& rect) OVERRIDE;
  const gfx::RectF& last_needs_display_rect() const {
    return last_needs_display_rect_;
  }

  virtual void SetTexturePriorities(
      const PriorityCalculator& priority_calculator) OVERRIDE;

  virtual PrioritizedResourceManager* ResourceManager() OVERRIDE;
  FakeLayerUpdater* fake_layer_updater() { return fake_updater_.get(); }
  gfx::RectF update_rect() { return update_rect_; }

  // Simulate CalcDrawProperties.
  void UpdateContentsScale(float ideal_contents_scale);

  void ResetNumDependentsNeedPushProperties();

 protected:
  virtual LayerUpdater* Updater() const OVERRIDE;
  virtual void CreateUpdaterIfNeeded() OVERRIDE {}
  virtual ~FakeTiledLayer();

 private:
  scoped_refptr<FakeLayerUpdater> fake_updater_;
  PrioritizedResourceManager* resource_manager_;
  gfx::RectF last_needs_display_rect_;

  DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer);
};

class FakeTiledLayerWithScaledBounds : public FakeTiledLayer {
 public:
  explicit FakeTiledLayerWithScaledBounds(
      PrioritizedResourceManager* resource_manager);

  void SetContentBounds(const gfx::Size& content_bounds);
  virtual void CalculateContentsScale(float ideal_contents_scale,
                                      float* contents_scale_x,
                                      float* contents_scale_y,
                                      gfx::Size* content_bounds) OVERRIDE;

 protected:
  virtual ~FakeTiledLayerWithScaledBounds();
  gfx::Size forced_content_bounds_;

 private:
  DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds);
};

}  // namespace cc

#endif  // CC_TEST_TILED_LAYER_TEST_COMMON_H_