rasterizer.h 2.1 KB
Newer Older
A
Adam Barth 已提交
1 2 3 4
// Copyright 2015 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.

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/layers/layer_tree.h"
12
#include "flutter/fml/memory/weak_ptr.h"
13
#include "flutter/shell/common/surface.h"
14
#include "flutter/synchronization/pipeline.h"
15 16
#include "lib/fxl/functional/closure.h"
#include "lib/fxl/synchronization/waitable_event.h"
A
Adam Barth 已提交
17 18 19

namespace shell {

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

24
  ~Rasterizer();
25

26
  void Setup(std::unique_ptr<Surface> surface);
27

28
  void Teardown();
29

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

32
  flow::LayerTree* GetLastLayerTree();
33

34
  void DrawLastLayerTree();
35

36
  flow::TextureRegistry* GetTextureRegistry();
37

38
  void Draw(fxl::RefPtr<flutter::Pipeline<flow::LayerTree>> pipeline);
39

40 41 42 43 44
  enum class ScreenshotType {
    SkiaPicture,
    UncompressedImage,  // In kN32_SkColorType format
    CompressedImage,
  };
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
  struct Screenshot {
    sk_sp<SkData> data;
    SkISize frame_size = SkISize::MakeEmpty();

    Screenshot() {}

    Screenshot(sk_sp<SkData> p_data, SkISize p_size)
        : data(std::move(p_data)), frame_size(p_size) {}
  };

  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.
  void SetNextFrameCallback(fxl::Closure callback);

 private:
  blink::TaskRunners task_runners_;
  std::unique_ptr<Surface> surface_;
  std::unique_ptr<flow::CompositorContext> compositor_context_;
  std::unique_ptr<flow::LayerTree> last_layer_tree_;
  fxl::Closure next_frame_callback_;
  fml::WeakPtr<Rasterizer> weak_prototype_;
  fml::WeakPtrFactory<Rasterizer> weak_factory_;

  void DoDraw(std::unique_ptr<flow::LayerTree> layer_tree);

  bool DrawToSurface(flow::LayerTree& layer_tree);

  void FireNextFrameCallbackIfPresent();

  FXL_DISALLOW_COPY_AND_ASSIGN(Rasterizer);
A
Adam Barth 已提交
78 79 80 81
};

}  // namespace shell

82
#endif  // SHELL_COMMON_RASTERIZER_H_