platform_view_embedder.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2017 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.

#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_PLATFORM_VIEW_EMBEDDER_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_PLATFORM_VIEW_EMBEDDER_H_

#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"
10
#include "flutter/shell/platform/embedder/embedder.h"
11
#include "lib/fxl/macros.h"
12 13 14

namespace shell {

15 16
class PlatformViewEmbedder final : public PlatformView,
                                   public GPUSurfaceGLDelegate {
17
 public:
18 19
  using PlatformMessageResponseCallback =
      std::function<void(fxl::RefPtr<blink::PlatformMessage>)>;
20
  struct DispatchTable {
21 22 23 24 25
    std::function<bool(void)> gl_make_current_callback;   // required
    std::function<bool(void)> gl_clear_current_callback;  // required
    std::function<bool(void)> gl_present_callback;        // required
    std::function<intptr_t(void)> gl_fbo_callback;        // required
    PlatformMessageResponseCallback
26 27
        platform_message_response_callback;                       // optional
    std::function<bool(void)> gl_make_resource_current_callback;  // optional
28 29
  };

30 31 32
  PlatformViewEmbedder(PlatformView::Delegate& delegate,
                       blink::TaskRunners task_runners,
                       DispatchTable dispatch_table);
33

34
  ~PlatformViewEmbedder() override;
35 36 37 38 39 40 41 42 43 44 45 46 47

  // |shell::GPUSurfaceGLDelegate|
  bool GLContextMakeCurrent() override;

  // |shell::GPUSurfaceGLDelegate|
  bool GLContextClearCurrent() override;

  // |shell::GPUSurfaceGLDelegate|
  bool GLContextPresent() override;

  // |shell::GPUSurfaceGLDelegate|
  intptr_t GLContextFBO() const override;

48 49 50 51
  // |shell::PlatformView|
  void HandlePlatformMessage(
      fxl::RefPtr<blink::PlatformMessage> message) override;

52 53 54
 private:
  DispatchTable dispatch_table_;

55 56 57 58 59 60
  // |shell::PlatformView|
  std::unique_ptr<Surface> CreateRenderingSurface() override;

  // |shell::PlatformView|
  sk_sp<GrContext> CreateResourceContext() const override;

61
  FXL_DISALLOW_COPY_AND_ASSIGN(PlatformViewEmbedder);
62 63 64 65 66
};

}  // namespace shell

#endif  // FLUTTER_SHELL_PLATFORM_EMBEDDER_PLATFORM_VIEW_EMBEDDER_H_