Flutter Engine
The Flutter Engine
device_buffer_gles.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 <cstring>
8#include <memory>
9
10#include "flutter/fml/trace_event.h"
14
15namespace impeller {
16
18 ReactorGLES::Ref reactor,
19 std::shared_ptr<Allocation> backing_store)
21 reactor_(std::move(reactor)),
22 handle_(reactor_ ? reactor_->CreateHandle(HandleType::kBuffer)
23 : HandleGLES::DeadHandle()),
24 backing_store_(std::move(backing_store)) {}
25
26// |DeviceBuffer|
28 if (!handle_.IsDead()) {
29 reactor_->CollectHandle(handle_);
30 }
31}
32
33// |DeviceBuffer|
34uint8_t* DeviceBufferGLES::OnGetContents() const {
35 if (!reactor_) {
36 return nullptr;
37 }
38 return backing_store_->GetBuffer();
39}
40
41// |DeviceBuffer|
42bool DeviceBufferGLES::OnCopyHostBuffer(const uint8_t* source,
43 Range source_range,
44 size_t offset) {
45 if (!reactor_) {
46 return false;
47 }
48
49 if (offset + source_range.length > backing_store_->GetLength()) {
50 return false;
51 }
52
53 std::memmove(backing_store_->GetBuffer() + offset,
54 source + source_range.offset, source_range.length);
55 ++generation_;
56
57 return true;
58}
59
60void DeviceBufferGLES::Flush(std::optional<Range> range) const {
61 generation_++;
62}
63
65 switch (type) {
67 return GL_ARRAY_BUFFER;
69 return GL_ELEMENT_ARRAY_BUFFER;
70 }
72}
73
75 if (!reactor_) {
76 return false;
77 }
78
79 auto buffer = reactor_->GetGLHandle(handle_);
80 if (!buffer.has_value()) {
81 return false;
82 }
83
84 const auto target_type = ToTarget(type);
85 const auto& gl = reactor_->GetProcTable();
86
87 gl.BindBuffer(target_type, buffer.value());
88
89 if (upload_generation_ != generation_) {
90 TRACE_EVENT1("impeller", "BufferData", "Bytes",
91 std::to_string(backing_store_->GetLength()).c_str());
92 gl.BufferData(target_type, backing_store_->GetLength(),
93 backing_store_->GetBuffer(), GL_STATIC_DRAW);
94 upload_generation_ = generation_;
95 }
96
97 return true;
98}
99
100// |DeviceBuffer|
101bool DeviceBufferGLES::SetLabel(const std::string& label) {
102 reactor_->SetDebugLabel(handle_, label);
103 return true;
104}
105
106// |DeviceBuffer|
107bool DeviceBufferGLES::SetLabel(const std::string& label, Range range) {
108 // Cannot support debug label on the range. Set the label for the entire
109 // range.
110 return SetLabel(label);
111}
112
113const uint8_t* DeviceBufferGLES::GetBufferData() const {
114 return backing_store_->GetBuffer();
115}
116
118 const std::function<void(uint8_t* data, size_t length)>&
119 update_buffer_data) {
120 if (update_buffer_data) {
121 update_buffer_data(backing_store_->GetBuffer(),
122 backing_store_->GetLength());
123 ++generation_;
124 }
125}
126
127} // namespace impeller
GLenum type
const char * c_str() const
Definition: SkString.h:133
void Flush(std::optional< Range > range=std::nullopt) const override
DeviceBufferGLES(DeviceBufferDescriptor desc, ReactorGLES::Ref reactor, std::shared_ptr< Allocation > backing_store)
void UpdateBufferData(const std::function< void(uint8_t *, size_t length)> &update_buffer_data)
bool BindAndUploadDataIfNecessary(BindingType type) const
const uint8_t * GetBufferData() const
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:86
SkBitmap source
Definition: examples.cpp:28
#define FML_UNREACHABLE()
Definition: logging.h:109
Dart_NativeFunction function
Definition: fuchsia.cc:51
size_t length
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
static GLenum ToTarget(DeviceBufferGLES::BindingType type)
gl
Definition: malisc.py:41
Definition: ref_ptr.h:256
static SkString to_string(int n)
Definition: nanobench.cpp:119
fuchsia::ui::composition::ParentViewportWatcherHandle handle_
SeparatedVector2 offset
constexpr bool IsDead() const
Definition: handle_gles.h:39
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141