Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_PRODUCER_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_PRODUCER_H_
7
8#include <lib/async/cpp/time.h>
9#include <lib/async/default.h>
10
11#include "flutter/flutter_vma/flutter_skia_vma.h"
12#include "flutter/fml/macros.h"
13#include "flutter/fml/memory/weak_ptr.h"
14#include "flutter/vulkan/procs/vulkan_proc_table.h"
15#include "flutter/vulkan/vulkan_application.h"
16#include "flutter/vulkan/vulkan_device.h"
17#include "flutter/vulkan/vulkan_provider.h"
19
20#include "logging.h"
21#include "vulkan_surface.h"
22#include "vulkan_surface_pool.h"
23
24namespace flutter_runner {
25
28 public:
29 explicit VulkanSurfaceProducer();
30 ~VulkanSurfaceProducer() override;
31
32 bool IsValid() const { return valid_; }
33
34 // |SurfaceProducer|
35 GrDirectContext* gr_context() const override { return context_.get(); }
36
37 // |SurfaceProducer|
38 std::unique_ptr<SurfaceProducerSurface> ProduceOffscreenSurface(
39 const SkISize& size) override;
40
41 // |SurfaceProducer|
42 std::unique_ptr<SurfaceProducerSurface> ProduceSurface(
43 const SkISize& size) override;
44
45 // |SurfaceProducer|
46 void SubmitSurfaces(
47 std::vector<std::unique_ptr<SurfaceProducerSurface>> surfaces) override;
48
49 private:
50 // VulkanProvider
51 const vulkan::VulkanProcTable& vk() override { return *vk_.get(); }
53 return logical_device_->GetHandle();
54 }
55
56 bool Initialize();
57
58 void SubmitSurface(std::unique_ptr<SurfaceProducerSurface> surface);
59 bool TransitionSurfacesToExternal(
60 const std::vector<std::unique_ptr<SurfaceProducerSurface>>& surfaces);
61
62 // Keep track of the last time we produced a surface. This is used to
63 // determine whether it is safe to shrink |surface_pool_| or not.
64 zx::time last_produce_time_ = async::Now(async_get_default_dispatcher());
65
66 // Disallow copy and assignment.
68 VulkanSurfaceProducer& operator=(const VulkanSurfaceProducer&) = delete;
69
70 // Note: the order here is very important. The proctable must be destroyed
71 // last because it contains the function pointers for VkDestroyDevice and
72 // VkDestroyInstance.
74 std::unique_ptr<vulkan::VulkanApplication> application_;
75 std::unique_ptr<vulkan::VulkanDevice> logical_device_;
77 std::unique_ptr<VulkanSurfacePool> surface_pool_;
79 bool valid_ = false;
80
81 // WeakPtrFactory must be the last member.
83};
84
85} // namespace flutter_runner
86
87#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_PRODUCER_H_
const vulkan::VulkanProcTable & vk() override
std::unique_ptr< SurfaceProducerSurface > ProduceOffscreenSurface(const SkISize &size) override
void SubmitSurfaces(std::vector< std::unique_ptr< SurfaceProducerSurface > > surfaces) override
GrDirectContext * gr_context() const override
std::unique_ptr< SurfaceProducerSurface > ProduceSurface(const SkISize &size) override
const vulkan::VulkanHandle< VkDevice > & vk_device() override
T * get() const
Definition ref_ptr.h:116
T * get() const
Definition SkRefCnt.h:303
VkSurfaceKHR surface
Definition main.cc:49