1// Copyright 2013 The Flutter 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#include "flutter/flow/texture.h"
6#include "flutter/testing/assertions_skia.h"
7
8#include <ostream>
9#include <vector>
10
11namespace flutter {
12namespace testing {
13
14// Mock implementation of the |Texture| interface that does not interact with
15// the GPU. It simply records the list of various calls made so the test can
16// later verify them against expected data.
17class MockTexture : public Texture {
18 public:
19 struct PaintCall {
20 SkCanvas& canvas;
21 SkRect bounds;
22 bool freeze;
23 GrDirectContext* context;
24 SkFilterQuality filter_quality;
25 };
26
27 explicit MockTexture(int64_t textureId);
28
29 // Called from raster thread.
30 void Paint(SkCanvas& canvas,
31 const SkRect& bounds,
32 bool freeze,
33 GrDirectContext* context,
34 SkFilterQuality filter_quality) override;
35
36 void OnGrContextCreated() override { gr_context_created_ = true; }
37 void OnGrContextDestroyed() override { gr_context_destroyed_ = true; }
38 void MarkNewFrameAvailable() override {}
39 void OnTextureUnregistered() override { unregistered_ = true; }
40
41 const std::vector<PaintCall>& paint_calls() { return paint_calls_; }
42 bool gr_context_created() { return gr_context_created_; }
43 bool gr_context_destroyed() { return gr_context_destroyed_; }
44 bool unregistered() { return unregistered_; }
45
46 private:
47 std::vector<PaintCall> paint_calls_;
48 bool gr_context_created_ = false;
49 bool gr_context_destroyed_ = false;
50 bool unregistered_ = false;
51};
52
53extern bool operator==(const MockTexture::PaintCall& a,
54 const MockTexture::PaintCall& b);
55extern std::ostream& operator<<(std::ostream& os,
56 const MockTexture::PaintCall& data);
57
58} // namespace testing
59} // namespace flutter
60