platform_view.h 3.2 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/flow/texture.h"
11
#include "flutter/lib/ui/semantics/semantics_node.h"
12 13
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/shell.h"
14
#include "flutter/shell/common/surface.h"
15
#include "flutter/shell/common/vsync_waiter.h"
16 17 18
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/weak_ptr.h"
#include "lib/fxl/synchronization/waitable_event.h"
19
#include "third_party/skia/include/core/SkSize.h"
20
#include "third_party/skia/include/gpu/GrContext.h"
21 22 23

namespace shell {

24 25
class Rasterizer;

26
class PlatformView : public std::enable_shared_from_this<PlatformView> {
27
 public:
28 29 30 31 32 33 34 35 36
  struct SurfaceConfig {
    uint8_t red_bits = 8;
    uint8_t green_bits = 8;
    uint8_t blue_bits = 8;
    uint8_t alpha_bits = 8;
    uint8_t depth_bits = 0;
    uint8_t stencil_bits = 8;
  };

37 38
  void SetupResourceContextOnIOThread();

39
  virtual ~PlatformView();
40

41 42
  virtual void Attach() = 0;

43
  void DispatchPlatformMessage(fxl::RefPtr<blink::PlatformMessage> message);
44 45 46
  void DispatchSemanticsAction(int32_t id,
                               blink::SemanticsAction action,
                               std::vector<uint8_t> args);
47 48
  void SetSemanticsEnabled(bool enabled);

49
  void NotifyCreated(std::unique_ptr<Surface> surface);
50

51
  void NotifyCreated(std::unique_ptr<Surface> surface,
52
                     fxl::Closure continuation);
53 54 55

  void NotifyDestroyed();

56
  std::weak_ptr<PlatformView> GetWeakPtr();
57

58 59 60
  // The VsyncWaiter will live at least as long as the PlatformView.
  virtual VsyncWaiter* GetVsyncWaiter();

61 62
  virtual bool ResourceContextMakeCurrent() = 0;

Y
Yegor 已提交
63
  virtual void UpdateSemantics(blink::SemanticsNodeUpdates update);
64
  virtual void HandlePlatformMessage(
65
      fxl::RefPtr<blink::PlatformMessage> message);
66

67 68 69 70 71 72 73 74 75
  // 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.
  virtual void MarkTextureFrameAvailable(int64_t texture_id);

76 77
  void SetRasterizer(std::unique_ptr<Rasterizer> rasterizer);

78
  Rasterizer& rasterizer() { return *rasterizer_; }
79
  Engine& engine() { return *engine_; }
80

A
Adam Barth 已提交
81 82 83
  virtual void RunFromSource(const std::string& assets_directory,
                             const std::string& main,
                             const std::string& packages) = 0;
84

85 86
  virtual void SetAssetBundlePath(const std::string& assets_directory) = 0;

87
 protected:
88
  explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);
89

90 91
  void CreateEngine();

92
  void SetupResourceContextOnIOThreadPerform(
93
      fxl::AutoResetWaitableEvent* event);
94

95 96
  SurfaceConfig surface_config_;
  std::unique_ptr<Rasterizer> rasterizer_;
97
  flow::TextureRegistry texture_registry_;
98
  std::unique_ptr<Engine> engine_;
99
  std::unique_ptr<VsyncWaiter> vsync_waiter_;
100 101
  SkISize size_;

102
 private:
103
  FXL_DISALLOW_COPY_AND_ASSIGN(PlatformView);
104 105 106 107
};

}  // namespace shell

108
#endif  // COMMON_PLATFORM_VIEW_H_