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#ifndef FLOW_TESTING_MOCK_TEXTURE_H_
6#define FLOW_TESTING_MOCK_TEXTURE_H_
7
8#include <ostream>
9#include <vector>
10
11#include "flutter/common/graphics/texture.h"
12#include "flutter/testing/assertions_skia.h"
13
14namespace flutter {
15namespace testing {
16
17// Mock implementation of the |Texture| interface that does not interact with
18// the GPU. It simply records the list of various calls made so the test can
19// later verify them against expected data.
20class MockTexture : public Texture {
21 public:
22 static sk_sp<DlImage> MakeTestTexture(int w, int h, int checker_size);
23
24 explicit MockTexture(int64_t textureId,
25 const sk_sp<DlImage>& texture = nullptr);
26
27 // Called from raster thread.
28 void Paint(PaintContext& context,
29 const SkRect& bounds,
30 bool freeze,
31 const DlImageSampling sampling) override;
32
33 void OnGrContextCreated() override { gr_context_created_ = true; }
34 void OnGrContextDestroyed() override { gr_context_destroyed_ = true; }
35 void MarkNewFrameAvailable() override {}
36 void OnTextureUnregistered() override { unregistered_ = true; }
37
38 bool gr_context_created() { return gr_context_created_; }
39 bool gr_context_destroyed() { return gr_context_destroyed_; }
40 bool unregistered() { return unregistered_; }
41
42 private:
43 sk_sp<DlImage> texture_;
44 bool gr_context_created_ = false;
45 bool gr_context_destroyed_ = false;
46 bool unregistered_ = false;
47};
48
49} // namespace testing
50} // namespace flutter
51
52#endif // FLOW_TESTING_MOCK_TEXTURE_H_
53

source code of flutter_engine/flutter/flow/testing/mock_texture.h