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 return texture;
100 }
101
102 private:
103 std::unique_ptr<Skwasm::TextureSourceWrapper> texture_source_wrapper_;
104};
105
107 public:
109 int height,
110 sk_sp<SkData> data,
111 Skwasm::PixelFormat format,
112 size_t row_byte_count)
114 data_(std::move(data)),
115 format_(format),
116 row_byte_count_(row_byte_count) {}
117
118 std::shared_ptr<impeller::Texture> GetImpellerTexture(
119 const std::shared_ptr<impeller::Context>& context) const override {
122
123 if (format_ == Skwasm::PixelFormat::bgra8888) {
125 } else if (format_ == Skwasm::PixelFormat::rgba8888) {
127 } else {
129 }
130
131 desc.mip_count = 1;
133 desc.usage = static_cast<impeller::TextureUsageMask>(
135
136 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
137 if (!texture) {
138 return nullptr;
139 }
140
141 if (!texture->SetContents(static_cast<const uint8_t*>(data_->bytes()),
142 data_->size(), 0)) {
143 return nullptr;
144 }
145 return texture;
146 }
147
148 private:
149 sk_sp<SkData> data_;
150 Skwasm::PixelFormat format_;
151 size_t row_byte_count_;
152};
153
155 public:
157 int height,
158 sk_sp<flutter::DisplayList> display_list)
160 display_list_(std::move(display_list)) {}
161
162 std::shared_ptr<impeller::Texture> GetImpellerTexture(
163 const std::shared_ptr<impeller::Context>& context) const override {
164 impeller::AiksContext aiks_context(context, nullptr);
166 display_list_, impeller::ISize(width_, height_), aiks_context);
167 }
168
169 private:
170 sk_sp<flutter::DisplayList> display_list_;
171};
172
173sk_sp<flutter::DlImage> MakeImageFromPicture(flutter::DisplayList* display_list,
174 int32_t width,
175 int32_t height) {
176 return sk_make_sp<DlWimpImageFromPicture>(width, height,
177 sk_ref_sp(display_list));
178}
179
180sk_sp<flutter::DlImage> MakeImageFromTexture(SkwasmObject texture_source,
181 int width,
182 int height,
183 Skwasm::Surface* surface) {
184 return sk_sp<flutter::DlImage>(
185 new DlWimpImageFromTexture(width, height, texture_source, surface));
186}
187
188sk_sp<flutter::DlImage> MakeImageFromPixels(SkData* data,
189 int width,
190 int height,
191 Skwasm::PixelFormat pixel_format,
192 size_t row_byte_count) {
193 return sk_make_sp<DlWimpImageFromPixels>(width, height, sk_ref_sp(data),
194 pixel_format, row_byte_count);
195}
196} // 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
std::shared_ptr< ContextGLES > context
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...