summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_content_layer_client.h
blob: 53548338c0304730d2f35b1ed3af1c121c1e7d29 (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
// 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_FAKE_CONTENT_LAYER_CLIENT_H_
#define CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_

#include <stddef.h>

#include <utility>
#include <vector>

#include "base/compiler_specific.h"
#include "cc/layers/content_layer_client.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/transform.h"

class SkImage;

namespace cc {

class FakeContentLayerClient : public ContentLayerClient {
 public:
  struct ImageData {
    ImageData(const SkImage* image,
              const gfx::Point& point,
              const SkPaint& paint);
    ImageData(const SkImage* image,
              const gfx::Transform& transform,
              const SkPaint& paint);
    ~ImageData();
    skia::RefPtr<const SkImage> image;
    gfx::Point point;
    gfx::Transform transform;
    SkPaint paint;
  };

  FakeContentLayerClient();
  ~FakeContentLayerClient() override;

  gfx::Rect PaintableRegion() override;
  scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
      PaintingControlSetting painting_control) override;
  bool FillsBoundsCompletely() const override;
  size_t GetApproximateUnsharedMemoryUsage() const override;

  void set_display_list_use_cached_picture(bool use_cached_picture) {
    display_list_use_cached_picture_ = use_cached_picture;
  }

  void set_fill_with_nonsolid_color(bool nonsolid) {
    fill_with_nonsolid_color_ = nonsolid;
  }

  void add_draw_rect(const gfx::Rect& rect, const SkPaint& paint) {
    draw_rects_.push_back(std::make_pair(gfx::RectF(rect), paint));
  }

  void add_draw_rectf(const gfx::RectF& rect, const SkPaint& paint) {
    draw_rects_.push_back(std::make_pair(rect, paint));
  }

  void add_draw_image(const SkImage* image,
                      const gfx::Point& point,
                      const SkPaint& paint) {
    ImageData data(image, point, paint);
    draw_images_.push_back(data);
  }

  void add_draw_image_with_transform(const SkImage* image,
                                     const gfx::Transform& transform,
                                     const SkPaint& paint) {
    ImageData data(image, transform, paint);
    draw_images_.push_back(data);
  }

  SkCanvas* last_canvas() const { return last_canvas_; }

  PaintingControlSetting last_painting_control() const {
    return last_painting_control_;
  }

  void set_reported_memory_usage(size_t reported_memory_usage) {
    reported_memory_usage_ = reported_memory_usage;
  }

  void set_bounds(gfx::Size bounds) {
    bounds_ = bounds;
    bounds_set_ = true;
  }

 private:
  typedef std::vector<std::pair<gfx::RectF, SkPaint>> RectPaintVector;
  typedef std::vector<ImageData> ImageVector;

  bool display_list_use_cached_picture_;
  bool fill_with_nonsolid_color_;
  RectPaintVector draw_rects_;
  ImageVector draw_images_;
  SkCanvas* last_canvas_;
  PaintingControlSetting last_painting_control_;
  size_t reported_memory_usage_;
  gfx::Size bounds_;
  bool bounds_set_;
};

}  // namespace cc

#endif  // CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_