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

namespace shell {

23 24
class Rasterizer;

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

36 37
  void SetupResourceContextOnIOThread();

38
  virtual ~PlatformView();
39

A
Adam Barth 已提交
40
  void DispatchPlatformMessage(ftl::RefPtr<blink::PlatformMessage> message);
41 42 43
  void DispatchSemanticsAction(int32_t id, blink::SemanticsAction action);
  void SetSemanticsEnabled(bool enabled);

44
  void NotifyCreated(std::unique_ptr<Surface> surface);
45

46 47
  void NotifyCreated(std::unique_ptr<Surface> surface,
                     ftl::Closure continuation);
48 49 50

  void NotifyDestroyed();

51
  std::weak_ptr<PlatformView> GetWeakPtr();
52

53 54 55
  // The VsyncWaiter will live at least as long as the PlatformView.
  virtual VsyncWaiter* GetVsyncWaiter();

56 57
  virtual bool ResourceContextMakeCurrent() = 0;

58
  virtual void UpdateSemantics(std::vector<blink::SemanticsNode> update);
59 60
  virtual void HandlePlatformMessage(
      ftl::RefPtr<blink::PlatformMessage> message);
61

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

A
Adam Barth 已提交
65 66 67
  virtual void RunFromSource(const std::string& assets_directory,
                             const std::string& main,
                             const std::string& packages) = 0;
68

69
 protected:
70
  explicit PlatformView(std::unique_ptr<Rasterizer> rasterizer);
71

72
  void CreateEngine();
73
  void PostAddToShellTask();
74

75 76
  void SetupResourceContextOnIOThreadPerform(
      ftl::AutoResetWaitableEvent* event);
77

78 79 80
  SurfaceConfig surface_config_;
  std::unique_ptr<Rasterizer> rasterizer_;
  std::unique_ptr<Engine> engine_;
81
  std::unique_ptr<VsyncWaiter> vsync_waiter_;
82 83
  SkISize size_;

84
private:
85

86
  FTL_DISALLOW_COPY_AND_ASSIGN(PlatformView);
87 88 89 90
};

}  // namespace shell

91
#endif  // COMMON_PLATFORM_VIEW_H_