platform_view.h 4.2 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
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 COMMON_PLATFORM_VIEW_H_
#define COMMON_PLATFORM_VIEW_H_
7

8 9
#include <memory>

10
#include "flutter/common/task_runners.h"
11
#include "flutter/flow/texture.h"
12
#include "flutter/fml/macros.h"
13
#include "flutter/fml/memory/weak_ptr.h"
14
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
15
#include "flutter/lib/ui/semantics/semantics_node.h"
16 17 18
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
19
#include "flutter/shell/common/surface.h"
20
#include "flutter/shell/common/vsync_waiter.h"
21
#include "third_party/skia/include/core/SkSize.h"
22
#include "third_party/skia/include/gpu/GrContext.h"
23

24
namespace flutter {
25

26
class Shell;
27

28 29
/// Abstract Base Class that represents the platform specific view we will be
/// rendering to.
30
class PlatformView {
31
 public:
32 33
  class Delegate {
   public:
34
    virtual void OnPlatformViewCreated(std::unique_ptr<Surface> surface) = 0;
35

36
    virtual void OnPlatformViewDestroyed() = 0;
37

38
    virtual void OnPlatformViewSetNextFrameCallback(fml::closure closure) = 0;
39 40

    virtual void OnPlatformViewSetViewportMetrics(
41
        const ViewportMetrics& metrics) = 0;
42 43

    virtual void OnPlatformViewDispatchPlatformMessage(
44
        fml::RefPtr<PlatformMessage> message) = 0;
45 46

    virtual void OnPlatformViewDispatchPointerDataPacket(
47
        std::unique_ptr<PointerDataPacket> packet) = 0;
48 49 50

    virtual void OnPlatformViewDispatchSemanticsAction(
        int32_t id,
51
        SemanticsAction action,
52 53
        std::vector<uint8_t> args) = 0;

54
    virtual void OnPlatformViewSetSemanticsEnabled(bool enabled) = 0;
55

56
    virtual void OnPlatformViewSetAccessibilityFeatures(int32_t flags) = 0;
57

58
    virtual void OnPlatformViewRegisterTexture(
59
        std::shared_ptr<flutter::Texture> texture) = 0;
60

61
    virtual void OnPlatformViewUnregisterTexture(int64_t texture_id) = 0;
62 63 64

    virtual void OnPlatformViewMarkTextureFrameAvailable(
        int64_t texture_id) = 0;
65 66
  };

67
  explicit PlatformView(Delegate& delegate, TaskRunners task_runners);
68

69
  virtual ~PlatformView();
70

71
  virtual std::unique_ptr<VsyncWaiter> CreateVSyncWaiter();
72

73
  void DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
74

75
  void DispatchSemanticsAction(int32_t id,
76
                               SemanticsAction action,
77
                               std::vector<uint8_t> args);
78

79
  virtual void SetSemanticsEnabled(bool enabled);
80

81
  virtual void SetAccessibilityFeatures(int32_t flags);
82

83
  void SetViewportMetrics(const ViewportMetrics& metrics);
84

85
  void NotifyCreated();
86

87
  virtual void NotifyDestroyed();
88

89 90 91
  // Unlike all other methods on the platform view, this one may be called on a
  // non-platform task runner.
  virtual sk_sp<GrContext> CreateResourceContext() const;
92

93 94 95 96
  // Unlike all other methods on the platform view, this one may be called on a
  // non-platform task runner.
  virtual void ReleaseResourceContext() const;

97
  fml::WeakPtr<PlatformView> GetWeakPtr() const;
98

99 100
  virtual void UpdateSemantics(SemanticsNodeUpdates updates,
                               CustomAccessibilityActionUpdates actions);
101

102
  virtual void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message);
103

104 105
  virtual void OnPreEngineRestart() const;

106
  void SetNextFrameCallback(fml::closure closure);
107

108
  void DispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet);
109

110
  // Called once per texture, on the platform thread.
111
  void RegisterTexture(std::shared_ptr<flutter::Texture> texture);
112 113 114 115 116

  // Called once per texture, on the platform thread.
  void UnregisterTexture(int64_t texture_id);

  // Called once per texture update (e.g. video frame), on the platform thread.
117
  void MarkTextureFrameAvailable(int64_t texture_id);
118

119
 protected:
120
  PlatformView::Delegate& delegate_;
121
  const TaskRunners task_runners_;
122

123
  SkISize size_;
124 125
  fml::WeakPtrFactory<PlatformView> weak_factory_;

126 127
  // Unlike all other methods on the platform view, this is called on the GPU
  // task runner.
128
  virtual std::unique_ptr<Surface> CreateRenderingSurface();
129

130
 private:
131
  FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
132 133
};

134
}  // namespace flutter
135

136
#endif  // COMMON_PLATFORM_VIEW_H_