Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
texture.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
5#include "flutter/lib/gpu/texture.h"
6
7#include "flutter/lib/gpu/formats.h"
8#include "flutter/lib/ui/painting/image.h"
9#include "fml/mapping.h"
15
16namespace flutter {
17namespace gpu {
18
20
21Texture::Texture(std::shared_ptr<impeller::Texture> texture)
22 : texture_(std::move(texture)) {}
23
24Texture::~Texture() = default;
25
26std::shared_ptr<impeller::Texture> Texture::GetTexture() {
27 return texture_;
28}
29
31 impeller::TextureCoordinateSystem coordinate_system) {
32 texture_->SetCoordinateSystem(coordinate_system);
33}
34
35bool Texture::Overwrite(const tonic::DartByteData& source_bytes) {
36 const uint8_t* data = static_cast<const uint8_t*>(source_bytes.data());
37 auto copy = std::vector<uint8_t>(data, data + source_bytes.length_in_bytes());
38 // Texture::SetContents is a bit funky right now. It takes a shared_ptr of a
39 // mapping and we're forced to copy here.
40 auto mapping = std::make_shared<fml::DataMapping>(copy);
41 if (!texture_->SetContents(mapping)) {
42 return false;
43 }
44 return true;
45}
46
49 texture_->GetTextureDescriptor().format);
50}
51
53 // DlImageImpeller isn't compiled in builds with Impeller disabled. If
54 // Impeller is disabled, it's impossible to get here anyhow, so just ifdef it
55 // out.
56#if IMPELLER_SUPPORTS_RENDERING
58 auto dl_image = impeller::DlImageImpeller::Make(texture_);
59 image->set_image(dl_image);
60 auto wrapped = image->CreateOuterWrapping();
61 return wrapped;
62#else
63 return Dart_Null();
64#endif
65}
66
67} // namespace gpu
68} // namespace flutter
69
70//----------------------------------------------------------------------------
71/// Exports
72///
73
75 flutter::gpu::Context* gpu_context,
76 int storage_mode,
77 int format,
78 int width,
79 int height,
80 int sample_count,
81 int coordinate_system,
82 bool enable_render_target_usage,
83 bool enable_shader_read_usage,
84 bool enable_shader_write_usage) {
86 desc.storage_mode = flutter::gpu::ToImpellerStorageMode(storage_mode);
87 desc.size = {width, height};
89 desc.usage = {};
90 if (enable_render_target_usage) {
92 }
93 if (enable_shader_read_usage) {
95 }
96 if (enable_shader_write_usage) {
98 }
99 switch (sample_count) {
100 case 1:
102 desc.sample_count = impeller::SampleCount::kCount1;
103 break;
104 case 4:
106 desc.sample_count = impeller::SampleCount::kCount4;
107 break;
108 default:
109 return false;
110 }
111 auto texture =
112 gpu_context->GetContext()->GetResourceAllocator()->CreateTexture(desc);
113 if (!texture) {
114 FML_LOG(ERROR) << "Failed to create texture.";
115 return false;
116 }
117
118 texture->SetCoordinateSystem(
120
121 auto res = fml::MakeRefCounted<flutter::gpu::Texture>(std::move(texture));
122 res->AssociateWithDartWrapper(wrapper);
123
124 return true;
125}
126
128 flutter::gpu::Texture* wrapper,
129 int coordinate_system) {
130 return wrapper->SetCoordinateSystem(
132}
133
135 Dart_Handle source_byte_data) {
136 return texture->Overwrite(tonic::DartByteData(source_byte_data));
137}
138
140 flutter::gpu::Texture* wrapper) {
141 return wrapper->GetBytesPerTexel();
142}
143
static sk_sp< GrTextureProxy > wrapped(skiatest::Reporter *reporter, GrRecordingContext *rContext, GrProxyProvider *proxyProvider, SkBackingFit fit)
static fml::RefPtr< CanvasImage > Create()
Definition image.h:28
std::shared_ptr< impeller::Context > GetContext()
Definition context.cc:65
Texture(std::shared_ptr< impeller::Texture > texture)
Definition texture.cc:21
size_t GetBytesPerTexel()
Definition texture.cc:47
std::shared_ptr< impeller::Texture > GetTexture()
Definition texture.cc:26
bool Overwrite(const tonic::DartByteData &source_bytes)
Definition texture.cc:35
Dart_Handle AsImage() const
Definition texture.cc:52
void SetCoordinateSystem(impeller::TextureCoordinateSystem coordinate_system)
Definition texture.cc:30
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
const void * data() const
size_t length_in_bytes() const
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_Null(void)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
sk_sp< SkImage > image
Definition examples.cpp:29
uint32_t uint32_t * format
#define FML_LOG(severity)
Definition logging.h:82
void InternalFlutterGpu_Texture_SetCoordinateSystem(flutter::gpu::Texture *wrapper, int coordinate_system)
Definition texture.cc:127
Dart_Handle InternalFlutterGpu_Texture_AsImage(flutter::gpu::Texture *wrapper)
Definition texture.cc:144
bool InternalFlutterGpu_Texture_Overwrite(flutter::gpu::Texture *texture, Dart_Handle source_byte_data)
Definition texture.cc:134
int InternalFlutterGpu_Texture_BytesPerTexel(flutter::gpu::Texture *wrapper)
Definition texture.cc:139
bool InternalFlutterGpu_Texture_Initialize(Dart_Handle wrapper, flutter::gpu::Context *gpu_context, int storage_mode, int format, int width, int height, int sample_count, int coordinate_system, bool enable_render_target_usage, bool enable_shader_read_usage, bool enable_shader_write_usage)
Definition texture.cc:74
FlTexture * texture
Definition copy.py:1
constexpr impeller::PixelFormat ToImpellerPixelFormat(FlutterGPUPixelFormat value)
Definition formats.h:60
constexpr impeller::TextureCoordinateSystem ToImpellerTextureCoordinateSystem(FlutterGPUTextureCoordinateSystem value)
Definition formats.h:145
constexpr impeller::StorageMode ToImpellerStorageMode(FlutterGPUStorageMode value)
Definition formats.h:25
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:448
TextureCoordinateSystem
Definition formats.h:328
Definition ref_ptr.h:256
int32_t height
int32_t width
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define ERROR(message)