vulkan_surface_producer.h 2.6 KB
Newer Older
1 2 3 4
// 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.

5
#pragma once
6 7 8 9 10

#include "flutter/flow/scene_update_context.h"
#include "flutter/vulkan/vulkan_application.h"
#include "flutter/vulkan/vulkan_device.h"
#include "flutter/vulkan/vulkan_proc_table.h"
C
Craig Stout 已提交
11
#include "flutter/vulkan/vulkan_provider.h"
G
George Kulakowski 已提交
12
#include "lib/fsl/tasks/message_loop.h"
13 14 15
#include "lib/fxl/macros.h"
#include "lib/ui/scenic/client/resources.h"
#include "lib/ui/scenic/client/session.h"
16
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
17 18
#include "vulkan_surface.h"
#include "vulkan_surface_pool.h"
19

20
namespace flutter {
21

22 23 24
class VulkanSurfaceProducer final
    : public flow::SceneUpdateContext::SurfaceProducer,
      public vulkan::VulkanProvider {
25
 public:
26
  VulkanSurfaceProducer(scenic_lib::Session* mozart_session);
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

  ~VulkanSurfaceProducer();

  bool IsValid() const { return valid_; }

  // |flow::SceneUpdateContext::SurfaceProducer|
  std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>
  ProduceSurface(const SkISize& size) override;

  // |flow::SceneUpdateContext::SurfaceProducer|
  void SubmitSurface(
      std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface> surface)
      override;

  void OnSurfacesPresented(
      std::vector<
          std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>>
          surfaces);

 private:
C
Craig Stout 已提交
47 48 49 50 51 52
  // VulkanProvider
  const vulkan::VulkanProcTable& vk() override { return *vk_.get(); }
  const vulkan::VulkanHandle<VkDevice>& vk_device() override {
    return logical_device_->GetHandle();
  }

53 54 55 56 57
  bool TransitionSurfacesToExternal(
      const std::vector<
          std::unique_ptr<flow::SceneUpdateContext::SurfaceProducerSurface>>&
          surfaces);

58 59 60 61 62 63
  // Note: the order here is very important. The proctable must be destroyed
  // last because it contains the function pointers for VkDestroyDevice and
  // VkDestroyInstance. The backend context owns the VkDevice and the
  // VkInstance, so it must be destroyed after the logical device and the
  // application, which own other vulkan objects associated with the device
  // and instance.
64
  fxl::RefPtr<vulkan::VulkanProcTable> vk_;
65 66 67 68 69 70 71
  sk_sp<GrVkBackendContext> backend_context_;
  std::unique_ptr<vulkan::VulkanDevice> logical_device_;
  std::unique_ptr<vulkan::VulkanApplication> application_;
  sk_sp<GrContext> context_;
  std::unique_ptr<VulkanSurfacePool> surface_pool_;
  bool valid_ = false;

72
  bool Initialize(scenic_lib::Session* mozart_session);
73

74
  FXL_DISALLOW_COPY_AND_ASSIGN(VulkanSurfaceProducer);
75 76
};

77
}  // namespace flutter