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 ()
 
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE GetGlContext ()
 
void SetCallbackHandler (CallbackHandler *callback_handler)
 
void Dispose ()
 
uint32_t SetCanvas (SkwasmObject canvas)
 
void OnInitialized (uint32_t callback_id)
 
void ReceiveCanvasOnWorker (SkwasmObject canvas, uint32_t callback_id)
 
uint32_t SetSize (int width, int height)
 
void OnResizeComplete (uint32_t callback_id)
 
void ResizeOnWorker (int width, int height, uint32_t callback_id)
 
uint32_t RenderPictures (flutter::DisplayList **picture, int count)
 
void OnRenderComplete (uint32_t callback_id, SkwasmObject image_bitmap)
 
void RenderPicturesOnWorker (sk_sp< flutter::DisplayList > *picture, int picture_count, uint32_t callback_id, double raster_start)
 
uint32_t RasterizeImage (flutter::DlImage *image, ImageByteFormat format)
 
void OnRasterizeComplete (uint32_t callback_id, SkData *data)
 
void RasterizeImageOnWorker (flutter::DlImage *image, ImageByteFormat format, uint32_t callback_id)
 
uint32_t TriggerContextLoss ()
 
void OnContextLossTriggered (uint32_t callback_id)
 
void ReportContextLost (uint32_t callback_id)
 
void TriggerContextLossOnWorker (uint32_t callback_id)
 
void OnContextLost ()
 
void SetResourceCacheLimit (int bytes)
 
std::unique_ptr< TextureSourceWrapperCreateTextureSourceWrapper (SkwasmObject textureSource)
 

Detailed Description

Definition at line 35 of file surface.h.

Member Typedef Documentation

◆ CallbackHandler

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

Definition at line 37 of file surface.h.

Constructor & Destructor Documentation

◆ Surface()

Skwasm::Surface::Surface ( )

Definition at line 64 of file surface.cc.

64 {
65 // Ensure the raster thread is initialized
67}
unsigned long GetRasterThread()
Definition surface.cc:44

References Skwasm::GetRasterThread().

Member Function Documentation

◆ CreateTextureSourceWrapper()

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

Definition at line 296 of file surface.cc.

296 {
297 return std::unique_ptr<Skwasm::TextureSourceWrapper>(
298 new Skwasm::TextureSourceWrapper(texture_source));
299}

◆ Dispose()

void Skwasm::Surface::Dispose ( )

Definition at line 78 of file surface.cc.

78 {
79 if (gl_context_) {
80 skwasm_destroyContext(gl_context_);
81 }
82 delete this;
83}
void skwasm_destroyContext(uint32_t context_handle)

References skwasm_destroyContext().

◆ GetGlContext()

EMSCRIPTEN_WEBGL_CONTEXT_HANDLE Skwasm::Surface::GetGlContext ( )
inline

Definition at line 43 of file surface.h.

43{ return gl_context_; }

◆ OnContextLossTriggered()

void Skwasm::Surface::OnContextLossTriggered ( uint32_t  callback_id)

Definition at line 265 of file surface.cc.

265 {
266 assert(emscripten_is_main_browser_thread());
267 callback_handler_(callback_id, nullptr, __builtin_wasm_ref_null_extern());
268}

◆ OnContextLost()

void Skwasm::Surface::OnContextLost ( )

Definition at line 281 of file surface.cc.

281 {
282 if (!context_lost_callback_id_) {
283 printf("Received context lost event but never set callback handler!\n");
284 return;
285 }
286 skwasm_reportContextLost(this, context_lost_callback_id_);
287}
void skwasm_reportContextLost(Skwasm::Surface *surface, uint32_t callback_id)

References skwasm_reportContextLost().

◆ OnInitialized()

void Skwasm::Surface::OnInitialized ( uint32_t  callback_id)

Definition at line 93 of file surface.cc.

93 {
94 assert(emscripten_is_main_browser_thread());
95 callback_handler_(callback_id, (void*)context_lost_callback_id_,
96 __builtin_wasm_ref_null_extern());
97}

◆ OnRasterizeComplete()

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

Definition at line 225 of file surface.cc.

225 {
226 assert(emscripten_is_main_browser_thread());
227 callback_handler_(callback_id, data, __builtin_wasm_ref_null_extern());
228}

◆ OnRenderComplete()

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

Definition at line 187 of file surface.cc.

188 {
189 assert(emscripten_is_main_browser_thread());
190 callback_handler_(callback_id, nullptr, image_bitmap);
191}

◆ OnResizeComplete()

void Skwasm::Surface::OnResizeComplete ( uint32_t  callback_id)

Definition at line 148 of file surface.cc.

148 {
149 assert(emscripten_is_main_browser_thread());
150 callback_handler_(callback_id, nullptr, __builtin_wasm_ref_null_extern());
151}

◆ RasterizeImage()

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

Definition at line 214 of file surface.cc.

215 {
216 assert(emscripten_is_main_browser_thread());
217 uint32_t callback_id = ++current_callback_id_;
218 image->ref();
219
221 callback_id);
222 return callback_id;
223}
FlutterVulkanImage * image
void skwasm_dispatchRasterizeImage(unsigned long thread_id, Skwasm::Surface *surface, flutter::DlImage *image, Skwasm::ImageByteFormat format, uint32_t callback_id)

References format, Skwasm::GetRasterThread(), image, and skwasm_dispatchRasterizeImage().

◆ RasterizeImageOnWorker()

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

Definition at line 230 of file surface.cc.

232 {
233 // We handle PNG encoding with browser APIs so that we can omit libpng from
234 // skia to save binary size.
235 assert(format != Skwasm::ImageByteFormat::png);
236 Skwasm::makeCurrent(gl_context_);
238 ? SkAlphaType::kUnpremul_SkAlphaType
239 : SkAlphaType::kPremul_SkAlphaType;
240 SkImageInfo info = SkImageInfo::Make(image->width(), image->height(),
241 SkColorType::kRGBA_8888_SkColorType,
242 alpha_type, SkColorSpace::MakeSRGB());
243 sk_sp<SkData> data;
244 size_t bytes_per_row = 4 * image->width();
245 size_t byte_size = info.computeByteSize(bytes_per_row);
246 data = SkData::MakeUninitialized(byte_size);
247 uint8_t* pixels = reinterpret_cast<uint8_t*>(data->writable_data());
248
249 render_context_->RasterizeImage(image, format,
250 reinterpret_cast<void*>(pixels));
251
252 image->unref();
253 skwasm_postRasterizeResult(this, data.release(), callback_id);
254}
uint32_t uint32_t * format
void makeCurrent(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle)
Definition wrappers.h:26
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 switch_defs.h:36
uint32_t alpha_type
void skwasm_postRasterizeResult(Skwasm::Surface *surface, SkData *data, uint32_t callback_id)

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

◆ ReceiveCanvasOnWorker()

void Skwasm::Surface::ReceiveCanvasOnWorker ( SkwasmObject  canvas,
uint32_t  callback_id 
)

Definition at line 100 of file surface.cc.

101 {
102 if (render_context_) {
103 render_context_.reset();
104 }
105 canvas_width_ = 1;
106 canvas_height_ = 1;
107 bool antialias = skwasm_isWimp();
108 gl_context_ = skwasm_getGlContextForCanvas(canvas, antialias, this);
109 if (!gl_context_) {
110 printf("Failed to create context!\n");
111 return;
112 }
113
114 Skwasm::makeCurrent(gl_context_);
115 emscripten_webgl_enable_extension(gl_context_, "WEBGL_debug_renderer_info");
116
117 // WebGL should already be clearing the color and stencil buffers, but do it
118 // again here to ensure Skia receives them in the expected state.
119 emscripten_glBindFramebuffer(GL_FRAMEBUFFER, 0);
120 emscripten_glClearColor(0, 0, 0, 0);
121 emscripten_glClearStencil(0);
122 emscripten_glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
123
124 int sample_count;
125 int stencil;
126 emscripten_glGetIntegerv(GL_SAMPLES, &sample_count);
127 emscripten_glGetIntegerv(GL_STENCIL_BITS, &stencil);
128
129 render_context_ = Skwasm::RenderContext::Make(sample_count, stencil);
130 render_context_->Resize(canvas_width_, canvas_height_);
131
132 context_lost_callback_id_ = ++current_callback_id_;
133
134 skwasm_reportInitialized(this, context_lost_callback_id_, callback_id);
135}
static std::unique_ptr< RenderContext > Make(int sample_count, int stencil)
SKWASM_EXPORT bool skwasm_isWimp()
uint32_t skwasm_getGlContextForCanvas(SkwasmObject canvas, bool antialias, Skwasm::Surface *surface)
void skwasm_reportInitialized(Skwasm::Surface *surface, uint32_t callback_id, uint32_t context_lost_callback_id)

References Skwasm::RenderContext::Make(), Skwasm::makeCurrent(), skwasm_getGlContextForCanvas(), skwasm_isWimp(), and skwasm_reportInitialized().

◆ RenderPictures()

uint32_t Skwasm::Surface::RenderPictures ( flutter::DisplayList **  picture,
int  count 
)

Definition at line 170 of file surface.cc.

171 {
172 assert(emscripten_is_main_browser_thread());
173 uint32_t callback_id = ++current_callback_id_;
174 std::unique_ptr<sk_sp<flutter::DisplayList>[]> picture_pointers =
175 std::make_unique<sk_sp<flutter::DisplayList>[]>(count);
176 for (int i = 0; i < count; i++) {
177 picture_pointers[i] = sk_ref_sp(pictures[i]);
178 }
179
180 // Releasing picture_pointers here and will recreate the unique_ptr on the
181 // other thread See surface_renderPicturesOnWorker
183 picture_pointers.release(), count, callback_id);
184 return callback_id;
185}
void skwasm_dispatchRenderPictures(unsigned long thread_id, Skwasm::Surface *surface, sk_sp< flutter::DisplayList > *pictures, int count, uint32_t callback_id)

References Skwasm::GetRasterThread(), i, and skwasm_dispatchRenderPictures().

◆ RenderPicturesOnWorker()

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

Definition at line 193 of file surface.cc.

197 {
198 Skwasm::makeCurrent(gl_context_);
199 // This is initialized on the first call to `skwasm_captureImageBitmap` and
200 // then populated with more bitmaps on subsequent calls.
201 SkwasmObject image_bitmap_array = __builtin_wasm_ref_null_extern();
202 for (int i = 0; i < picture_count; i++) {
203 sk_sp<flutter::DisplayList> picture = pictures[i];
204 render_context_->RenderPicture(picture);
205 image_bitmap_array =
206 skwasm_captureImageBitmap(gl_context_, image_bitmap_array);
207 }
208 skwasm_resolveAndPostImages(this, image_bitmap_array, raster_start,
209 callback_id);
210}
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)
__externref_t SkwasmObject

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

◆ ReportContextLost()

void Skwasm::Surface::ReportContextLost ( uint32_t  callback_id)

Definition at line 270 of file surface.cc.

270 {
271 assert(emscripten_is_main_browser_thread());
272 callback_handler_(callback_id, nullptr, __builtin_wasm_ref_null_extern());
273}

◆ ResizeOnWorker()

void Skwasm::Surface::ResizeOnWorker ( int  width,
int  height,
uint32_t  callback_id 
)

Definition at line 153 of file surface.cc.

155 {
156 ResizeSurface(width, height);
157 skwasm_reportResizeComplete(this, callback_id);
158}
int32_t height
int32_t width
void skwasm_reportResizeComplete(Skwasm::Surface *surface, uint32_t callback_id)

References height, skwasm_reportResizeComplete(), and width.

◆ SetCallbackHandler()

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

Definition at line 73 of file surface.cc.

73 {
74 assert(emscripten_is_main_browser_thread());
75 callback_handler_ = callback_handler;
76}
CallbackHandler callback_handler

References callback_handler.

◆ SetCanvas()

uint32_t Skwasm::Surface::SetCanvas ( SkwasmObject  canvas)

Definition at line 86 of file surface.cc.

86 {
87 assert(emscripten_is_main_browser_thread());
88 uint32_t callback_id = ++current_callback_id_;
89 skwasm_dispatchTransferCanvas(GetRasterThread(), this, canvas, callback_id);
90 return callback_id;
91}
void skwasm_dispatchTransferCanvas(unsigned long thread_id, Skwasm::Surface *surface, SkwasmObject canvas, uint32_t callback_id)

References Skwasm::GetRasterThread(), and skwasm_dispatchTransferCanvas().

◆ SetResourceCacheLimit()

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

Definition at line 291 of file surface.cc.

291 {
292 render_context_->SetResourceCacheLimit(bytes);
293}

◆ SetSize()

uint32_t Skwasm::Surface::SetSize ( int  width,
int  height 
)

Definition at line 139 of file surface.cc.

139 {
140 assert(emscripten_is_main_browser_thread());
141 uint32_t callback_id = ++current_callback_id_;
142
144 callback_id);
145 return callback_id;
146}
void skwasm_dispatchResizeSurface(unsigned long thread_id, Skwasm::Surface *surface, int width, int height, uint32_t callback_id)

References Skwasm::GetRasterThread(), height, skwasm_dispatchResizeSurface(), and width.

◆ TriggerContextLoss()

uint32_t Skwasm::Surface::TriggerContextLoss ( )

Definition at line 258 of file surface.cc.

258 {
259 assert(emscripten_is_main_browser_thread());
260 uint32_t callback_id = ++current_callback_id_;
262 return callback_id;
263}
void skwasm_dispatchTriggerContextLoss(unsigned long thread_id, Skwasm::Surface *surface, uint32_t callback_id)

References Skwasm::GetRasterThread(), and skwasm_dispatchTriggerContextLoss().

◆ TriggerContextLossOnWorker()

void Skwasm::Surface::TriggerContextLossOnWorker ( uint32_t  callback_id)

Definition at line 275 of file surface.cc.

275 {
276 Skwasm::makeCurrent(gl_context_);
278 skwasm_reportContextLossTriggered(this, callback_id);
279}
void skwasm_reportContextLossTriggered(Skwasm::Surface *surface, uint32_t callback_id)
void skwasm_triggerContextLossOnCanvas()

References Skwasm::makeCurrent(), skwasm_reportContextLossTriggered(), and skwasm_triggerContextLossOnCanvas().


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