rasterizer.h 2.7 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
A
Adam Barth 已提交
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef SHELL_COMMON_RASTERIZER_H_
#define SHELL_COMMON_RASTERIZER_H_
A
Adam Barth 已提交
7 8

#include <memory>
A
Adam Barth 已提交
9

10
#include "flutter/common/task_runners.h"
11
#include "flutter/flow/compositor_context.h"
12
#include "flutter/flow/layers/layer_tree.h"
13
#include "flutter/fml/closure.h"
14
#include "flutter/fml/memory/weak_ptr.h"
15
#include "flutter/fml/synchronization/waitable_event.h"
16
#include "flutter/lib/ui/snapshot_delegate.h"
17
#include "flutter/shell/common/surface.h"
18
#include "flutter/synchronization/pipeline.h"
A
Adam Barth 已提交
19 20 21

namespace shell {

22
class Rasterizer final : public blink::SnapshotDelegate {
A
Adam Barth 已提交
23
 public:
24
  Rasterizer(blink::TaskRunners task_runners);
25

26 27 28
  Rasterizer(blink::TaskRunners task_runners,
             std::unique_ptr<flow::CompositorContext> compositor_context);

29
  ~Rasterizer();
30

31
  void Setup(std::unique_ptr<Surface> surface);
32

33
  void Teardown();
34

35
  fml::WeakPtr<Rasterizer> GetWeakPtr() const;
A
Adam Barth 已提交
36

37 38
  fml::WeakPtr<blink::SnapshotDelegate> GetSnapshotDelegate() const;

39
  flow::LayerTree* GetLastLayerTree();
40

41
  void DrawLastLayerTree();
42

43
  flow::TextureRegistry* GetTextureRegistry();
44

45
  void Draw(fml::RefPtr<flutter::Pipeline<flow::LayerTree>> pipeline);
46

47 48 49 50 51
  enum class ScreenshotType {
    SkiaPicture,
    UncompressedImage,  // In kN32_SkColorType format
    CompressedImage,
  };
52

53 54 55 56
  struct Screenshot {
    sk_sp<SkData> data;
    SkISize frame_size = SkISize::MakeEmpty();

57
    Screenshot();
58

59 60 61 62 63
    Screenshot(sk_sp<SkData> p_data, SkISize p_size);

    Screenshot(const Screenshot& other);

    ~Screenshot();
64 65 66 67 68 69
  };

  Screenshot ScreenshotLastLayerTree(ScreenshotType type, bool base64_encode);

  // Sets a callback that will be executed after the next frame is submitted to
  // the surface on the GPU task runner.
70
  void SetNextFrameCallback(fml::closure callback);
71

72 73 74 75
  flow::CompositorContext* compositor_context() {
    return compositor_context_.get();
  }

76 77 78
 private:
  blink::TaskRunners task_runners_;
  std::unique_ptr<Surface> surface_;
79
  std::unique_ptr<flow::CompositorContext> compositor_context_;
80
  std::unique_ptr<flow::LayerTree> last_layer_tree_;
81
  fml::closure next_frame_callback_;
82 83
  fml::WeakPtrFactory<Rasterizer> weak_factory_;

84 85 86 87
  // |blink::SnapshotDelegate|
  sk_sp<SkImage> MakeRasterSnapshot(sk_sp<SkPicture> picture,
                                    SkISize picture_size) override;

88 89 90 91 92 93
  void DoDraw(std::unique_ptr<flow::LayerTree> layer_tree);

  bool DrawToSurface(flow::LayerTree& layer_tree);

  void FireNextFrameCallbackIfPresent();

94
  FML_DISALLOW_COPY_AND_ASSIGN(Rasterizer);
A
Adam Barth 已提交
95 96 97 98
};

}  // namespace shell

99
#endif  // SHELL_COMMON_RASTERIZER_H_