Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
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 ()
 
uint32_t renderPictures (SkPicture **picture, int count)
 
uint32_t rasterizeImage (SkImage *image, ImageByteFormat format)
 
void setCallbackHandler (CallbackHandler *callbackHandler)
 
void onRenderComplete (uint32_t callbackId, SkwasmObject imageBitmap)
 
std::unique_ptr< TextureSourceWrappercreateTextureSourceWrapper (SkwasmObject textureSource)
 
void renderPicturesOnWorker (sk_sp< SkPicture > *picture, int pictureCount, uint32_t callbackId, double rasterStart)
 

Detailed Description

Definition at line 54 of file surface.h.

Member Typedef Documentation

◆ CallbackHandler

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

Definition at line 56 of file surface.h.

Constructor & Destructor Documentation

◆ Surface()

Surface::Surface ( )

Definition at line 16 of file surface.cpp.

16 {
17 assert(emscripten_is_main_browser_thread());
18
19 pthread_attr_t attr;
20 pthread_attr_init(&attr);
21 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
22
23 pthread_create(
24 &_thread, &attr,
25 [](void* context) -> void* {
26 static_cast<Surface*>(context)->_runWorker();
27 return nullptr;
28 },
29 this);
30 // Listen to messages from the worker
32
33 // Synchronize the time origin for the worker thread
35}
void skwasm_syncTimeOriginForThread(pthread_t threadId)
void skwasm_registerMessageListener(pthread_t threadId)

Member Function Documentation

◆ createTextureSourceWrapper()

std::unique_ptr< TextureSourceWrapper > Surface::createTextureSourceWrapper ( SkwasmObject  textureSource)

Definition at line 74 of file surface.cpp.

75 {
76 return std::unique_ptr<TextureSourceWrapper>(
77 new TextureSourceWrapper(_thread, textureSource));
78}

◆ dispose()

void Surface::dispose ( )

Definition at line 38 of file surface.cpp.

38 {
39 assert(emscripten_is_main_browser_thread());
40 emscripten_dispatch_to_thread(_thread, EM_FUNC_SIG_VI,
41 reinterpret_cast<void*>(fDispose), nullptr,
42 this);
43}

◆ getThreadId()

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

Definition at line 61 of file surface.h.

61{ return _thread; }

◆ onRenderComplete()

void Surface::onRenderComplete ( uint32_t  callbackId,
SkwasmObject  imageBitmap 
)

Definition at line 210 of file surface.cpp.

210 {
211 assert(emscripten_is_main_browser_thread());
212 _callbackHandler(callbackId, nullptr, imageBitmap);
213}

◆ rasterizeImage()

uint32_t Surface::rasterizeImage ( SkImage image,
ImageByteFormat  format 
)

Definition at line 63 of file surface.cpp.

63 {
64 assert(emscripten_is_main_browser_thread());
65 uint32_t callbackId = ++_currentCallbackId;
66 image->ref();
67
68 emscripten_dispatch_to_thread(_thread, EM_FUNC_SIG_VIIII,
69 reinterpret_cast<void*>(fRasterizeImage),
70 nullptr, this, image, format, callbackId);
71 return callbackId;
72}
void ref() const
Definition: SkRefCnt.h:62
uint32_t uint32_t * format
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ renderPictures()

uint32_t Surface::renderPictures ( SkPicture **  picture,
int  count 
)

Definition at line 46 of file surface.cpp.

46 {
47 assert(emscripten_is_main_browser_thread());
48 uint32_t callbackId = ++_currentCallbackId;
49 std::unique_ptr<sk_sp<SkPicture>[]> picturePointers =
50 std::make_unique<sk_sp<SkPicture>[]>(count);
51 for (int i = 0; i < count; i++) {
52 picturePointers[i] = sk_ref_sp(pictures[i]);
53 }
54
55 // Releasing picturePointers here and will recreate the unique_ptr on the
56 // other thread See surface_renderPicturesOnWorker
57 skwasm_dispatchRenderPictures(_thread, this, picturePointers.release(), count,
58 callbackId);
59 return callbackId;
60}
int count
Definition: FontMgrTest.cpp:50
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
void skwasm_dispatchRenderPictures(unsigned long threadId, Skwasm::Surface *surface, sk_sp< SkPicture > *pictures, int count, uint32_t callbackId)

◆ renderPicturesOnWorker()

void Surface::renderPicturesOnWorker ( sk_sp< SkPicture > *  picture,
int  pictureCount,
uint32_t  callbackId,
double  rasterStart 
)

Definition at line 151 of file surface.cpp.

154 {
155 // This is populated by the `captureImageBitmap` call the first time it is
156 // passed in.
157 SkwasmObject imagePromiseArray = __builtin_wasm_ref_null_extern();
158 for (int i = 0; i < pictureCount; i++) {
159 sk_sp<SkPicture> picture = pictures[i];
160 SkRect pictureRect = picture->cullRect();
161 SkIRect roundedOutRect;
162 pictureRect.roundOut(&roundedOutRect);
163 _resizeCanvasToFit(roundedOutRect.width(), roundedOutRect.height());
165 SkMatrix::Translate(-roundedOutRect.fLeft, -roundedOutRect.fTop);
166 makeCurrent(_glContext);
167 auto canvas = _surface->getCanvas();
169 canvas->drawPicture(picture, &matrix, nullptr);
170 _grContext->flush(_surface.get());
171 imagePromiseArray =
172 skwasm_captureImageBitmap(_glContext, roundedOutRect.width(),
173 roundedOutRect.height(), imagePromiseArray);
174 }
175 skwasm_resolveAndPostImages(this, imagePromiseArray, rasterStart, callbackId);
176}
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
virtual SkRect cullRect() const =0
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
T * get() const
Definition: SkRefCnt.h:303
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
void makeCurrent(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle)
Definition: wrappers.h:22
SkwasmObject skwasm_captureImageBitmap(uint32_t contextHandle, int width, int height, SkwasmObject imagePromises)
void skwasm_resolveAndPostImages(Skwasm::Surface *surface, SkwasmObject imagePromises, double rasterStart, uint32_t callbackId)
__externref_t SkwasmObject
Definition: SkRect.h:32
constexpr int32_t height() const
Definition: SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr int32_t width() const
Definition: SkRect.h:158
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ setCallbackHandler()

void Surface::setCallbackHandler ( CallbackHandler callbackHandler)

Definition at line 81 of file surface.cpp.

81 {
82 assert(emscripten_is_main_browser_thread());
83 _callbackHandler = callbackHandler;
84}

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