Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
images_impeller.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#define GL_GLEXT_PROTOTYPES
6
9
13#include "third_party/skia/include/core/SkData.h"
14
20
21#include <emscripten/wasm_worker.h>
22
23extern "C" {
24void skwasm_dispatchDisposeDlImage(unsigned long thread_id, void* pointer);
25void skwasm_disposeDlImageOnWorker(void* dl_image_ptr);
26}
27
28namespace Skwasm {
29
31 public:
33
34 // |DlImageImpeller|
35 std::shared_ptr<impeller::Texture> GetImpellerTexture(
36 const std::shared_ptr<impeller::Context>& context) const override {
37 return nullptr;
38 }
39
40 bool isOpaque() const override { return false; }
41 bool isUIThreadSafe() const override { return true; }
45
46 virtual ~DlWimpImageBase();
47
48 flutter::DlISize GetSize() const override {
50 }
51
52 size_t GetApproximateByteSize() const override {
53 return width_ * height_ * 4;
54 }
55
56 protected:
57 int width_;
59};
60
62 if (emscripten_wasm_worker_self_id() == GetRasterThread()) {
64 } else {
66 }
67}
68
70 public:
72 int height,
73 SkwasmObject texture_source,
74 Skwasm::Surface* surface)
76 texture_source_wrapper_(
77 surface->CreateTextureSourceWrapper(texture_source)) {}
78
79 std::shared_ptr<impeller::Texture> GetImpellerTexture(
80 const std::shared_ptr<impeller::Context>& context) const override {
81 auto* gles_context = impeller::ContextGLES::Cast(context.get());
82 GLuint gl_texture_id = skwasm_createGlTextureFromTextureSource(
83 texture_source_wrapper_->GetTextureSource(), width_, height_);
84
88 desc.mip_count = 1;
90 desc.usage = static_cast<impeller::TextureUsageMask>(
92
93 impeller::HandleGLES external_handle =
94 gles_context->GetReactor()->CreateHandle(impeller::HandleType::kTexture,
95 gl_texture_id);
96
98 gles_context->GetReactor(), desc, std::move(external_handle));
99 if (texture) {
100 texture->SetCoordinateSystem(
102 }
103 return texture;
104 }
105
106 private:
107 std::unique_ptr<Skwasm::TextureSourceWrapper> texture_source_wrapper_;
108};
109
111 public:
113 int height,
114 sk_sp<SkData> data,
115 Skwasm::PixelFormat format,
116 size_t row_byte_count)
118 data_(std::move(data)),
119 format_(format),
120 row_byte_count_(row_byte_count) {}
121
122 std::shared_ptr<impeller::Texture> GetImpellerTexture(
123 const std::shared_ptr<impeller::Context>& context) const override {
126
127 if (format_ == Skwasm::PixelFormat::bgra8888) {
129 } else if (format_ == Skwasm::PixelFormat::rgba8888) {
131 } else {
133 }
134
135 desc.mip_count = 1;
137 desc.usage = static_cast<impeller::TextureUsageMask>(
139
140 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
141 if (!texture) {
142 return nullptr;
143 }
144
145 if (!texture->SetContents(static_cast<const uint8_t*>(data_->bytes()),
146 data_->size(), 0)) {
147 return nullptr;
148 }
149 return texture;
150 }
151
152 private:
153 sk_sp<SkData> data_;
154 Skwasm::PixelFormat format_;
155 size_t row_byte_count_;
156};
157
159 public:
161 int height,
162 sk_sp<flutter::DisplayList> display_list)
164 display_list_(std::move(display_list)) {}
165
166 std::shared_ptr<impeller::Texture> GetImpellerTexture(
167 const std::shared_ptr<impeller::Context>& context) const override {
168 impeller::AiksContext aiks_context(context, nullptr);
170 display_list_, impeller::ISize(width_, height_), aiks_context);
171 }
172
173 private:
174 sk_sp<flutter::DisplayList> display_list_;
175};
176
177sk_sp<flutter::DlImage> MakeImageFromPicture(flutter::DisplayList* display_list,
178 int32_t width,
179 int32_t height) {
180 return sk_make_sp<DlWimpImageFromPicture>(width, height,
181 sk_ref_sp(display_list));
182}
183
184sk_sp<flutter::DlImage> MakeImageFromTexture(SkwasmObject texture_source,
185 int width,
186 int height,
187 Skwasm::Surface* surface) {
188 return sk_sp<flutter::DlImage>(
189 new DlWimpImageFromTexture(width, height, texture_source, surface));
190}
191
192sk_sp<flutter::DlImage> MakeImageFromPixels(SkData* data,
193 int width,
194 int height,
195 Skwasm::PixelFormat pixel_format,
196 size_t row_byte_count) {
197 return sk_make_sp<DlWimpImageFromPixels>(width, height, sk_ref_sp(data),
198 pixel_format, row_byte_count);
199}
200} // namespace Skwasm
DlWimpImageBase(int width, int height)
flutter::DlColorSpace GetColorSpace() const override
Gets the color space of the image.
flutter::DlISize GetSize() const override
std::shared_ptr< impeller::Texture > GetImpellerTexture(const std::shared_ptr< impeller::Context > &context) const override
bool isOpaque() const override
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
size_t GetApproximateByteSize() const override
bool isUIThreadSafe() const override
If the underlying platform image held by this object has no threading requirements for the release of...
DlWimpImageFromPicture(int width, int height, sk_sp< flutter::DisplayList > display_list)
std::shared_ptr< impeller::Texture > GetImpellerTexture(const std::shared_ptr< impeller::Context > &context) const override
DlWimpImageFromPixels(int width, int height, sk_sp< SkData > data, Skwasm::PixelFormat format, size_t row_byte_count)
std::shared_ptr< impeller::Texture > GetImpellerTexture(const std::shared_ptr< impeller::Context > &context) const override
std::shared_ptr< impeller::Texture > GetImpellerTexture(const std::shared_ptr< impeller::Context > &context) const override
DlWimpImageFromTexture(int width, int height, SkwasmObject texture_source, Skwasm::Surface *surface)
int height() const
Definition dl_image.cc:19
int width() const
Definition dl_image.cc:15
static ContextGLES & Cast(Context &base)
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition handle_gles.h:42
static std::shared_ptr< TextureGLES > WrapTexture(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is as...
VkSurfaceKHR surface
Definition main.cc:65
uint32_t uint32_t * format
void skwasm_disposeDlImageOnWorker(void *dl_image_ptr)
void skwasm_dispatchDisposeDlImage(unsigned long thread_id, void *pointer)
FlTexture * texture
sk_sp< flutter::DlImage > MakeImageFromTexture(SkwasmObject texture_source, int width, int height, Skwasm::Surface *surface)
__externref_t SkwasmObject
Definition wrappers.h:18
unsigned long GetRasterThread()
Definition surface.cc:44
sk_sp< flutter::DlImage > MakeImageFromPicture(flutter::DisplayList *display_list, int32_t width, int32_t height)
PixelFormat
Definition images.h:13
sk_sp< flutter::DlImage > MakeImageFromPixels(SkData *data, int width, int height, PixelFormat pixel_format, size_t row_byte_count)
DlColorSpace
Definition dl_color.h:13
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
ISize64 ISize
Definition size.h:162
Definition ref_ptr.h:261
int32_t height
int32_t width
unsigned int skwasm_createGlTextureFromTextureSource(SkwasmObject texture_source, int width, int height)
static constexpr TSize MakeWH(Type width, Type height)
Definition size.h:43
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...