platform_view.h 4.5 KB
Newer Older
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 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 25

namespace shell {

26
class Shell;
27

28
class PlatformView {
29
 public:
30 31 32 33 34 35 36 37
  class Delegate {
   public:
    virtual void OnPlatformViewCreated(const PlatformView& view,
                                       std::unique_ptr<Surface> surface) = 0;

    virtual void OnPlatformViewDestroyed(const PlatformView& view) = 0;

    virtual void OnPlatformViewSetNextFrameCallback(const PlatformView& view,
38
                                                    fml::closure closure) = 0;
39 40 41 42 43 44 45

    virtual void OnPlatformViewSetViewportMetrics(
        const PlatformView& view,
        const blink::ViewportMetrics& metrics) = 0;

    virtual void OnPlatformViewDispatchPlatformMessage(
        const PlatformView& view,
46
        fml::RefPtr<blink::PlatformMessage> message) = 0;
47 48 49 50 51 52 53 54 55 56 57 58 59 60

    virtual void OnPlatformViewDispatchPointerDataPacket(
        const PlatformView& view,
        std::unique_ptr<blink::PointerDataPacket> packet) = 0;

    virtual void OnPlatformViewDispatchSemanticsAction(
        const PlatformView& view,
        int32_t id,
        blink::SemanticsAction action,
        std::vector<uint8_t> args) = 0;

    virtual void OnPlatformViewSetSemanticsEnabled(const PlatformView& view,
                                                   bool enabled) = 0;

61
    virtual void OnPlatformViewSetAccessibilityFeatures(
62
        const PlatformView& view,
63
        int32_t flags) = 0;
64

65 66 67 68 69 70 71 72 73 74
    virtual void OnPlatformViewRegisterTexture(
        const PlatformView& view,
        std::shared_ptr<flow::Texture> texture) = 0;

    virtual void OnPlatformViewUnregisterTexture(const PlatformView& view,
                                                 int64_t texture_id) = 0;

    virtual void OnPlatformViewMarkTextureFrameAvailable(
        const PlatformView& view,
        int64_t texture_id) = 0;
75 76
  };

77
  explicit PlatformView(Delegate& delegate, blink::TaskRunners task_runners);
78

79
  virtual ~PlatformView();
80

81
  virtual std::unique_ptr<VsyncWaiter> CreateVSyncWaiter();
82

83
  void DispatchPlatformMessage(fml::RefPtr<blink::PlatformMessage> message);
84

85 86 87
  void DispatchSemanticsAction(int32_t id,
                               blink::SemanticsAction action,
                               std::vector<uint8_t> args);
88

89
  virtual void SetSemanticsEnabled(bool enabled);
90

91
  virtual void SetAccessibilityFeatures(int32_t flags);
92

93
  void SetViewportMetrics(const blink::ViewportMetrics& metrics);
94

95
  void NotifyCreated();
96

97
  virtual void NotifyDestroyed();
98

99 100 101
  // 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;
102

103
  fml::WeakPtr<PlatformView> GetWeakPtr() const;
104

105 106
  virtual void UpdateSemantics(blink::SemanticsNodeUpdates updates,
                               blink::CustomAccessibilityActionUpdates actions);
107

108
  virtual void HandlePlatformMessage(
109
      fml::RefPtr<blink::PlatformMessage> message);
110

111
  void SetNextFrameCallback(fml::closure closure);
112 113 114 115

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

116 117 118 119 120 121 122
  // Called once per texture, on the platform thread.
  void RegisterTexture(std::shared_ptr<flow::Texture> texture);

  // 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.
123
  void MarkTextureFrameAvailable(int64_t texture_id);
124

125
 protected:
126 127
  PlatformView::Delegate& delegate_;
  const blink::TaskRunners task_runners_;
128

129
  SkISize size_;
130 131 132
  fml::WeakPtrFactory<PlatformView> weak_factory_;

  virtual std::unique_ptr<Surface> CreateRenderingSurface();
133

134
 private:
135
  FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
136 137 138 139
};

}  // namespace shell

140
#endif  // COMMON_PLATFORM_VIEW_H_