Flutter Engine
vulkan_surface_producer.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <lib/async/cpp/time.h>
8 #include <lib/async/default.h>
9 #include <lib/syslog/global.h>
10 
11 #include "flutter/fml/macros.h"
12 #include "flutter/fml/memory/weak_ptr.h"
13 #include "flutter/vulkan/vulkan_application.h"
14 #include "flutter/vulkan/vulkan_device.h"
15 #include "flutter/vulkan/vulkan_proc_table.h"
16 #include "flutter/vulkan/vulkan_provider.h"
17 #include "lib/ui/scenic/cpp/resources.h"
18 #include "lib/ui/scenic/cpp/session.h"
19 #include "logging.h"
20 #include "vulkan_surface.h"
21 #include "vulkan_surface_pool.h"
22 
23 namespace flutter_runner {
24 
26  public vulkan::VulkanProvider {
27  public:
28  VulkanSurfaceProducer(scenic::Session* scenic_session);
29 
31 
32  bool IsValid() const { return valid_; }
33 
34  // |SurfaceProducer|
35  std::unique_ptr<SurfaceProducerSurface> ProduceSurface(
36  const SkISize& size) override;
37 
38  // |SurfaceProducer|
39  void SubmitSurface(std::unique_ptr<SurfaceProducerSurface> surface) override;
40 
42  std::vector<std::unique_ptr<SurfaceProducerSurface>> surfaces);
43 
44  GrDirectContext* gr_context() { return context_.get(); }
45 
46  private:
47  // VulkanProvider
48  const vulkan::VulkanProcTable& vk() override { return *vk_.get(); }
49  const vulkan::VulkanHandle<VkDevice>& vk_device() override {
50  return logical_device_->GetHandle();
51  }
52 
53  bool TransitionSurfacesToExternal(
54  const std::vector<std::unique_ptr<SurfaceProducerSurface>>& surfaces);
55 
56  // Note: the order here is very important. The proctable must be destroyed
57  // last because it contains the function pointers for VkDestroyDevice and
58  // VkDestroyInstance.
60  std::unique_ptr<vulkan::VulkanApplication> application_;
61  std::unique_ptr<vulkan::VulkanDevice> logical_device_;
62  sk_sp<GrDirectContext> context_;
63  std::unique_ptr<VulkanSurfacePool> surface_pool_;
64  bool valid_ = false;
65 
66  // Keep track of the last time we produced a surface. This is used to
67  // determine whether it is safe to shrink |surface_pool_| or not.
68  zx::time last_produce_time_ = async::Now(async_get_default_dispatcher());
70 
71  bool Initialize(scenic::Session* scenic_session);
72 
73  // Disallow copy and assignment.
75  VulkanSurfaceProducer& operator=(const VulkanSurfaceProducer&) = delete;
76 };
77 
78 } // namespace flutter_runner
void SubmitSurface(std::unique_ptr< SurfaceProducerSurface > surface) override
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
void OnSurfacesPresented(std::vector< std::unique_ptr< SurfaceProducerSurface >> surfaces)
VulkanSurfaceProducer(scenic::Session *scenic_session)
T * get() const
Definition: ref_ptr.h:112
std::unique_ptr< SurfaceProducerSurface > ProduceSurface(const SkISize &size) override