Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
Skwasm::Surface Class Reference

#include <surface.h>

Public Types

using CallbackHandler = void(uint32_t, void *, SkwasmObject)
 

Public Member Functions

 Surface ()
 
unsigned long GetThreadId ()
 
void Dispose ()
 
void SetResourceCacheLimit (int bytes)
 
uint32_t RenderPictures (flutter::DisplayList **pictures, int width, int height, int count)
 
uint32_t RasterizeImage (flutter::DlImage *image, ImageByteFormat format)
 
void SetCallbackHandler (CallbackHandler *callback_handler)
 
void OnRenderComplete (uint32_t callback_id, SkwasmObject image_bitmap)
 
void OnRasterizeComplete (uint32_t callback_id, SkData *data)
 
std::unique_ptr< TextureSourceWrapperCreateTextureSourceWrapper (SkwasmObject texture_source)
 
void RenderPicturesOnWorker (sk_sp< flutter::DisplayList > *pictures, int width, int height, int picture_count, uint32_t callback_id, double raster_start)
 
void RasterizeImageOnWorker (flutter::DlImage *image, ImageByteFormat format, uint32_t callback_id)
 

Detailed Description

Definition at line 41 of file surface.h.

Member Typedef Documentation

◆ CallbackHandler

using Skwasm::Surface::CallbackHandler = void(uint32_t, void*, SkwasmObject)

Definition at line 43 of file surface.h.

Constructor & Destructor Documentation

◆ Surface()

Skwasm::Surface::Surface ( )

Definition at line 17 of file surface.cc.

17 {
20 } else {
21 assert(emscripten_is_main_browser_thread());
22
23 thread_ = emscripten_malloc_wasm_worker(65536);
24 emscripten_wasm_worker_post_function_v(thread_, []() {
25 // Listen to the main thread from the worker
27 });
28
29 // Listen to messages from the worker
30 skwasm_connectThread(thread_);
31 }
32}
void skwasm_connectThread(pthread_t thread_id)
bool skwasm_isSingleThreaded()

References skwasm_connectThread(), and skwasm_isSingleThreaded().

Member Function Documentation

◆ CreateTextureSourceWrapper()

std::unique_ptr< Skwasm::TextureSourceWrapper > Skwasm::Surface::CreateTextureSourceWrapper ( Skwasm::SkwasmObject  texture_source)

Definition at line 76 of file surface.cc.

77 {
78 return std::unique_ptr<Skwasm::TextureSourceWrapper>(
79 new Skwasm::TextureSourceWrapper(thread_, texture_source));
80}

◆ Dispose()

void Skwasm::Surface::Dispose ( )

Definition at line 35 of file surface.cc.

35 {
36 delete this;
37}

◆ GetThreadId()

unsigned long Skwasm::Surface::GetThreadId ( )
inline

Definition at line 48 of file surface.h.

48{ return thread_; }

◆ OnRasterizeComplete()

void Skwasm::Surface::OnRasterizeComplete ( uint32_t  callback_id,
SkData *  data 
)

Definition at line 206 of file surface.cc.

206 {
207 callback_handler_(callback_id, data, __builtin_wasm_ref_null_extern());
208}
std::shared_ptr< const fml::Mapping > data

References data.

◆ OnRenderComplete()

void Skwasm::Surface::OnRenderComplete ( uint32_t  callback_id,
Skwasm::SkwasmObject  image_bitmap 
)

Definition at line 211 of file surface.cc.

212 {
213 assert(emscripten_is_main_browser_thread());
214 callback_handler_(callback_id, nullptr, image_bitmap);
215}

◆ RasterizeImage()

uint32_t Skwasm::Surface::RasterizeImage ( flutter::DlImage image,
Skwasm::ImageByteFormat  format 
)

Definition at line 65 of file surface.cc.

66 {
67 assert(emscripten_is_main_browser_thread());
68 uint32_t callback_id = ++current_callback_id_;
69 image->ref();
70
71 skwasm_dispatchRasterizeImage(thread_, this, image, format, callback_id);
72 return callback_id;
73}
FlutterVulkanImage * image
void skwasm_dispatchRasterizeImage(unsigned long thread_id, Skwasm::Surface *surface, flutter::DlImage *image, Skwasm::ImageByteFormat format, uint32_t callback_id)

References format, image, and skwasm_dispatchRasterizeImage().

◆ RasterizeImageOnWorker()

void Skwasm::Surface::RasterizeImageOnWorker ( flutter::DlImage image,
Skwasm::ImageByteFormat  format,
uint32_t  callback_id 
)

Definition at line 166 of file surface.cc.

168 {
169 if (!is_initialized_) {
170 Init();
171 }
172
173 // We handle PNG encoding with browser APIs so that we can omit libpng from
174 // skia to save binary size.
175 assert(format != Skwasm::ImageByteFormat::png);
177 ? SkAlphaType::kUnpremul_SkAlphaType
178 : SkAlphaType::kPremul_SkAlphaType;
179 SkImageInfo info = SkImageInfo::Make(image->width(), image->height(),
180 SkColorType::kRGBA_8888_SkColorType,
181 alpha_type, SkColorSpace::MakeSRGB());
182 sk_sp<SkData> data;
183 size_t bytes_per_row = 4 * image->width();
184 size_t byte_size = info.computeByteSize(bytes_per_row);
185 data = SkData::MakeUninitialized(byte_size);
186 uint8_t* pixels = reinterpret_cast<uint8_t*>(data->writable_data());
187
188 // TODO(jacksongardner):
189 // Normally we'd just call `readPixels` on the image. However, this doesn't
190 // actually work in some cases due to a skia bug. Instead, we just draw the
191 // image to our scratch canvas and grab the pixels out directly with
192 // `glReadPixels`. Once the skia bug is fixed, we should switch back to using
193 // `SkImage::readPixels` instead.
194 // See https://g-issues.skia.org/issues/349201915
195 ResizeSurface(image->width(), image->height());
196
197 render_context_->RenderImage(image, format);
198
199 emscripten_glReadPixels(0, 0, image->width(), image->height(), GL_RGBA,
200 GL_UNSIGNED_BYTE, reinterpret_cast<void*>(pixels));
201
202 image->unref();
203 skwasm_postRasterizeResult(this, data.release(), callback_id);
204}
uint32_t uint32_t * format
uint32_t alpha_type
void skwasm_postRasterizeResult(Skwasm::Surface *surface, SkData *data, uint32_t callback_id)

References alpha_type, data, format, image, Skwasm::png, Skwasm::rawStraightRgba, and skwasm_postRasterizeResult().

◆ RenderPictures()

uint32_t Skwasm::Surface::RenderPictures ( flutter::DisplayList **  pictures,
int  width,
int  height,
int  count 
)

Definition at line 45 of file surface.cc.

48 {
49 assert(emscripten_is_main_browser_thread());
50 uint32_t callback_id = ++current_callback_id_;
51 std::unique_ptr<sk_sp<flutter::DisplayList>[]> picture_pointers =
52 std::make_unique<sk_sp<flutter::DisplayList>[]>(count);
53 for (int i = 0; i < count; i++) {
54 picture_pointers[i] = sk_ref_sp(pictures[i]);
55 }
56
57 // Releasing picturePointers here and will recreate the unique_ptr on the
58 // other thread See surface_renderPicturesOnWorker
59 skwasm_dispatchRenderPictures(thread_, this, picture_pointers.release(),
60 width, height, count, callback_id);
61 return callback_id;
62}
int32_t height
int32_t width
void skwasm_dispatchRenderPictures(unsigned long thread_id, Skwasm::Surface *surface, sk_sp< flutter::DisplayList > *pictures, int width, int height, int count, uint32_t callback_id)

References height, i, skwasm_dispatchRenderPictures(), and width.

◆ RenderPicturesOnWorker()

void Skwasm::Surface::RenderPicturesOnWorker ( sk_sp< flutter::DisplayList > *  pictures,
int  width,
int  height,
int  picture_count,
uint32_t  callback_id,
double  raster_start 
)

Definition at line 137 of file surface.cc.

143 {
144 if (!is_initialized_) {
145 Init();
146 }
147
148 // This is initialized on the first call to `skwasm_captureImageBitmap` and
149 // then populated with more bitmaps on subsequent calls.
150 Skwasm::SkwasmObject image_bitmap_array = __builtin_wasm_ref_null_extern();
151 for (int i = 0; i < picture_count; i++) {
152 sk_sp<flutter::DisplayList> picture = pictures[i];
153 ResizeSurface(width, height);
154 Skwasm::makeCurrent(gl_context_);
155
156 render_context_->RenderPicture(picture);
157
158 image_bitmap_array =
159 skwasm_captureImageBitmap(gl_context_, image_bitmap_array);
160 }
161 skwasm_resolveAndPostImages(this, image_bitmap_array, raster_start,
162 callback_id);
163}
__externref_t SkwasmObject
Definition wrappers.h:18
void makeCurrent(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle)
Definition wrappers.h:26
void skwasm_resolveAndPostImages(Skwasm::Surface *surface, SkwasmObject image_bitmaps, double raster_start, uint32_t callback_id)
SkwasmObject skwasm_captureImageBitmap(uint32_t context_handle, SkwasmObject image_bitmaps)

References height, i, Skwasm::makeCurrent(), skwasm_captureImageBitmap(), skwasm_resolveAndPostImages(), and width.

◆ SetCallbackHandler()

void Skwasm::Surface::SetCallbackHandler ( CallbackHandler callback_handler)

Definition at line 83 of file surface.cc.

84 {
85 assert(emscripten_is_main_browser_thread());
86 callback_handler_ = callback_handler;
87}
CallbackHandler callback_handler

References callback_handler.

◆ SetResourceCacheLimit()

void Skwasm::Surface::SetResourceCacheLimit ( int  bytes)

Definition at line 40 of file surface.cc.

40 {
41 render_context_->SetResourceCacheLimit(bytes);
42}

The documentation for this class was generated from the following files: