Flutter Engine
The Flutter Engine
device_buffer_vk.cc
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
6
7#include "flutter/flutter_vma/flutter_vma.h"
8#include "flutter/fml/trace_event.h"
10#include "vulkan/vulkan_core.h"
11
12namespace impeller {
13
15 std::weak_ptr<Context> context,
17 VmaAllocationInfo info)
19 context_(std::move(context)),
20 resource_(ContextVK::Cast(*context_.lock().get()).GetResourceManager(),
22 std::move(buffer), //
23 info //
24 }) {}
25
27
28uint8_t* DeviceBufferVK::OnGetContents() const {
29 return static_cast<uint8_t*>(resource_->info.pMappedData);
30}
31
32bool DeviceBufferVK::OnCopyHostBuffer(const uint8_t* source,
33 Range source_range,
34 size_t offset) {
35 uint8_t* dest = OnGetContents();
36
37 if (!dest) {
38 return false;
39 }
40
41 if (source) {
42 ::memmove(dest + offset, source + source_range.offset, source_range.length);
43 }
44 ::vmaFlushAllocation(resource_->buffer.get().allocator,
45 resource_->buffer.get().allocation, offset,
46 source_range.length);
47
48 return true;
49}
50
51bool DeviceBufferVK::SetLabel(const std::string& label) {
52 auto context = context_.lock();
53 if (!context || !resource_->buffer.is_valid()) {
54 // The context could have died at this point.
55 return false;
56 }
57
58 ::vmaSetAllocationName(resource_->buffer.get().allocator, //
59 resource_->buffer.get().allocation, //
60 label.c_str() //
61 );
62
63 return ContextVK::Cast(*context).SetDebugName(resource_->buffer.get().buffer,
64 label);
65}
66
67void DeviceBufferVK::Flush(std::optional<Range> range) const {
68 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
69 ::vmaFlushAllocation(resource_->buffer.get().allocator,
70 resource_->buffer.get().allocation, flush_range.offset,
71 flush_range.length);
72}
73
74void DeviceBufferVK::Invalidate(std::optional<Range> range) const {
75 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
76 ::vmaInvalidateAllocation(resource_->buffer.get().allocator,
77 resource_->buffer.get().allocation,
78 flush_range.offset, flush_range.length);
79}
80
81bool DeviceBufferVK::SetLabel(const std::string& label, Range range) {
82 // We do not have the ability to name ranges. Just name the whole thing.
83 return SetLabel(label);
84}
85
86vk::Buffer DeviceBufferVK::GetBuffer() const {
87 return resource_->buffer.get().buffer;
88}
89
90} // namespace impeller
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:108
DeviceBufferVK(DeviceBufferDescriptor desc, std::weak_ptr< Context > context, UniqueBufferVMA buffer, VmaAllocationInfo info)
vk::Buffer GetBuffer() const
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
SkBitmap source
Definition: examples.cpp:28
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
Resource< BufferView > BufferResource
Definition: command.h:57
const myers::Point & get(const myers::Segment &)
Definition: ref_ptr.h:256
dest
Definition: zip.py:79
SeparatedVector2 offset