Flutter Engine
mock_texture.h
Go to the documentation of this file.
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 <ostream>
6 #include <vector>
7 
8 #include "flutter/flow/texture.h"
9 #include "flutter/testing/assertions_skia.h"
10 
11 namespace flutter {
12 namespace 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.
17 class 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 
53 extern bool operator==(const MockTexture::PaintCall& a,
54  const MockTexture::PaintCall& b);
55 extern std::ostream& operator<<(std::ostream& os,
56  const MockTexture::PaintCall& data);
57 
58 } // namespace testing
59 } // namespace flutter
std::ostream & operator<<(std::ostream &os, const MockTexture::PaintCall &data)
Definition: mock_texture.cc:28
void OnGrContextDestroyed() override
Definition: mock_texture.h:37
const std::vector< PaintCall > & paint_calls()
Definition: mock_texture.h:41
void OnTextureUnregistered() override
Definition: mock_texture.h:39
MockTexture(int64_t textureId)
Definition: mock_texture.cc:10
void Paint(SkCanvas &canvas, const SkRect &bounds, bool freeze, GrDirectContext *context, SkFilterQuality filter_quality) override
Definition: mock_texture.cc:12
bool operator==(const MockTexture::PaintCall &a, const MockTexture::PaintCall &b)
Definition: mock_texture.cc:21
void OnGrContextCreated() override
Definition: mock_texture.h:36
void MarkNewFrameAvailable() override
Definition: mock_texture.h:38