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
#include "lib/fxl/macros.h"
17 18
#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
class Rasterizer;
25

26
class PlatformView : public std::enable_shared_from_this<PlatformView> {
27
 public:
28 29 30 31 32 33 34
  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 = 0;
35 36
  };

37
  void SetupResourceContextOnIOThread();
38

39
  virtual ~PlatformView();
40

41
  virtual void Attach() = 0;
42

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
  void SetSemanticsEnabled(bool enabled);
48

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

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

54
  void NotifyDestroyed();
55

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

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

61
  virtual bool ResourceContextMakeCurrent() = 0;
62

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
  // 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.
74 75 76 77 78 79 80 81 82 83 84 85
  virtual void MarkTextureFrameAvailable(int64_t texture_id);

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

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

  virtual void RunFromSource(const std::string& assets_directory,
                             const std::string& main,
                             const std::string& packages) = 0;

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

87
 protected:
88 89 90 91 92 93 94 95 96 97 98
  explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);

  void CreateEngine();

  void SetupResourceContextOnIOThreadPerform(
      fxl::AutoResetWaitableEvent* event);

  SurfaceConfig surface_config_;
  std::unique_ptr<Rasterizer> rasterizer_;
  flow::TextureRegistry texture_registry_;
  std::unique_ptr<Engine> engine_;
99
  std::unique_ptr<VsyncWaiter> vsync_waiter_;
100

101 102
  SkISize size_;

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

}  // namespace shell

109
#endif  // COMMON_PLATFORM_VIEW_H_